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