]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/Manager.java
eb62cb60ef1359b9adef3fb75bc62bda50a86907
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / Manager.java
1 package org.asamk.signal.manager;
2
3 import org.asamk.signal.manager.api.AttachmentInvalidException;
4 import org.asamk.signal.manager.api.Configuration;
5 import org.asamk.signal.manager.api.Device;
6 import org.asamk.signal.manager.api.Group;
7 import org.asamk.signal.manager.api.Identity;
8 import org.asamk.signal.manager.api.InactiveGroupLinkException;
9 import org.asamk.signal.manager.api.InvalidDeviceLinkException;
10 import org.asamk.signal.manager.api.InvalidStickerException;
11 import org.asamk.signal.manager.api.Message;
12 import org.asamk.signal.manager.api.MessageEnvelope;
13 import org.asamk.signal.manager.api.NotPrimaryDeviceException;
14 import org.asamk.signal.manager.api.Pair;
15 import org.asamk.signal.manager.api.PendingAdminApprovalException;
16 import org.asamk.signal.manager.api.ReceiveConfig;
17 import org.asamk.signal.manager.api.RecipientIdentifier;
18 import org.asamk.signal.manager.api.SendGroupMessageResults;
19 import org.asamk.signal.manager.api.SendMessageResults;
20 import org.asamk.signal.manager.api.StickerPack;
21 import org.asamk.signal.manager.api.StickerPackInvalidException;
22 import org.asamk.signal.manager.api.StickerPackUrl;
23 import org.asamk.signal.manager.api.TypingAction;
24 import org.asamk.signal.manager.api.UnregisteredRecipientException;
25 import org.asamk.signal.manager.api.UpdateGroup;
26 import org.asamk.signal.manager.api.UpdateProfile;
27 import org.asamk.signal.manager.api.UserStatus;
28 import org.asamk.signal.manager.groups.GroupId;
29 import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
30 import org.asamk.signal.manager.groups.GroupNotFoundException;
31 import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
32 import org.asamk.signal.manager.groups.LastGroupAdminException;
33 import org.asamk.signal.manager.groups.NotAGroupMemberException;
34 import org.asamk.signal.manager.storage.recipients.Profile;
35 import org.asamk.signal.manager.storage.recipients.Recipient;
36 import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
37
38 import java.io.Closeable;
39 import java.io.File;
40 import java.io.IOException;
41 import java.net.URI;
42 import java.time.Duration;
43 import java.util.Collection;
44 import java.util.List;
45 import java.util.Map;
46 import java.util.Optional;
47 import java.util.Set;
48
49 public interface Manager extends Closeable {
50
51 static boolean isValidNumber(final String e164Number, final String countryCode) {
52 return PhoneNumberFormatter.isValidNumber(e164Number, countryCode);
53 }
54
55 String getSelfNumber();
56
57 /**
58 * This is used for checking a set of phone numbers for registration on Signal
59 *
60 * @param numbers The set of phone number in question
61 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
62 * @throws IOException if it's unable to get the contacts to check if they're registered
63 */
64 Map<String, UserStatus> getUserStatus(Set<String> numbers) throws IOException;
65
66 void updateAccountAttributes(String deviceName) throws IOException;
67
68 Configuration getConfiguration();
69
70 void updateConfiguration(Configuration configuration) throws IOException, NotPrimaryDeviceException;
71
72 /**
73 * Update the user's profile.
74 * If a field is null, the previous value will be kept.
75 */
76 void updateProfile(UpdateProfile updateProfile) throws IOException;
77
78 void unregister() throws IOException;
79
80 void deleteAccount() throws IOException;
81
82 void submitRateLimitRecaptchaChallenge(String challenge, String captcha) throws IOException;
83
84 List<Device> getLinkedDevices() throws IOException;
85
86 void removeLinkedDevices(int deviceId) throws IOException;
87
88 void addDeviceLink(URI linkUri) throws IOException, InvalidDeviceLinkException;
89
90 void setRegistrationLockPin(Optional<String> pin) throws IOException, NotPrimaryDeviceException;
91
92 Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException;
93
94 List<Group> getGroups();
95
96 SendGroupMessageResults quitGroup(
97 GroupId groupId, Set<RecipientIdentifier.Single> groupAdmins
98 ) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException, UnregisteredRecipientException;
99
100 void deleteGroup(GroupId groupId) throws IOException;
101
102 Pair<GroupId, SendGroupMessageResults> createGroup(
103 String name, Set<RecipientIdentifier.Single> members, File avatarFile
104 ) throws IOException, AttachmentInvalidException, UnregisteredRecipientException;
105
106 SendGroupMessageResults updateGroup(
107 final GroupId groupId, final UpdateGroup updateGroup
108 ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException, UnregisteredRecipientException;
109
110 Pair<GroupId, SendGroupMessageResults> joinGroup(
111 GroupInviteLinkUrl inviteLinkUrl
112 ) throws IOException, InactiveGroupLinkException, PendingAdminApprovalException;
113
114 SendMessageResults sendTypingMessage(
115 TypingAction action, Set<RecipientIdentifier> recipients
116 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
117
118 SendMessageResults sendReadReceipt(
119 RecipientIdentifier.Single sender, List<Long> messageIds
120 ) throws IOException;
121
122 SendMessageResults sendViewedReceipt(
123 RecipientIdentifier.Single sender, List<Long> messageIds
124 ) throws IOException;
125
126 SendMessageResults sendMessage(
127 Message message, Set<RecipientIdentifier> recipients
128 ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException;
129
130 SendMessageResults sendRemoteDeleteMessage(
131 long targetSentTimestamp, Set<RecipientIdentifier> recipients
132 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
133
134 SendMessageResults sendMessageReaction(
135 String emoji,
136 boolean remove,
137 RecipientIdentifier.Single targetAuthor,
138 long targetSentTimestamp,
139 Set<RecipientIdentifier> recipients
140 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException;
141
142 SendMessageResults sendPaymentNotificationMessage(
143 byte[] receipt, String note, RecipientIdentifier.Single recipient
144 ) throws IOException;
145
146 SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
147
148 void deleteRecipient(RecipientIdentifier.Single recipient);
149
150 void deleteContact(RecipientIdentifier.Single recipient);
151
152 void setContactName(
153 RecipientIdentifier.Single recipient, String givenName, final String familyName
154 ) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
155
156 void setContactsBlocked(
157 Collection<RecipientIdentifier.Single> recipient, boolean blocked
158 ) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
159
160 void setGroupsBlocked(
161 Collection<GroupId> groupId, boolean blocked
162 ) throws GroupNotFoundException, IOException, NotPrimaryDeviceException;
163
164 /**
165 * Change the expiration timer for a contact
166 */
167 void setExpirationTimer(
168 RecipientIdentifier.Single recipient, int messageExpirationTimer
169 ) throws IOException, UnregisteredRecipientException;
170
171 /**
172 * Upload the sticker pack from path.
173 *
174 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
175 * @return if successful, returns the URL to install the sticker pack in the signal app
176 */
177 StickerPackUrl uploadStickerPack(File path) throws IOException, StickerPackInvalidException;
178
179 List<StickerPack> getStickerPacks();
180
181 void requestAllSyncData() throws IOException;
182
183 /**
184 * Add a handler to receive new messages.
185 * Will start receiving messages from server, if not already started.
186 */
187 default void addReceiveHandler(ReceiveMessageHandler handler) {
188 addReceiveHandler(handler, false);
189 }
190
191 void addReceiveHandler(ReceiveMessageHandler handler, final boolean isWeakListener);
192
193 /**
194 * Remove a handler to receive new messages.
195 * Will stop receiving messages from server, if this was the last registered receiver.
196 */
197 void removeReceiveHandler(ReceiveMessageHandler handler);
198
199 boolean isReceiving();
200
201 /**
202 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
203 */
204 void receiveMessages(Duration timeout, ReceiveMessageHandler handler) throws IOException;
205
206 /**
207 * Receive new messages from server, returns only if the thread is interrupted.
208 */
209 void receiveMessages(ReceiveMessageHandler handler) throws IOException;
210
211 void setReceiveConfig(ReceiveConfig receiveConfig);
212
213 boolean hasCaughtUpWithOldMessages();
214
215 boolean isContactBlocked(RecipientIdentifier.Single recipient);
216
217 void sendContacts() throws IOException;
218
219 List<Recipient> getRecipients(
220 boolean onlyContacts,
221 Optional<Boolean> blocked,
222 Collection<RecipientIdentifier.Single> address,
223 Optional<String> name
224 );
225
226 String getContactOrProfileName(RecipientIdentifier.Single recipient);
227
228 Group getGroup(GroupId groupId);
229
230 List<Identity> getIdentities();
231
232 List<Identity> getIdentities(RecipientIdentifier.Single recipient);
233
234 /**
235 * Trust this the identity with this fingerprint
236 *
237 * @param recipient account of the identity
238 * @param fingerprint Fingerprint
239 */
240 boolean trustIdentityVerified(
241 RecipientIdentifier.Single recipient, byte[] fingerprint
242 ) throws UnregisteredRecipientException;
243
244 /**
245 * Trust this the identity with this safety number
246 *
247 * @param recipient account of the identity
248 * @param safetyNumber Safety number
249 */
250 boolean trustIdentityVerifiedSafetyNumber(
251 RecipientIdentifier.Single recipient, String safetyNumber
252 ) throws UnregisteredRecipientException;
253
254 /**
255 * Trust this the identity with this scannable safety number
256 *
257 * @param recipient account of the identity
258 * @param safetyNumber Scannable safety number
259 */
260 boolean trustIdentityVerifiedSafetyNumber(
261 RecipientIdentifier.Single recipient, byte[] safetyNumber
262 ) throws UnregisteredRecipientException;
263
264 /**
265 * Trust all keys of this identity without verification
266 *
267 * @param recipient account of the identity
268 */
269 boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient) throws UnregisteredRecipientException;
270
271 void addAddressChangedListener(Runnable listener);
272
273 void addClosedListener(Runnable listener);
274
275 @Override
276 void close() throws IOException;
277
278 interface ReceiveMessageHandler {
279
280 ReceiveMessageHandler EMPTY = (envelope, e) -> {
281 };
282
283 void handleMessage(MessageEnvelope envelope, Throwable e);
284 }
285 }