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