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