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