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