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