]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/Manager.java
Dbus get/setConfiguration methods
[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 List<Boolean> getConfiguration() throws IOException, NotMasterDeviceException;
109
110 void setProfile(
111 String givenName, String familyName, String about, String aboutEmoji, Optional<File> avatar
112 ) throws IOException;
113
114 void unregister() throws IOException;
115
116 void deleteAccount() throws IOException;
117
118 void submitRateLimitRecaptchaChallenge(String challenge, String captcha) throws IOException;
119
120 List<Device> getLinkedDevices() throws IOException;
121
122 void removeLinkedDevices(long deviceId) throws IOException;
123
124 void addDeviceLink(URI linkUri) throws IOException, InvalidKeyException;
125
126 void setRegistrationLockPin(Optional<String> pin) throws IOException, UnauthenticatedResponseException;
127
128 Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws UnregisteredUserException;
129
130 List<Group> getGroups();
131
132 SendGroupMessageResults quitGroup(
133 GroupId groupId, Set<RecipientIdentifier.Single> groupAdmins
134 ) throws GroupNotFoundException, IOException, NotAGroupMemberException, LastGroupAdminException;
135
136 void deleteGroup(GroupId groupId) throws IOException;
137
138 Pair<GroupId, SendGroupMessageResults> createGroup(
139 String name, Set<RecipientIdentifier.Single> members, File avatarFile
140 ) throws IOException, AttachmentInvalidException;
141
142 SendGroupMessageResults updateGroup(
143 GroupId groupId,
144 String name,
145 String description,
146 Set<RecipientIdentifier.Single> members,
147 Set<RecipientIdentifier.Single> removeMembers,
148 Set<RecipientIdentifier.Single> admins,
149 Set<RecipientIdentifier.Single> removeAdmins,
150 boolean resetGroupLink,
151 GroupLinkState groupLinkState,
152 GroupPermission addMemberPermission,
153 GroupPermission editDetailsPermission,
154 File avatarFile,
155 Integer expirationTimer,
156 Boolean isAnnouncementGroup
157 ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException;
158
159 Pair<GroupId, SendGroupMessageResults> joinGroup(
160 GroupInviteLinkUrl inviteLinkUrl
161 ) throws IOException, GroupLinkNotActiveException;
162
163 void sendTypingMessage(
164 TypingAction action, Set<RecipientIdentifier> recipients
165 ) throws IOException, UntrustedIdentityException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
166
167 void sendReadReceipt(
168 RecipientIdentifier.Single sender, List<Long> messageIds
169 ) throws IOException, UntrustedIdentityException;
170
171 void sendViewedReceipt(
172 RecipientIdentifier.Single sender, List<Long> messageIds
173 ) throws IOException, UntrustedIdentityException;
174
175 SendMessageResults sendMessage(
176 Message message, Set<RecipientIdentifier> recipients
177 ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
178
179 SendMessageResults sendRemoteDeleteMessage(
180 long targetSentTimestamp, Set<RecipientIdentifier> recipients
181 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
182
183 SendMessageResults sendMessageReaction(
184 String emoji,
185 boolean remove,
186 RecipientIdentifier.Single targetAuthor,
187 long targetSentTimestamp,
188 Set<RecipientIdentifier> recipients
189 ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException;
190
191 SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
192
193 void setContactName(
194 RecipientIdentifier.Single recipient, String name
195 ) throws NotMasterDeviceException, UnregisteredUserException;
196
197 void setContactBlocked(
198 RecipientIdentifier.Single recipient, boolean blocked
199 ) throws NotMasterDeviceException, IOException;
200
201 void setGroupBlocked(
202 GroupId groupId, boolean blocked
203 ) throws GroupNotFoundException, IOException;
204
205 void setExpirationTimer(
206 RecipientIdentifier.Single recipient, int messageExpirationTimer
207 ) throws IOException;
208
209 URI uploadStickerPack(File path) throws IOException, StickerPackInvalidException;
210
211 void requestAllSyncData() throws IOException;
212
213 void receiveMessages(
214 long timeout,
215 TimeUnit unit,
216 boolean returnOnTimeout,
217 boolean ignoreAttachments,
218 ReceiveMessageHandler handler
219 ) throws IOException;
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 String computeSafetyNumber(SignalServiceAddress theirAddress, IdentityKey theirIdentityKey);
248
249 SignalServiceAddress resolveSignalServiceAddress(SignalServiceAddress address);
250
251 @Override
252 void close() throws IOException;
253
254 interface ReceiveMessageHandler {
255
256 void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent decryptedContent, Throwable e);
257 }
258 }