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