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