]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/Manager.java
Merge branch master into dbus_updateConfiguration
[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 List<Boolean> getConfiguration() 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(long 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 final GroupId groupId, final UpdateGroup updateGroup
142 ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException;
143
144 Pair<GroupId, SendGroupMessageResults> joinGroup(
145 GroupInviteLinkUrl inviteLinkUrl
146 ) throws IOException, GroupLinkNotActiveException;
147
148 void sendTypingMessage(
149 TypingAction action, Set<RecipientIdentifier> recipients
150 ) throws IOException, UntrustedIdentityException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
151
152 void sendReadReceipt(
153 RecipientIdentifier.Single sender, List<Long> messageIds
154 ) throws IOException, UntrustedIdentityException;
155
156 void sendViewedReceipt(
157 RecipientIdentifier.Single sender, List<Long> messageIds
158 ) throws IOException, UntrustedIdentityException;
159
160 SendMessageResults sendMessage(
161 Message message, Set<RecipientIdentifier> recipients
162 ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
163
164 SendMessageResults sendRemoteDeleteMessage(
165 long targetSentTimestamp, Set<RecipientIdentifier> recipients
166 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
167
168 SendMessageResults sendMessageReaction(
169 String emoji,
170 boolean remove,
171 RecipientIdentifier.Single targetAuthor,
172 long targetSentTimestamp,
173 Set<RecipientIdentifier> recipients
174 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
175
176 SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
177
178 void setContactName(
179 RecipientIdentifier.Single recipient, String name
180 ) throws NotMasterDeviceException, UnregisteredUserException;
181
182 void setContactBlocked(
183 RecipientIdentifier.Single recipient, boolean blocked
184 ) throws NotMasterDeviceException, IOException;
185
186 void setGroupBlocked(
187 GroupId groupId, boolean blocked
188 ) throws GroupNotFoundException, IOException, NotMasterDeviceException;
189
190 void setExpirationTimer(
191 RecipientIdentifier.Single recipient, int messageExpirationTimer
192 ) throws IOException;
193
194 URI uploadStickerPack(File path) throws IOException, StickerPackInvalidException;
195
196 void requestAllSyncData() throws IOException;
197
198 void receiveMessages(
199 long timeout,
200 TimeUnit unit,
201 boolean returnOnTimeout,
202 boolean ignoreAttachments,
203 ReceiveMessageHandler handler
204 ) throws IOException;
205
206 boolean hasCaughtUpWithOldMessages();
207
208 boolean isContactBlocked(RecipientIdentifier.Single recipient);
209
210 File getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId);
211
212 void sendContacts() throws IOException;
213
214 List<Pair<RecipientAddress, Contact>> getContacts();
215
216 String getContactOrProfileName(RecipientIdentifier.Single recipient);
217
218 Group getGroup(GroupId groupId);
219
220 List<Identity> getIdentities();
221
222 List<Identity> getIdentities(RecipientIdentifier.Single recipient);
223
224 boolean trustIdentityVerified(RecipientIdentifier.Single recipient, byte[] fingerprint);
225
226 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier.Single recipient, String safetyNumber);
227
228 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier.Single recipient, byte[] safetyNumber);
229
230 boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient);
231
232 SignalServiceAddress resolveSignalServiceAddress(SignalServiceAddress address);
233
234 @Override
235 void close() throws IOException;
236
237 interface ReceiveMessageHandler {
238
239 void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent decryptedContent, Throwable e);
240 }
241 }