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
.MessageEnvelope
;
10 import org
.asamk
.signal
.manager
.api
.Pair
;
11 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
12 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
13 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
14 import org
.asamk
.signal
.manager
.api
.TypingAction
;
15 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
16 import org
.asamk
.signal
.manager
.config
.ServiceConfig
;
17 import org
.asamk
.signal
.manager
.config
.ServiceEnvironment
;
18 import org
.asamk
.signal
.manager
.groups
.GroupId
;
19 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
20 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
21 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
22 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
23 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
24 import org
.asamk
.signal
.manager
.storage
.SignalAccount
;
25 import org
.asamk
.signal
.manager
.storage
.identities
.TrustNewIdentity
;
26 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
27 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
28 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
29 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
31 import java
.io
.Closeable
;
33 import java
.io
.IOException
;
35 import java
.util
.Arrays
;
36 import java
.util
.List
;
38 import java
.util
.Optional
;
40 import java
.util
.UUID
;
41 import java
.util
.concurrent
.TimeUnit
;
42 import java
.util
.stream
.Collectors
;
44 public interface Manager
extends Closeable
{
49 ServiceEnvironment serviceEnvironment
,
51 TrustNewIdentity trustNewIdentity
52 ) throws IOException
, NotRegisteredException
{
53 var pathConfig
= PathConfig
.createDefault(settingsPath
);
55 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
56 throw new NotRegisteredException();
59 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
61 if (!account
.isRegistered()) {
62 throw new NotRegisteredException();
65 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
67 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
70 static List
<String
> getAllLocalNumbers(File settingsPath
) {
71 var pathConfig
= PathConfig
.createDefault(settingsPath
);
72 final var dataPath
= pathConfig
.dataPath();
73 final var files
= dataPath
.listFiles();
79 return Arrays
.stream(files
)
82 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
83 .collect(Collectors
.toList());
86 String
getSelfNumber();
88 void checkAccountState() throws IOException
;
90 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
92 void updateAccountAttributes(String deviceName
) throws IOException
;
94 void updateConfiguration(
95 final Boolean readReceipts
,
96 final Boolean unidentifiedDeliveryIndicators
,
97 final Boolean typingIndicators
,
98 final Boolean linkPreviews
99 ) throws IOException
, NotMasterDeviceException
;
102 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
103 ) throws IOException
;
105 void unregister() throws IOException
;
107 void deleteAccount() throws IOException
;
109 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
111 List
<Device
> getLinkedDevices() throws IOException
;
113 void removeLinkedDevices(long deviceId
) throws IOException
;
115 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
117 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
;
119 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
;
121 List
<Group
> getGroups();
123 SendGroupMessageResults
quitGroup(
124 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
125 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
;
127 void deleteGroup(GroupId groupId
) throws IOException
;
129 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
130 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
131 ) throws IOException
, AttachmentInvalidException
;
133 SendGroupMessageResults
updateGroup(
134 final GroupId groupId
, final UpdateGroup updateGroup
135 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
;
137 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
138 GroupInviteLinkUrl inviteLinkUrl
139 ) throws IOException
, InactiveGroupLinkException
;
141 void sendTypingMessage(
142 TypingAction action
, Set
<RecipientIdentifier
> recipients
143 ) throws IOException
, UntrustedIdentityException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
145 void sendReadReceipt(
146 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
147 ) throws IOException
, UntrustedIdentityException
;
149 void sendViewedReceipt(
150 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
151 ) throws IOException
, UntrustedIdentityException
;
153 SendMessageResults
sendMessage(
154 Message message
, Set
<RecipientIdentifier
> recipients
155 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
157 SendMessageResults
sendRemoteDeleteMessage(
158 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
159 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
161 SendMessageResults
sendMessageReaction(
164 RecipientIdentifier
.Single targetAuthor
,
165 long targetSentTimestamp
,
166 Set
<RecipientIdentifier
> recipients
167 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
169 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
172 RecipientIdentifier
.Single recipient
, String name
173 ) throws NotMasterDeviceException
, IOException
;
175 void setContactBlocked(
176 RecipientIdentifier
.Single recipient
, boolean blocked
177 ) throws NotMasterDeviceException
, IOException
;
179 void setGroupBlocked(
180 GroupId groupId
, boolean blocked
181 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
183 void setExpirationTimer(
184 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
185 ) throws IOException
;
187 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
189 void requestAllSyncData() throws IOException
;
192 * Add a handler to receive new messages.
193 * Will start receiving messages from server, if not already started.
195 void addReceiveHandler(ReceiveMessageHandler handler
);
198 * Remove a handler to receive new messages.
199 * Will stop receiving messages from server, if this was the last registered receiver.
201 void removeReceiveHandler(ReceiveMessageHandler handler
);
203 boolean isReceiving();
206 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
208 void receiveMessages(long timeout
, TimeUnit unit
, ReceiveMessageHandler handler
) throws IOException
;
211 * Receive new messages from server, returns only if the thread is interrupted.
213 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
215 void setIgnoreAttachments(boolean ignoreAttachments
);
217 boolean hasCaughtUpWithOldMessages();
219 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
221 File
getAttachmentFile(String attachmentId
);
223 void sendContacts() throws IOException
;
225 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
227 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
229 Group
getGroup(GroupId groupId
);
231 List
<Identity
> getIdentities();
233 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
235 boolean trustIdentityVerified(RecipientIdentifier
.Single recipient
, byte[] fingerprint
);
237 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, String safetyNumber
);
239 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, byte[] safetyNumber
);
241 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
);
244 void close() throws IOException
;
246 interface ReceiveMessageHandler
{
248 void handleMessage(MessageEnvelope envelope
, Throwable e
);