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