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