]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/Manager.java
0a8762d981d1c6b6329108c249cb159790f432fb
[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.Device;
4 import org.asamk.signal.manager.api.Group;
5 import org.asamk.signal.manager.api.Identity;
6 import org.asamk.signal.manager.api.Message;
7 import org.asamk.signal.manager.api.RecipientIdentifier;
8 import org.asamk.signal.manager.api.SendGroupMessageResults;
9 import org.asamk.signal.manager.api.SendMessageResults;
10 import org.asamk.signal.manager.api.TypingAction;
11 import org.asamk.signal.manager.api.UpdateGroup;
12 import org.asamk.signal.manager.config.ServiceConfig;
13 import org.asamk.signal.manager.config.ServiceEnvironment;
14 import org.asamk.signal.manager.groups.GroupId;
15 import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
16 import org.asamk.signal.manager.groups.GroupNotFoundException;
17 import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
18 import org.asamk.signal.manager.groups.LastGroupAdminException;
19 import org.asamk.signal.manager.groups.NotAGroupMemberException;
20 import org.asamk.signal.manager.storage.SignalAccount;
21 import org.asamk.signal.manager.storage.identities.TrustNewIdentity;
22 import org.asamk.signal.manager.storage.recipients.Contact;
23 import org.asamk.signal.manager.storage.recipients.Profile;
24 import org.asamk.signal.manager.storage.recipients.RecipientAddress;
25 import org.whispersystems.libsignal.InvalidKeyException;
26 import org.whispersystems.libsignal.util.Pair;
27 import org.whispersystems.libsignal.util.guava.Optional;
28 import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
29 import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentRemoteId;
30 import org.whispersystems.signalservice.api.messages.SignalServiceContent;
31 import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
32 import org.whispersystems.signalservice.api.push.SignalServiceAddress;
33 import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
34 import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
35 import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
36
37 import java.io.Closeable;
38 import java.io.File;
39 import java.io.IOException;
40 import java.net.URI;
41 import java.util.Arrays;
42 import java.util.List;
43 import java.util.Map;
44 import java.util.Set;
45 import java.util.UUID;
46 import java.util.concurrent.TimeUnit;
47 import java.util.stream.Collectors;
48
49 public interface Manager extends Closeable {
50
51 static Manager init(
52 String number,
53 File settingsPath,
54 ServiceEnvironment serviceEnvironment,
55 String userAgent,
56 TrustNewIdentity trustNewIdentity
57 ) throws IOException, NotRegisteredException {
58 var pathConfig = PathConfig.createDefault(settingsPath);
59
60 if (!SignalAccount.userExists(pathConfig.getDataPath(), number)) {
61 throw new NotRegisteredException();
62 }
63
64 var account = SignalAccount.load(pathConfig.getDataPath(), number, true, trustNewIdentity);
65
66 if (!account.isRegistered()) {
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 List<String> getAllLocalNumbers(File settingsPath) {
76 var pathConfig = PathConfig.createDefault(settingsPath);
77 final var dataPath = pathConfig.getDataPath();
78 final var files = dataPath.listFiles();
79
80 if (files == null) {
81 return List.of();
82 }
83
84 return Arrays.stream(files)
85 .filter(File::isFile)
86 .map(File::getName)
87 .filter(file -> PhoneNumberFormatter.isValidNumber(file, null))
88 .collect(Collectors.toList());
89 }
90
91 String getSelfNumber();
92
93 void checkAccountState() throws IOException;
94
95 Map<String, Pair<String, UUID>> areUsersRegistered(Set<String> numbers) throws IOException;
96
97 void updateAccountAttributes(String deviceName) throws IOException;
98
99 void updateConfiguration(
100 final Boolean readReceipts,
101 final Boolean unidentifiedDeliveryIndicators,
102 final Boolean typingIndicators,
103 final Boolean linkPreviews
104 ) throws IOException, NotMasterDeviceException;
105
106 void setProfile(
107 String givenName, String familyName, String about, String aboutEmoji, Optional<File> avatar
108 ) throws IOException;
109
110 void unregister() throws IOException;
111
112 void deleteAccount() throws IOException;
113
114 void submitRateLimitRecaptchaChallenge(String challenge, String captcha) throws IOException;
115
116 List<Device> getLinkedDevices() throws IOException;
117
118 void removeLinkedDevices(long deviceId) throws IOException;
119
120 void addDeviceLink(URI linkUri) throws IOException, InvalidKeyException;
121
122 void setRegistrationLockPin(Optional<String> pin) throws IOException, UnauthenticatedResponseException;
123
124 Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws UnregisteredUserException;
125
126 List<Group> getGroups();
127
128 SendGroupMessageResults quitGroup(
129 GroupId groupId, Set<RecipientIdentifier.Single> groupAdmins
130 ) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException;
131
132 void deleteGroup(GroupId groupId) throws IOException;
133
134 Pair<GroupId, SendGroupMessageResults> createGroup(
135 String name, Set<RecipientIdentifier.Single> members, File avatarFile
136 ) throws IOException, AttachmentInvalidException;
137
138 SendGroupMessageResults updateGroup(
139 final GroupId groupId, final UpdateGroup updateGroup
140 ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException;
141
142 Pair<GroupId, SendGroupMessageResults> joinGroup(
143 GroupInviteLinkUrl inviteLinkUrl
144 ) throws IOException, GroupLinkNotActiveException;
145
146 void sendTypingMessage(
147 TypingAction action, Set<RecipientIdentifier> recipients
148 ) throws IOException, UntrustedIdentityException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
149
150 void sendReadReceipt(
151 RecipientIdentifier.Single sender, List<Long> messageIds
152 ) throws IOException, UntrustedIdentityException;
153
154 void sendViewedReceipt(
155 RecipientIdentifier.Single sender, List<Long> messageIds
156 ) throws IOException, UntrustedIdentityException;
157
158 SendMessageResults sendMessage(
159 Message message, Set<RecipientIdentifier> recipients
160 ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
161
162 SendMessageResults sendRemoteDeleteMessage(
163 long targetSentTimestamp, Set<RecipientIdentifier> recipients
164 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
165
166 SendMessageResults sendMessageReaction(
167 String emoji,
168 boolean remove,
169 RecipientIdentifier.Single targetAuthor,
170 long targetSentTimestamp,
171 Set<RecipientIdentifier> recipients
172 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
173
174 SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
175
176 void setContactName(
177 RecipientIdentifier.Single recipient, String name
178 ) throws NotMasterDeviceException, UnregisteredUserException;
179
180 void setContactBlocked(
181 RecipientIdentifier.Single recipient, boolean blocked
182 ) throws NotMasterDeviceException, IOException;
183
184 void setGroupBlocked(
185 GroupId groupId, boolean blocked
186 ) throws GroupNotFoundException, IOException, NotMasterDeviceException;
187
188 void setExpirationTimer(
189 RecipientIdentifier.Single recipient, int messageExpirationTimer
190 ) throws IOException;
191
192 URI uploadStickerPack(File path) throws IOException, StickerPackInvalidException;
193
194 void requestAllSyncData() throws IOException;
195
196 /**
197 * Add a handler to receive new messages.
198 * Will start receiving messages from server, if not already started.
199 */
200 void addReceiveHandler(ReceiveMessageHandler handler);
201
202 /**
203 * Remove a handler to receive new messages.
204 * Will stop receiving messages from server, if this was the last registered receiver.
205 */
206 void removeReceiveHandler(ReceiveMessageHandler handler);
207
208 boolean isReceiving();
209
210 /**
211 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
212 */
213 void receiveMessages(long timeout, TimeUnit unit, ReceiveMessageHandler handler) throws IOException;
214
215 /**
216 * Receive new messages from server, returns only if the thread is interrupted.
217 */
218 void receiveMessages(ReceiveMessageHandler handler) throws IOException;
219
220 void setIgnoreAttachments(boolean ignoreAttachments);
221
222 boolean hasCaughtUpWithOldMessages();
223
224 boolean isContactBlocked(RecipientIdentifier.Single recipient);
225
226 File getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId);
227
228 void sendContacts() throws IOException;
229
230 List<Pair<RecipientAddress, Contact>> getContacts();
231
232 String getContactOrProfileName(RecipientIdentifier.Single recipient);
233
234 Group getGroup(GroupId groupId);
235
236 List<Identity> getIdentities();
237
238 List<Identity> getIdentities(RecipientIdentifier.Single recipient);
239
240 boolean trustIdentityVerified(RecipientIdentifier.Single recipient, byte[] fingerprint);
241
242 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier.Single recipient, String safetyNumber);
243
244 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier.Single recipient, byte[] safetyNumber);
245
246 boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient);
247
248 SignalServiceAddress resolveSignalServiceAddress(SignalServiceAddress address);
249
250 @Override
251 void close() throws IOException;
252
253 interface ReceiveMessageHandler {
254
255 void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent decryptedContent, Throwable e);
256 }
257 }