]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/Manager.java
Implement configuration handling
[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.config.ServiceConfig;
12 import org.asamk.signal.manager.config.ServiceEnvironment;
13 import org.asamk.signal.manager.groups.GroupId;
14 import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
15 import org.asamk.signal.manager.groups.GroupLinkState;
16 import org.asamk.signal.manager.groups.GroupNotFoundException;
17 import org.asamk.signal.manager.groups.GroupPermission;
18 import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
19 import org.asamk.signal.manager.groups.LastGroupAdminException;
20 import org.asamk.signal.manager.groups.NotAGroupMemberException;
21 import org.asamk.signal.manager.storage.SignalAccount;
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.RecipientAddress;
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 number,
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(), number)) {
63 throw new NotRegisteredException();
64 }
65
66 var account = SignalAccount.load(pathConfig.getDataPath(), number, 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> getAllLocalNumbers(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 getSelfNumber();
94
95 void checkAccountState() throws IOException;
96
97 Map<String, Pair<String, UUID>> areUsersRegistered(Set<String> numbers) throws IOException;
98
99 void updateAccountAttributes(String deviceName) throws IOException;
100
101 void updateConfiguration(
102 final Boolean readReceipts,
103 final Boolean unidentifiedDeliveryIndicators,
104 final Boolean typingIndicators,
105 final Boolean linkPreviews
106 ) throws IOException, NotMasterDeviceException;
107
108 void setProfile(
109 String givenName, String familyName, String about, String aboutEmoji, Optional<File> avatar
110 ) throws IOException;
111
112 void unregister() throws IOException;
113
114 void deleteAccount() throws IOException;
115
116 void submitRateLimitRecaptchaChallenge(String challenge, String captcha) throws IOException;
117
118 List<Device> getLinkedDevices() throws IOException;
119
120 void removeLinkedDevices(int deviceId) throws IOException;
121
122 void addDeviceLink(URI linkUri) throws IOException, InvalidKeyException;
123
124 void setRegistrationLockPin(Optional<String> pin) throws IOException, UnauthenticatedResponseException;
125
126 Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws UnregisteredUserException;
127
128 List<Group> getGroups();
129
130 SendGroupMessageResults quitGroup(
131 GroupId groupId, Set<RecipientIdentifier.Single> groupAdmins
132 ) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException;
133
134 void deleteGroup(GroupId groupId) throws IOException;
135
136 Pair<GroupId, SendGroupMessageResults> createGroup(
137 String name, Set<RecipientIdentifier.Single> members, File avatarFile
138 ) throws IOException, AttachmentInvalidException;
139
140 SendGroupMessageResults updateGroup(
141 GroupId groupId,
142 String name,
143 String description,
144 Set<RecipientIdentifier.Single> members,
145 Set<RecipientIdentifier.Single> removeMembers,
146 Set<RecipientIdentifier.Single> admins,
147 Set<RecipientIdentifier.Single> removeAdmins,
148 boolean resetGroupLink,
149 GroupLinkState groupLinkState,
150 GroupPermission addMemberPermission,
151 GroupPermission editDetailsPermission,
152 File avatarFile,
153 Integer expirationTimer,
154 Boolean isAnnouncementGroup
155 ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException;
156
157 Pair<GroupId, SendGroupMessageResults> joinGroup(
158 GroupInviteLinkUrl inviteLinkUrl
159 ) throws IOException, GroupLinkNotActiveException;
160
161 void sendTypingMessage(
162 TypingAction action, Set<RecipientIdentifier> recipients
163 ) throws IOException, UntrustedIdentityException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
164
165 void sendReadReceipt(
166 RecipientIdentifier.Single sender, List<Long> messageIds
167 ) throws IOException, UntrustedIdentityException;
168
169 void sendViewedReceipt(
170 RecipientIdentifier.Single sender, List<Long> messageIds
171 ) throws IOException, UntrustedIdentityException;
172
173 SendMessageResults sendMessage(
174 Message message, Set<RecipientIdentifier> recipients
175 ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
176
177 SendMessageResults sendRemoteDeleteMessage(
178 long targetSentTimestamp, Set<RecipientIdentifier> recipients
179 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
180
181 SendMessageResults sendMessageReaction(
182 String emoji,
183 boolean remove,
184 RecipientIdentifier.Single targetAuthor,
185 long targetSentTimestamp,
186 Set<RecipientIdentifier> recipients
187 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
188
189 SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
190
191 void setContactName(
192 RecipientIdentifier.Single recipient, String name
193 ) throws NotMasterDeviceException, UnregisteredUserException;
194
195 void setContactBlocked(
196 RecipientIdentifier.Single recipient, boolean blocked
197 ) throws NotMasterDeviceException, IOException;
198
199 void setGroupBlocked(
200 GroupId groupId, boolean blocked
201 ) throws GroupNotFoundException, IOException;
202
203 void setExpirationTimer(
204 RecipientIdentifier.Single recipient, int messageExpirationTimer
205 ) throws IOException;
206
207 URI uploadStickerPack(File path) throws IOException, StickerPackInvalidException;
208
209 void requestAllSyncData() throws IOException;
210
211 void receiveMessages(
212 long timeout,
213 TimeUnit unit,
214 boolean returnOnTimeout,
215 boolean ignoreAttachments,
216 ReceiveMessageHandler handler
217 ) throws IOException;
218
219 boolean hasCaughtUpWithOldMessages();
220
221 boolean isContactBlocked(RecipientIdentifier.Single recipient);
222
223 File getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId);
224
225 void sendContacts() throws IOException;
226
227 List<Pair<RecipientAddress, Contact>> getContacts();
228
229 String getContactOrProfileName(RecipientIdentifier.Single recipient);
230
231 Group getGroup(GroupId groupId);
232
233 List<Identity> getIdentities();
234
235 List<Identity> getIdentities(RecipientIdentifier.Single recipient);
236
237 boolean trustIdentityVerified(RecipientIdentifier.Single recipient, byte[] fingerprint);
238
239 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier.Single recipient, String safetyNumber);
240
241 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier.Single recipient, byte[] safetyNumber);
242
243 boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient);
244
245 String computeSafetyNumber(SignalServiceAddress theirAddress, IdentityKey theirIdentityKey);
246
247 SignalServiceAddress resolveSignalServiceAddress(SignalServiceAddress address);
248
249 @Override
250 void close() throws IOException;
251
252 interface ReceiveMessageHandler {
253
254 void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent decryptedContent, Throwable e);
255 }
256 }