1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.manager
.api
.Configuration
;
4 import org
.asamk
.signal
.manager
.api
.Device
;
5 import org
.asamk
.signal
.manager
.api
.Group
;
6 import org
.asamk
.signal
.manager
.api
.Identity
;
7 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
8 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
9 import org
.asamk
.signal
.manager
.api
.Message
;
10 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
11 import org
.asamk
.signal
.manager
.api
.Pair
;
12 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
13 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
14 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
15 import org
.asamk
.signal
.manager
.api
.TypingAction
;
16 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
17 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
18 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
19 import org
.asamk
.signal
.manager
.groups
.GroupId
;
20 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
21 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
22 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
23 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
24 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
25 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
26 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
27 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
28 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
29 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
30 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
32 import java
.io
.Closeable
;
34 import java
.io
.IOException
;
36 import java
.util
.Arrays
;
37 import java
.util
.List
;
39 import java
.util
.Optional
;
41 import java
.util
.UUID
;
42 import java
.util
.concurrent
.TimeUnit
;
43 import java
.util
.stream
.Collectors
;
45 public interface Manager
extends Closeable
{
50 ServiceEnvironment serviceEnvironment
,
52 TrustNewIdentity trustNewIdentity
53 ) throws IOException
, NotRegisteredException
{
54 var pathConfig
= PathConfig
.createDefault(settingsPath
);
56 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
57 throw new NotRegisteredException();
60 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
62 if (!account
.isRegistered()) {
64 throw new NotRegisteredException();
67 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
69 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
72 static void initLogger() {
73 LibSignalLogger
.initLogger();
76 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
77 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
80 static List
<String
> getAllLocalAccountNumbers(File settingsPath
) {
81 var pathConfig
= PathConfig
.createDefault(settingsPath
);
82 final var dataPath
= pathConfig
.dataPath();
83 final var files
= dataPath
.listFiles();
89 return Arrays
.stream(files
)
92 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
93 .collect(Collectors
.toList());
96 String
getSelfNumber();
98 void checkAccountState() throws IOException
;
100 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
102 void updateAccountAttributes(String deviceName
) throws IOException
;
104 Configuration
getConfiguration();
106 void updateConfiguration(Configuration configuration
) throws IOException
, NotMasterDeviceException
;
109 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
110 ) throws IOException
;
112 void unregister() throws IOException
;
114 void deleteAccount() throws IOException
;
116 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
118 List
<Device
> getLinkedDevices() throws IOException
;
120 void removeLinkedDevices(long deviceId
) throws IOException
;
122 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
124 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
;
126 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
;
128 List
<Group
> getGroups();
130 SendGroupMessageResults
quitGroup(
131 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
132 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
;
134 void deleteGroup(GroupId groupId
) throws IOException
;
136 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
137 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
138 ) throws IOException
, AttachmentInvalidException
;
140 SendGroupMessageResults
updateGroup(
141 final GroupId groupId
, final UpdateGroup updateGroup
142 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
;
144 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
145 GroupInviteLinkUrl inviteLinkUrl
146 ) throws IOException
, InactiveGroupLinkException
;
148 SendMessageResults
sendTypingMessage(
149 TypingAction action
, Set
<RecipientIdentifier
> recipients
150 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
152 SendMessageResults
sendReadReceipt(
153 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
154 ) throws IOException
;
156 SendMessageResults
sendViewedReceipt(
157 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
158 ) throws IOException
;
160 SendMessageResults
sendMessage(
161 Message message
, Set
<RecipientIdentifier
> recipients
162 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
164 SendMessageResults
sendRemoteDeleteMessage(
165 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
166 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
168 SendMessageResults
sendMessageReaction(
171 RecipientIdentifier
.Single targetAuthor
,
172 long targetSentTimestamp
,
173 Set
<RecipientIdentifier
> recipients
174 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
176 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
178 void deleteRecipient(RecipientIdentifier
.Single recipient
) throws IOException
;
180 void deleteContact(RecipientIdentifier
.Single recipient
) throws IOException
;
183 RecipientIdentifier
.Single recipient
, String name
184 ) throws NotMasterDeviceException
, IOException
;
186 void setContactBlocked(
187 RecipientIdentifier
.Single recipient
, boolean blocked
188 ) throws NotMasterDeviceException
, IOException
;
190 void setGroupBlocked(
191 GroupId groupId
, boolean blocked
192 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
194 void setExpirationTimer(
195 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
196 ) throws IOException
;
198 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
200 void requestAllSyncData() throws IOException
;
203 * Add a handler to receive new messages.
204 * Will start receiving messages from server, if not already started.
206 default void addReceiveHandler(ReceiveMessageHandler handler
) {
207 addReceiveHandler(handler
, false);
210 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
213 * Remove a handler to receive new messages.
214 * Will stop receiving messages from server, if this was the last registered receiver.
216 void removeReceiveHandler(ReceiveMessageHandler handler
);
218 boolean isReceiving();
221 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
223 void receiveMessages(long timeout
, TimeUnit unit
, ReceiveMessageHandler handler
) throws IOException
;
226 * Receive new messages from server, returns only if the thread is interrupted.
228 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
230 void setIgnoreAttachments(boolean ignoreAttachments
);
232 boolean hasCaughtUpWithOldMessages();
234 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
236 void sendContacts() throws IOException
;
238 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
240 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
242 Group
getGroup(GroupId groupId
);
244 List
<Identity
> getIdentities();
246 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
248 boolean trustIdentityVerified(RecipientIdentifier
.Single recipient
, byte[] fingerprint
);
250 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, String safetyNumber
);
252 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, byte[] safetyNumber
);
254 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
);
256 void addClosedListener(Runnable listener
);
259 void close() throws IOException
;
261 interface ReceiveMessageHandler
{
263 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
266 void handleMessage(MessageEnvelope envelope
, Throwable e
);