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