]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/Manager.java
Allow using data URIs for updateGroup/updateProfile avatars
[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.Message;
13 import org.asamk.signal.manager.api.MessageEnvelope;
14 import org.asamk.signal.manager.api.NotPrimaryDeviceException;
15 import org.asamk.signal.manager.api.Pair;
16 import org.asamk.signal.manager.api.PendingAdminApprovalException;
17 import org.asamk.signal.manager.api.ReceiveConfig;
18 import org.asamk.signal.manager.api.Recipient;
19 import org.asamk.signal.manager.api.RecipientIdentifier;
20 import org.asamk.signal.manager.api.SendGroupMessageResults;
21 import org.asamk.signal.manager.api.SendMessageResults;
22 import org.asamk.signal.manager.api.StickerPack;
23 import org.asamk.signal.manager.api.StickerPackInvalidException;
24 import org.asamk.signal.manager.api.StickerPackUrl;
25 import org.asamk.signal.manager.api.TypingAction;
26 import org.asamk.signal.manager.api.UnregisteredRecipientException;
27 import org.asamk.signal.manager.api.UpdateGroup;
28 import org.asamk.signal.manager.api.UpdateProfile;
29 import org.asamk.signal.manager.api.UserStatus;
30 import org.asamk.signal.manager.groups.GroupId;
31 import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
32 import org.asamk.signal.manager.groups.GroupNotFoundException;
33 import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
34 import org.asamk.signal.manager.groups.LastGroupAdminException;
35 import org.asamk.signal.manager.groups.NotAGroupMemberException;
36 import org.asamk.signal.manager.storage.recipients.Profile;
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 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, NotPrimaryDeviceException;
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, String 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, PendingAdminApprovalException;
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 final boolean isStory
143 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException;
144
145 SendMessageResults sendPaymentNotificationMessage(
146 byte[] receipt, String note, RecipientIdentifier.Single recipient
147 ) throws IOException;
148
149 SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
150
151 void deleteRecipient(RecipientIdentifier.Single recipient);
152
153 void deleteContact(RecipientIdentifier.Single recipient);
154
155 void setContactName(
156 RecipientIdentifier.Single recipient, String givenName, final String familyName
157 ) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
158
159 void setContactsBlocked(
160 Collection<RecipientIdentifier.Single> recipient, boolean blocked
161 ) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
162
163 void setGroupsBlocked(
164 Collection<GroupId> groupId, boolean blocked
165 ) throws GroupNotFoundException, IOException, NotPrimaryDeviceException;
166
167 /**
168 * Change the expiration timer for a contact
169 */
170 void setExpirationTimer(
171 RecipientIdentifier.Single recipient, int messageExpirationTimer
172 ) throws IOException, UnregisteredRecipientException;
173
174 /**
175 * Upload the sticker pack from path.
176 *
177 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
178 * @return if successful, returns the URL to install the sticker pack in the signal app
179 */
180 StickerPackUrl uploadStickerPack(File path) throws IOException, StickerPackInvalidException;
181
182 List<StickerPack> getStickerPacks();
183
184 void requestAllSyncData() throws IOException;
185
186 /**
187 * Add a handler to receive new messages.
188 * Will start receiving messages from server, if not already started.
189 */
190 default void addReceiveHandler(ReceiveMessageHandler handler) {
191 addReceiveHandler(handler, false);
192 }
193
194 void addReceiveHandler(ReceiveMessageHandler handler, final boolean isWeakListener);
195
196 /**
197 * Remove a handler to receive new messages.
198 * Will stop receiving messages from server, if this was the last registered receiver.
199 */
200 void removeReceiveHandler(ReceiveMessageHandler handler);
201
202 boolean isReceiving();
203
204 /**
205 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
206 */
207 public void receiveMessages(
208 Optional<Duration> timeout, Optional<Integer> maxMessages, ReceiveMessageHandler handler
209 ) throws IOException, AlreadyReceivingException;
210
211 void setReceiveConfig(ReceiveConfig receiveConfig);
212
213 boolean hasCaughtUpWithOldMessages();
214
215 boolean isContactBlocked(RecipientIdentifier.Single recipient);
216
217 void sendContacts() throws IOException;
218
219 List<Recipient> getRecipients(
220 boolean onlyContacts,
221 Optional<Boolean> blocked,
222 Collection<RecipientIdentifier.Single> address,
223 Optional<String> name
224 );
225
226 String getContactOrProfileName(RecipientIdentifier.Single recipient);
227
228 Group getGroup(GroupId groupId);
229
230 List<Identity> getIdentities();
231
232 List<Identity> getIdentities(RecipientIdentifier.Single recipient);
233
234 /**
235 * Trust this the identity with this fingerprint
236 *
237 * @param recipient account of the identity
238 * @param fingerprint Fingerprint
239 */
240 boolean trustIdentityVerified(
241 RecipientIdentifier.Single recipient, byte[] fingerprint
242 ) throws UnregisteredRecipientException;
243
244 /**
245 * Trust this the identity with this safety number
246 *
247 * @param recipient account of the identity
248 * @param safetyNumber Safety number
249 */
250 boolean trustIdentityVerifiedSafetyNumber(
251 RecipientIdentifier.Single recipient, String safetyNumber
252 ) throws UnregisteredRecipientException;
253
254 /**
255 * Trust this the identity with this scannable safety number
256 *
257 * @param recipient account of the identity
258 * @param safetyNumber Scannable safety number
259 */
260 boolean trustIdentityVerifiedSafetyNumber(
261 RecipientIdentifier.Single recipient, byte[] safetyNumber
262 ) throws UnregisteredRecipientException;
263
264 /**
265 * Trust all keys of this identity without verification
266 *
267 * @param recipient account of the identity
268 */
269 boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient) throws UnregisteredRecipientException;
270
271 void addAddressChangedListener(Runnable listener);
272
273 void addClosedListener(Runnable listener);
274
275 InputStream retrieveAttachment(final String id) throws IOException;
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 }