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