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