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