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