1 package org
.asamk
.signal
.manager
;
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
;
35 import java
.io
.Closeable
;
37 import java
.io
.IOException
;
39 import java
.util
.Arrays
;
40 import java
.util
.List
;
42 import java
.util
.Optional
;
44 import java
.util
.UUID
;
45 import java
.util
.concurrent
.TimeUnit
;
46 import java
.util
.stream
.Collectors
;
48 public interface Manager
extends Closeable
{
53 ServiceEnvironment serviceEnvironment
,
55 TrustNewIdentity trustNewIdentity
56 ) throws IOException
, NotRegisteredException
{
57 var pathConfig
= PathConfig
.createDefault(settingsPath
);
59 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
60 throw new NotRegisteredException();
63 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
65 if (!account
.isRegistered()) {
66 throw new NotRegisteredException();
69 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
71 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
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();
83 return Arrays
.stream(files
)
86 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
87 .collect(Collectors
.toList());
90 String
getSelfNumber();
92 void checkAccountState() throws IOException
;
94 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
96 void updateAccountAttributes(String deviceName
) throws IOException
;
98 void updateConfiguration(
99 final Boolean readReceipts
,
100 final Boolean unidentifiedDeliveryIndicators
,
101 final Boolean typingIndicators
,
102 final Boolean linkPreviews
103 ) throws IOException
, NotMasterDeviceException
;
106 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
107 ) throws IOException
;
109 void unregister() throws IOException
;
111 void deleteAccount() throws IOException
;
113 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
115 List
<Device
> getLinkedDevices() throws IOException
;
117 void removeLinkedDevices(long deviceId
) throws IOException
;
119 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
121 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, UnauthenticatedResponseException
;
123 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
;
125 List
<Group
> getGroups();
127 SendGroupMessageResults
quitGroup(
128 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
129 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
;
131 void deleteGroup(GroupId groupId
) throws IOException
;
133 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
134 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
135 ) throws IOException
, AttachmentInvalidException
;
137 SendGroupMessageResults
updateGroup(
138 final GroupId groupId
, final UpdateGroup updateGroup
139 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
;
141 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
142 GroupInviteLinkUrl inviteLinkUrl
143 ) throws IOException
, InactiveGroupLinkException
;
145 void sendTypingMessage(
146 TypingAction action
, Set
<RecipientIdentifier
> recipients
147 ) throws IOException
, UntrustedIdentityException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
149 void sendReadReceipt(
150 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
151 ) throws IOException
, UntrustedIdentityException
;
153 void sendViewedReceipt(
154 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
155 ) throws IOException
, UntrustedIdentityException
;
157 SendMessageResults
sendMessage(
158 Message message
, Set
<RecipientIdentifier
> recipients
159 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
161 SendMessageResults
sendRemoteDeleteMessage(
162 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
163 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
165 SendMessageResults
sendMessageReaction(
168 RecipientIdentifier
.Single targetAuthor
,
169 long targetSentTimestamp
,
170 Set
<RecipientIdentifier
> recipients
171 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
173 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
176 RecipientIdentifier
.Single recipient
, String name
177 ) throws NotMasterDeviceException
, IOException
;
179 void setContactBlocked(
180 RecipientIdentifier
.Single recipient
, boolean blocked
181 ) throws NotMasterDeviceException
, IOException
;
183 void setGroupBlocked(
184 GroupId groupId
, boolean blocked
185 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
187 void setExpirationTimer(
188 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
189 ) throws IOException
;
191 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
193 void requestAllSyncData() throws IOException
;
196 * Add a handler to receive new messages.
197 * Will start receiving messages from server, if not already started.
199 void addReceiveHandler(ReceiveMessageHandler handler
);
202 * Remove a handler to receive new messages.
203 * Will stop receiving messages from server, if this was the last registered receiver.
205 void removeReceiveHandler(ReceiveMessageHandler handler
);
207 boolean isReceiving();
210 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
212 void receiveMessages(long timeout
, TimeUnit unit
, ReceiveMessageHandler handler
) throws IOException
;
215 * Receive new messages from server, returns only if the thread is interrupted.
217 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
219 void setIgnoreAttachments(boolean ignoreAttachments
);
221 boolean hasCaughtUpWithOldMessages();
223 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
225 File
getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId
);
227 void sendContacts() throws IOException
;
229 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
231 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
233 Group
getGroup(GroupId groupId
);
235 List
<Identity
> getIdentities();
237 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
239 boolean trustIdentityVerified(RecipientIdentifier
.Single recipient
, byte[] fingerprint
);
241 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, String safetyNumber
);
243 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, byte[] safetyNumber
);
245 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
);
247 SignalServiceAddress
resolveSignalServiceAddress(SignalServiceAddress address
);
250 void close() throws IOException
;
252 interface ReceiveMessageHandler
{
254 void handleMessage(SignalServiceEnvelope envelope
, SignalServiceContent decryptedContent
, Throwable e
);