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
;
34 import java
.io
.Closeable
;
36 import java
.io
.IOException
;
38 import java
.util
.Arrays
;
39 import java
.util
.List
;
41 import java
.util
.Optional
;
43 import java
.util
.UUID
;
44 import java
.util
.concurrent
.TimeUnit
;
45 import java
.util
.stream
.Collectors
;
47 public interface Manager
extends Closeable
{
52 ServiceEnvironment serviceEnvironment
,
54 TrustNewIdentity trustNewIdentity
55 ) throws IOException
, NotRegisteredException
{
56 var pathConfig
= PathConfig
.createDefault(settingsPath
);
58 if (!SignalAccount
.userExists(pathConfig
.dataPath(), number
)) {
59 throw new NotRegisteredException();
62 var account
= SignalAccount
.load(pathConfig
.dataPath(), number
, true, trustNewIdentity
);
64 if (!account
.isRegistered()) {
65 throw new NotRegisteredException();
68 final var serviceEnvironmentConfig
= ServiceConfig
.getServiceEnvironmentConfig(serviceEnvironment
, userAgent
);
70 return new ManagerImpl(account
, pathConfig
, serviceEnvironmentConfig
, userAgent
);
73 static List
<String
> getAllLocalNumbers(File settingsPath
) {
74 var pathConfig
= PathConfig
.createDefault(settingsPath
);
75 final var dataPath
= pathConfig
.dataPath();
76 final var files
= dataPath
.listFiles();
82 return Arrays
.stream(files
)
85 .filter(file
-> PhoneNumberFormatter
.isValidNumber(file
, null))
86 .collect(Collectors
.toList());
89 String
getSelfNumber();
91 void checkAccountState() throws IOException
;
93 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
95 void updateAccountAttributes(String deviceName
) throws IOException
;
97 void updateConfiguration(
98 final Boolean readReceipts
,
99 final Boolean unidentifiedDeliveryIndicators
,
100 final Boolean typingIndicators
,
101 final Boolean linkPreviews
102 ) throws IOException
, NotMasterDeviceException
;
105 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
106 ) throws IOException
;
108 void unregister() throws IOException
;
110 void deleteAccount() throws IOException
;
112 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
114 List
<Device
> getLinkedDevices() throws IOException
;
116 void removeLinkedDevices(long deviceId
) throws IOException
;
118 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
120 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
;
122 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
;
124 List
<Group
> getGroups();
126 SendGroupMessageResults
quitGroup(
127 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
128 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
;
130 void deleteGroup(GroupId groupId
) throws IOException
;
132 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
133 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
134 ) throws IOException
, AttachmentInvalidException
;
136 SendGroupMessageResults
updateGroup(
137 final GroupId groupId
, final UpdateGroup updateGroup
138 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
;
140 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
141 GroupInviteLinkUrl inviteLinkUrl
142 ) throws IOException
, InactiveGroupLinkException
;
144 void sendTypingMessage(
145 TypingAction action
, Set
<RecipientIdentifier
> recipients
146 ) throws IOException
, UntrustedIdentityException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
148 void sendReadReceipt(
149 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
150 ) throws IOException
, UntrustedIdentityException
;
152 void sendViewedReceipt(
153 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
154 ) throws IOException
, UntrustedIdentityException
;
156 SendMessageResults
sendMessage(
157 Message message
, Set
<RecipientIdentifier
> recipients
158 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
160 SendMessageResults
sendRemoteDeleteMessage(
161 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
162 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
164 SendMessageResults
sendMessageReaction(
167 RecipientIdentifier
.Single targetAuthor
,
168 long targetSentTimestamp
,
169 Set
<RecipientIdentifier
> recipients
170 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
172 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
175 RecipientIdentifier
.Single recipient
, String name
176 ) throws NotMasterDeviceException
, IOException
;
178 void setContactBlocked(
179 RecipientIdentifier
.Single recipient
, boolean blocked
180 ) throws NotMasterDeviceException
, IOException
;
182 void setGroupBlocked(
183 GroupId groupId
, boolean blocked
184 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
186 void setExpirationTimer(
187 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
188 ) throws IOException
;
190 URI
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
192 void requestAllSyncData() throws IOException
;
195 * Add a handler to receive new messages.
196 * Will start receiving messages from server, if not already started.
198 void addReceiveHandler(ReceiveMessageHandler handler
);
201 * Remove a handler to receive new messages.
202 * Will stop receiving messages from server, if this was the last registered receiver.
204 void removeReceiveHandler(ReceiveMessageHandler handler
);
206 boolean isReceiving();
209 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
211 void receiveMessages(long timeout
, TimeUnit unit
, ReceiveMessageHandler handler
) throws IOException
;
214 * Receive new messages from server, returns only if the thread is interrupted.
216 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
218 void setIgnoreAttachments(boolean ignoreAttachments
);
220 boolean hasCaughtUpWithOldMessages();
222 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
224 File
getAttachmentFile(SignalServiceAttachmentRemoteId attachmentId
);
226 void sendContacts() throws IOException
;
228 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
230 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
232 Group
getGroup(GroupId groupId
);
234 List
<Identity
> getIdentities();
236 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
238 boolean trustIdentityVerified(RecipientIdentifier
.Single recipient
, byte[] fingerprint
);
240 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, String safetyNumber
);
242 boolean trustIdentityVerifiedSafetyNumber(RecipientIdentifier
.Single recipient
, byte[] safetyNumber
);
244 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
);
246 SignalServiceAddress
resolveSignalServiceAddress(SignalServiceAddress address
);
249 void close() throws IOException
;
251 interface ReceiveMessageHandler
{
253 void handleMessage(SignalServiceEnvelope envelope
, SignalServiceContent decryptedContent
, Throwable e
);