]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/Manager.java
Refresh pre keys after receiving a sync message with PNI identity
[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.UpdateProfile;
25 import org.asamk.signal.manager.api.UserStatus;
26 import org.asamk.signal.manager.groups.GroupId;
27 import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
28 import org.asamk.signal.manager.groups.GroupNotFoundException;
29 import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
30 import org.asamk.signal.manager.groups.LastGroupAdminException;
31 import org.asamk.signal.manager.groups.NotAGroupMemberException;
32 import org.asamk.signal.manager.storage.recipients.Profile;
33 import org.asamk.signal.manager.storage.recipients.Recipient;
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 * Update the user's profile.
72 * If a field is null, the previous value will be kept.
73 */
74 void updateProfile(UpdateProfile updateProfile) throws IOException;
75
76 void unregister() throws IOException;
77
78 void deleteAccount() throws IOException;
79
80 void submitRateLimitRecaptchaChallenge(String challenge, String captcha) throws IOException;
81
82 List<Device> getLinkedDevices() throws IOException;
83
84 void removeLinkedDevices(int deviceId) throws IOException;
85
86 void addDeviceLink(URI linkUri) throws IOException, InvalidDeviceLinkException;
87
88 void setRegistrationLockPin(Optional<String> pin) throws IOException, NotMasterDeviceException;
89
90 Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws IOException, UnregisteredRecipientException;
91
92 List<Group> getGroups();
93
94 SendGroupMessageResults quitGroup(
95 GroupId groupId, Set<RecipientIdentifier.Single> groupAdmins
96 ) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException, UnregisteredRecipientException;
97
98 void deleteGroup(GroupId groupId) throws IOException;
99
100 Pair<GroupId, SendGroupMessageResults> createGroup(
101 String name, Set<RecipientIdentifier.Single> members, File avatarFile
102 ) throws IOException, AttachmentInvalidException, UnregisteredRecipientException;
103
104 SendGroupMessageResults updateGroup(
105 final GroupId groupId, final UpdateGroup updateGroup
106 ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException, UnregisteredRecipientException;
107
108 Pair<GroupId, SendGroupMessageResults> joinGroup(
109 GroupInviteLinkUrl inviteLinkUrl
110 ) throws IOException, InactiveGroupLinkException;
111
112 SendMessageResults sendTypingMessage(
113 TypingAction action, Set<RecipientIdentifier> recipients
114 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
115
116 SendMessageResults sendReadReceipt(
117 RecipientIdentifier.Single sender, List<Long> messageIds
118 ) throws IOException;
119
120 SendMessageResults sendViewedReceipt(
121 RecipientIdentifier.Single sender, List<Long> messageIds
122 ) throws IOException;
123
124 SendMessageResults sendMessage(
125 Message message, Set<RecipientIdentifier> recipients
126 ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException, InvalidStickerException;
127
128 SendMessageResults sendRemoteDeleteMessage(
129 long targetSentTimestamp, Set<RecipientIdentifier> recipients
130 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
131
132 SendMessageResults sendMessageReaction(
133 String emoji,
134 boolean remove,
135 RecipientIdentifier.Single targetAuthor,
136 long targetSentTimestamp,
137 Set<RecipientIdentifier> recipients
138 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException;
139
140 SendMessageResults sendPaymentNotificationMessage(
141 byte[] receipt, String note, RecipientIdentifier.Single recipient
142 ) throws IOException;
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 setContactsBlocked(
155 Collection<RecipientIdentifier.Single> recipient, boolean blocked
156 ) throws NotMasterDeviceException, IOException, UnregisteredRecipientException;
157
158 void setGroupsBlocked(
159 Collection<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<Recipient> getRecipients(
218 boolean onlyContacts,
219 Optional<Boolean> blocked,
220 Collection<RecipientIdentifier.Single> address,
221 Optional<String> name
222 );
223
224 String getContactOrProfileName(RecipientIdentifier.Single recipient);
225
226 Group getGroup(GroupId groupId);
227
228 List<Identity> getIdentities();
229
230 List<Identity> getIdentities(RecipientIdentifier.Single recipient);
231
232 /**
233 * Trust this the identity with this fingerprint
234 *
235 * @param recipient account of the identity
236 * @param fingerprint Fingerprint
237 */
238 boolean trustIdentityVerified(
239 RecipientIdentifier.Single recipient, byte[] fingerprint
240 ) throws UnregisteredRecipientException;
241
242 /**
243 * Trust this the identity with this safety number
244 *
245 * @param recipient account of the identity
246 * @param safetyNumber Safety number
247 */
248 boolean trustIdentityVerifiedSafetyNumber(
249 RecipientIdentifier.Single recipient, String safetyNumber
250 ) throws UnregisteredRecipientException;
251
252 /**
253 * Trust this the identity with this scannable safety number
254 *
255 * @param recipient account of the identity
256 * @param safetyNumber Scannable safety number
257 */
258 boolean trustIdentityVerifiedSafetyNumber(
259 RecipientIdentifier.Single recipient, byte[] safetyNumber
260 ) throws UnregisteredRecipientException;
261
262 /**
263 * Trust all keys of this identity without verification
264 *
265 * @param recipient account of the identity
266 */
267 boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient) throws UnregisteredRecipientException;
268
269 void addAddressChangedListener(Runnable listener);
270
271 void addClosedListener(Runnable listener);
272
273 @Override
274 void close() throws IOException;
275
276 interface ReceiveMessageHandler {
277
278 ReceiveMessageHandler EMPTY = (envelope, e) -> {
279 };
280
281 void handleMessage(MessageEnvelope envelope, Throwable e);
282 }
283 }