]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/Manager.java
Implement sendPayment notification command
[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.Profile;
32 import org.asamk.signal.manager.storage.recipients.Recipient;
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.Collection;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Optional;
44 import java.util.Set;
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, UserStatus> getUserStatus(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 sendPaymentNotificationMessage(
145 byte[] receipt, String note, RecipientIdentifier.Single recipient
146 ) throws IOException;
147
148 SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
149
150 void deleteRecipient(RecipientIdentifier.Single recipient);
151
152 void deleteContact(RecipientIdentifier.Single recipient);
153
154 void setContactName(
155 RecipientIdentifier.Single recipient, String name
156 ) throws NotMasterDeviceException, IOException, UnregisteredRecipientException;
157
158 void setContactsBlocked(
159 Collection<RecipientIdentifier.Single> recipient, boolean blocked
160 ) throws NotMasterDeviceException, IOException, UnregisteredRecipientException;
161
162 void setGroupsBlocked(
163 Collection<GroupId> groupId, boolean blocked
164 ) throws GroupNotFoundException, IOException, NotMasterDeviceException;
165
166 /**
167 * Change the expiration timer for a contact
168 */
169 void setExpirationTimer(
170 RecipientIdentifier.Single recipient, int messageExpirationTimer
171 ) throws IOException, UnregisteredRecipientException;
172
173 /**
174 * Upload the sticker pack from path.
175 *
176 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
177 * @return if successful, returns the URL to install the sticker pack in the signal app
178 */
179 StickerPackUrl uploadStickerPack(File path) throws IOException, StickerPackInvalidException;
180
181 List<StickerPack> getStickerPacks();
182
183 void requestAllSyncData() throws IOException;
184
185 /**
186 * Add a handler to receive new messages.
187 * Will start receiving messages from server, if not already started.
188 */
189 default void addReceiveHandler(ReceiveMessageHandler handler) {
190 addReceiveHandler(handler, false);
191 }
192
193 void addReceiveHandler(ReceiveMessageHandler handler, final boolean isWeakListener);
194
195 /**
196 * Remove a handler to receive new messages.
197 * Will stop receiving messages from server, if this was the last registered receiver.
198 */
199 void removeReceiveHandler(ReceiveMessageHandler handler);
200
201 boolean isReceiving();
202
203 /**
204 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
205 */
206 void receiveMessages(Duration timeout, ReceiveMessageHandler handler) throws IOException;
207
208 /**
209 * Receive new messages from server, returns only if the thread is interrupted.
210 */
211 void receiveMessages(ReceiveMessageHandler handler) throws IOException;
212
213 void setIgnoreAttachments(boolean ignoreAttachments);
214
215 boolean hasCaughtUpWithOldMessages();
216
217 boolean isContactBlocked(RecipientIdentifier.Single recipient);
218
219 void sendContacts() throws IOException;
220
221 List<Recipient> getRecipients(
222 boolean onlyContacts,
223 Optional<Boolean> blocked,
224 Collection<RecipientIdentifier.Single> address,
225 Optional<String> name
226 );
227
228 String getContactOrProfileName(RecipientIdentifier.Single recipient);
229
230 Group getGroup(GroupId groupId);
231
232 List<Identity> getIdentities();
233
234 List<Identity> getIdentities(RecipientIdentifier.Single recipient);
235
236 /**
237 * Trust this the identity with this fingerprint
238 *
239 * @param recipient account of the identity
240 * @param fingerprint Fingerprint
241 */
242 boolean trustIdentityVerified(
243 RecipientIdentifier.Single recipient, byte[] fingerprint
244 ) throws UnregisteredRecipientException;
245
246 /**
247 * Trust this the identity with this safety number
248 *
249 * @param recipient account of the identity
250 * @param safetyNumber Safety number
251 */
252 boolean trustIdentityVerifiedSafetyNumber(
253 RecipientIdentifier.Single recipient, String safetyNumber
254 ) throws UnregisteredRecipientException;
255
256 /**
257 * Trust this the identity with this scannable safety number
258 *
259 * @param recipient account of the identity
260 * @param safetyNumber Scannable safety number
261 */
262 boolean trustIdentityVerifiedSafetyNumber(
263 RecipientIdentifier.Single recipient, byte[] safetyNumber
264 ) throws UnregisteredRecipientException;
265
266 /**
267 * Trust all keys of this identity without verification
268 *
269 * @param recipient account of the identity
270 */
271 boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient) throws UnregisteredRecipientException;
272
273 void addAddressChangedListener(Runnable listener);
274
275 void addClosedListener(Runnable listener);
276
277 @Override
278 void close() throws IOException;
279
280 interface ReceiveMessageHandler {
281
282 ReceiveMessageHandler EMPTY = (envelope, e) -> {
283 };
284
285 void handleMessage(MessageEnvelope envelope, Throwable e);
286 }
287 }