]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/Manager.java
Extend updateContact command with nick given/family name and note
[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.AlreadyReceivingException;
4 import org.asamk.signal.manager.api.AttachmentInvalidException;
5 import org.asamk.signal.manager.api.CaptchaRejectedException;
6 import org.asamk.signal.manager.api.CaptchaRequiredException;
7 import org.asamk.signal.manager.api.Configuration;
8 import org.asamk.signal.manager.api.Device;
9 import org.asamk.signal.manager.api.DeviceLimitExceededException;
10 import org.asamk.signal.manager.api.DeviceLinkUrl;
11 import org.asamk.signal.manager.api.Group;
12 import org.asamk.signal.manager.api.GroupId;
13 import org.asamk.signal.manager.api.GroupInviteLinkUrl;
14 import org.asamk.signal.manager.api.GroupNotFoundException;
15 import org.asamk.signal.manager.api.GroupSendingNotAllowedException;
16 import org.asamk.signal.manager.api.Identity;
17 import org.asamk.signal.manager.api.IdentityVerificationCode;
18 import org.asamk.signal.manager.api.InactiveGroupLinkException;
19 import org.asamk.signal.manager.api.IncorrectPinException;
20 import org.asamk.signal.manager.api.InvalidDeviceLinkException;
21 import org.asamk.signal.manager.api.InvalidStickerException;
22 import org.asamk.signal.manager.api.InvalidUsernameException;
23 import org.asamk.signal.manager.api.LastGroupAdminException;
24 import org.asamk.signal.manager.api.Message;
25 import org.asamk.signal.manager.api.MessageEnvelope;
26 import org.asamk.signal.manager.api.NonNormalizedPhoneNumberException;
27 import org.asamk.signal.manager.api.NotAGroupMemberException;
28 import org.asamk.signal.manager.api.NotPrimaryDeviceException;
29 import org.asamk.signal.manager.api.Pair;
30 import org.asamk.signal.manager.api.PendingAdminApprovalException;
31 import org.asamk.signal.manager.api.PinLockedException;
32 import org.asamk.signal.manager.api.RateLimitException;
33 import org.asamk.signal.manager.api.ReceiveConfig;
34 import org.asamk.signal.manager.api.Recipient;
35 import org.asamk.signal.manager.api.RecipientIdentifier;
36 import org.asamk.signal.manager.api.SendGroupMessageResults;
37 import org.asamk.signal.manager.api.SendMessageResults;
38 import org.asamk.signal.manager.api.StickerPack;
39 import org.asamk.signal.manager.api.StickerPackId;
40 import org.asamk.signal.manager.api.StickerPackInvalidException;
41 import org.asamk.signal.manager.api.StickerPackUrl;
42 import org.asamk.signal.manager.api.TypingAction;
43 import org.asamk.signal.manager.api.UnregisteredRecipientException;
44 import org.asamk.signal.manager.api.UpdateGroup;
45 import org.asamk.signal.manager.api.UpdateProfile;
46 import org.asamk.signal.manager.api.UserStatus;
47 import org.asamk.signal.manager.api.UsernameLinkUrl;
48 import org.asamk.signal.manager.api.UsernameStatus;
49 import org.asamk.signal.manager.api.VerificationMethodNotAvailableException;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52 import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
53
54 import java.io.Closeable;
55 import java.io.File;
56 import java.io.IOException;
57 import java.io.InputStream;
58 import java.time.Duration;
59 import java.util.Collection;
60 import java.util.List;
61 import java.util.Map;
62 import java.util.Optional;
63 import java.util.Set;
64
65 public interface Manager extends Closeable {
66
67 static boolean isValidNumber(final String e164Number, final String countryCode) {
68 return PhoneNumberFormatter.isValidNumber(e164Number, countryCode);
69 }
70
71 static boolean isSignalClientAvailable() {
72 final Logger logger = LoggerFactory.getLogger(Manager.class);
73 try {
74 try {
75 org.signal.libsignal.internal.Native.UuidCiphertext_CheckValidContents(new byte[0]);
76 } catch (Exception e) {
77 logger.trace("Expected exception when checking libsignal-client: {}", e.getMessage());
78 }
79 return true;
80 } catch (UnsatisfiedLinkError e) {
81 logger.warn("Failed to call libsignal-client: {}", e.getMessage());
82 return false;
83 }
84 }
85
86 String getSelfNumber();
87
88 /**
89 * This is used for checking a set of phone numbers for registration on Signal
90 *
91 * @param numbers The set of phone number in question
92 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
93 * @throws IOException if it's unable to get the contacts to check if they're registered
94 */
95 Map<String, UserStatus> getUserStatus(Set<String> numbers) throws IOException, RateLimitException;
96
97 Map<String, UsernameStatus> getUsernameStatus(Set<String> usernames);
98
99 void updateAccountAttributes(
100 String deviceName,
101 Boolean unrestrictedUnidentifiedSender,
102 final Boolean discoverableByNumber,
103 final Boolean numberSharing
104 ) throws IOException;
105
106 Configuration getConfiguration();
107
108 void updateConfiguration(Configuration configuration) throws NotPrimaryDeviceException;
109
110 /**
111 * Update the user's profile.
112 * If a field is null, the previous value will be kept.
113 */
114 void updateProfile(UpdateProfile updateProfile) throws IOException;
115
116 String getUsername();
117
118 UsernameLinkUrl getUsernameLink();
119
120 /**
121 * Set a username for the account.
122 * If the username is null, it will be deleted.
123 */
124 void setUsername(String username) throws IOException, InvalidUsernameException;
125
126 /**
127 * Set a username for the account.
128 * If the username is null, it will be deleted.
129 */
130 void deleteUsername() throws IOException;
131
132 void startChangeNumber(
133 String newNumber,
134 boolean voiceVerification,
135 String captcha
136 ) throws RateLimitException, IOException, CaptchaRequiredException, NonNormalizedPhoneNumberException, NotPrimaryDeviceException, VerificationMethodNotAvailableException;
137
138 void finishChangeNumber(
139 String newNumber,
140 String verificationCode,
141 String pin
142 ) throws IncorrectPinException, PinLockedException, IOException, NotPrimaryDeviceException;
143
144 void unregister() throws IOException;
145
146 void deleteAccount() throws IOException;
147
148 void submitRateLimitRecaptchaChallenge(
149 String challenge,
150 String captcha
151 ) throws IOException, CaptchaRejectedException;
152
153 List<Device> getLinkedDevices() throws IOException;
154
155 void removeLinkedDevices(int deviceId) throws IOException, NotPrimaryDeviceException;
156
157 void addDeviceLink(DeviceLinkUrl linkUri) throws IOException, InvalidDeviceLinkException, NotPrimaryDeviceException, DeviceLimitExceededException;
158
159 void setRegistrationLockPin(Optional<String> pin) throws IOException, NotPrimaryDeviceException;
160
161 List<Group> getGroups();
162
163 SendGroupMessageResults quitGroup(
164 GroupId groupId,
165 Set<RecipientIdentifier.Single> groupAdmins
166 ) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException, UnregisteredRecipientException;
167
168 void deleteGroup(GroupId groupId) throws IOException;
169
170 Pair<GroupId, SendGroupMessageResults> createGroup(
171 String name,
172 Set<RecipientIdentifier.Single> members,
173 String avatarFile
174 ) throws IOException, AttachmentInvalidException, UnregisteredRecipientException;
175
176 SendGroupMessageResults updateGroup(
177 final GroupId groupId,
178 final UpdateGroup updateGroup
179 ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException, UnregisteredRecipientException;
180
181 Pair<GroupId, SendGroupMessageResults> joinGroup(
182 GroupInviteLinkUrl inviteLinkUrl
183 ) throws IOException, InactiveGroupLinkException, PendingAdminApprovalException;
184
185 SendMessageResults sendTypingMessage(
186 TypingAction action,
187 Set<RecipientIdentifier> recipients
188 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
189
190 SendMessageResults sendReadReceipt(RecipientIdentifier.Single sender, List<Long> messageIds);
191
192 SendMessageResults sendViewedReceipt(RecipientIdentifier.Single sender, List<Long> messageIds);
193
194 SendMessageResults sendMessage(
195 Message message,
196 Set<RecipientIdentifier> recipients,
197 boolean notifySelf
198 ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException;
199
200 SendMessageResults sendEditMessage(
201 Message message,
202 Set<RecipientIdentifier> recipients,
203 long editTargetTimestamp
204 ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException;
205
206 SendMessageResults sendRemoteDeleteMessage(
207 long targetSentTimestamp,
208 Set<RecipientIdentifier> recipients
209 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
210
211 SendMessageResults sendMessageReaction(
212 String emoji,
213 boolean remove,
214 RecipientIdentifier.Single targetAuthor,
215 long targetSentTimestamp,
216 Set<RecipientIdentifier> recipients,
217 final boolean isStory
218 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException;
219
220 SendMessageResults sendPaymentNotificationMessage(
221 byte[] receipt,
222 String note,
223 RecipientIdentifier.Single recipient
224 ) throws IOException;
225
226 SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
227
228 SendMessageResults sendMessageRequestResponse(
229 MessageEnvelope.Sync.MessageRequestResponse.Type type,
230 Set<RecipientIdentifier> recipientIdentifiers
231 );
232
233 void hideRecipient(RecipientIdentifier.Single recipient);
234
235 void deleteRecipient(RecipientIdentifier.Single recipient);
236
237 void deleteContact(RecipientIdentifier.Single recipient);
238
239 void setContactName(
240 final RecipientIdentifier.Single recipient,
241 final String givenName,
242 final String familyName,
243 final String nickGivenName,
244 final String nickFamilyName,
245 final String note
246 ) throws NotPrimaryDeviceException, UnregisteredRecipientException;
247
248 void setContactsBlocked(
249 Collection<RecipientIdentifier.Single> recipient,
250 boolean blocked
251 ) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
252
253 void setGroupsBlocked(
254 Collection<GroupId> groupId,
255 boolean blocked
256 ) throws GroupNotFoundException, IOException, NotPrimaryDeviceException;
257
258 /**
259 * Change the expiration timer for a contact
260 */
261 void setExpirationTimer(
262 RecipientIdentifier.Single recipient,
263 int messageExpirationTimer
264 ) throws IOException, UnregisteredRecipientException;
265
266 /**
267 * Upload the sticker pack from path.
268 *
269 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
270 * @return if successful, returns the URL to install the sticker pack in the signal app
271 */
272 StickerPackUrl uploadStickerPack(File path) throws IOException, StickerPackInvalidException;
273
274 void installStickerPack(StickerPackUrl url) throws IOException;
275
276 List<StickerPack> getStickerPacks();
277
278 void requestAllSyncData() throws IOException;
279
280 /**
281 * Add a handler to receive new messages.
282 * Will start receiving messages from server, if not already started.
283 */
284 default void addReceiveHandler(ReceiveMessageHandler handler) {
285 addReceiveHandler(handler, false);
286 }
287
288 void addReceiveHandler(ReceiveMessageHandler handler, final boolean isWeakListener);
289
290 /**
291 * Remove a handler to receive new messages.
292 * Will stop receiving messages from server, if this was the last registered receiver.
293 */
294 void removeReceiveHandler(ReceiveMessageHandler handler);
295
296 boolean isReceiving();
297
298 /**
299 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
300 */
301 void receiveMessages(
302 Optional<Duration> timeout,
303 Optional<Integer> maxMessages,
304 ReceiveMessageHandler handler
305 ) throws IOException, AlreadyReceivingException;
306
307 void stopReceiveMessages();
308
309 void setReceiveConfig(ReceiveConfig receiveConfig);
310
311 boolean isContactBlocked(RecipientIdentifier.Single recipient);
312
313 void sendContacts() throws IOException;
314
315 List<Recipient> getRecipients(
316 boolean onlyContacts,
317 Optional<Boolean> blocked,
318 Collection<RecipientIdentifier.Single> address,
319 Optional<String> name
320 );
321
322 String getContactOrProfileName(RecipientIdentifier.Single recipient);
323
324 Group getGroup(GroupId groupId);
325
326 List<Identity> getIdentities();
327
328 List<Identity> getIdentities(RecipientIdentifier.Single recipient);
329
330 /**
331 * Trust this the identity with this fingerprint/safetyNumber
332 *
333 * @param recipient account of the identity
334 */
335 boolean trustIdentityVerified(
336 RecipientIdentifier.Single recipient,
337 IdentityVerificationCode verificationCode
338 ) throws UnregisteredRecipientException;
339
340 /**
341 * Trust all keys of this identity without verification
342 *
343 * @param recipient account of the identity
344 */
345 boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient) throws UnregisteredRecipientException;
346
347 void addAddressChangedListener(Runnable listener);
348
349 void addClosedListener(Runnable listener);
350
351 InputStream retrieveAttachment(final String id) throws IOException;
352
353 InputStream retrieveContactAvatar(final RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException;
354
355 InputStream retrieveProfileAvatar(final RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException;
356
357 InputStream retrieveGroupAvatar(final GroupId groupId) throws IOException;
358
359 InputStream retrieveSticker(final StickerPackId stickerPackId, final int stickerId) throws IOException;
360
361 @Override
362 void close();
363
364 interface ReceiveMessageHandler {
365
366 ReceiveMessageHandler EMPTY = (envelope, e) -> {
367 };
368
369 void handleMessage(MessageEnvelope envelope, Throwable e);
370 }
371 }