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