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