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