1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.manager
.api
.AlreadyReceivingException
;
4 import org
.asamk
.signal
.manager
.api
.AttachmentInvalidException
;
5 import org
.asamk
.signal
.manager
.api
.Configuration
;
6 import org
.asamk
.signal
.manager
.api
.Device
;
7 import org
.asamk
.signal
.manager
.api
.Group
;
8 import org
.asamk
.signal
.manager
.api
.Identity
;
9 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
10 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
11 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
12 import org
.asamk
.signal
.manager
.api
.InvalidUsernameException
;
13 import org
.asamk
.signal
.manager
.api
.Message
;
14 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
15 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
16 import org
.asamk
.signal
.manager
.api
.Pair
;
17 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
18 import org
.asamk
.signal
.manager
.api
.ReceiveConfig
;
19 import org
.asamk
.signal
.manager
.api
.Recipient
;
20 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
21 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
22 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
23 import org
.asamk
.signal
.manager
.api
.StickerPack
;
24 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
25 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
26 import org
.asamk
.signal
.manager
.api
.TypingAction
;
27 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
28 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
29 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
30 import org
.asamk
.signal
.manager
.api
.UserStatus
;
31 import org
.asamk
.signal
.manager
.groups
.GroupId
;
32 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
33 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
34 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
35 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
36 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
37 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
38 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
40 import java
.io
.Closeable
;
42 import java
.io
.IOException
;
43 import java
.io
.InputStream
;
45 import java
.time
.Duration
;
46 import java
.util
.Collection
;
47 import java
.util
.List
;
49 import java
.util
.Optional
;
52 public interface Manager
extends Closeable
{
54 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
55 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
58 String
getSelfNumber();
61 * This is used for checking a set of phone numbers for registration on Signal
63 * @param numbers The set of phone number in question
64 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
65 * @throws IOException if it's unable to get the contacts to check if they're registered
67 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
;
69 void updateAccountAttributes(String deviceName
) throws IOException
;
71 Configuration
getConfiguration();
73 void updateConfiguration(Configuration configuration
) throws IOException
, NotPrimaryDeviceException
;
76 * Update the user's profile.
77 * If a field is null, the previous value will be kept.
79 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
82 * Set a username for the account.
83 * If the username is null, it will be deleted.
85 String
setUsername(String username
) throws IOException
, InvalidUsernameException
;
88 * Set a username for the account.
89 * If the username is null, it will be deleted.
91 void deleteUsername() throws IOException
;
93 void unregister() throws IOException
;
95 void deleteAccount() throws IOException
;
97 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
99 List
<Device
> getLinkedDevices() throws IOException
;
101 void removeLinkedDevices(int deviceId
) throws IOException
;
103 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
105 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
107 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
109 List
<Group
> getGroups();
111 SendGroupMessageResults
quitGroup(
112 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
113 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
115 void deleteGroup(GroupId groupId
) throws IOException
;
117 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
118 String name
, Set
<RecipientIdentifier
.Single
> members
, String avatarFile
119 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
121 SendGroupMessageResults
updateGroup(
122 final GroupId groupId
, final UpdateGroup updateGroup
123 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
125 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
126 GroupInviteLinkUrl inviteLinkUrl
127 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
129 SendMessageResults
sendTypingMessage(
130 TypingAction action
, Set
<RecipientIdentifier
> recipients
131 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
133 SendMessageResults
sendReadReceipt(
134 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
135 ) throws IOException
;
137 SendMessageResults
sendViewedReceipt(
138 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
139 ) throws IOException
;
141 SendMessageResults
sendMessage(
142 Message message
, Set
<RecipientIdentifier
> recipients
143 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
145 SendMessageResults
sendRemoteDeleteMessage(
146 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
147 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
149 SendMessageResults
sendMessageReaction(
152 RecipientIdentifier
.Single targetAuthor
,
153 long targetSentTimestamp
,
154 Set
<RecipientIdentifier
> recipients
,
155 final boolean isStory
156 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
158 SendMessageResults
sendPaymentNotificationMessage(
159 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
160 ) throws IOException
;
162 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
164 void deleteRecipient(RecipientIdentifier
.Single recipient
);
166 void deleteContact(RecipientIdentifier
.Single recipient
);
169 RecipientIdentifier
.Single recipient
, String givenName
, final String familyName
170 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
172 void setContactsBlocked(
173 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
174 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
176 void setGroupsBlocked(
177 Collection
<GroupId
> groupId
, boolean blocked
178 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
181 * Change the expiration timer for a contact
183 void setExpirationTimer(
184 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
185 ) throws IOException
, UnregisteredRecipientException
;
188 * Upload the sticker pack from path.
190 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
191 * @return if successful, returns the URL to install the sticker pack in the signal app
193 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
195 List
<StickerPack
> getStickerPacks();
197 void requestAllSyncData() throws IOException
;
200 * Add a handler to receive new messages.
201 * Will start receiving messages from server, if not already started.
203 default void addReceiveHandler(ReceiveMessageHandler handler
) {
204 addReceiveHandler(handler
, false);
207 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
210 * Remove a handler to receive new messages.
211 * Will stop receiving messages from server, if this was the last registered receiver.
213 void removeReceiveHandler(ReceiveMessageHandler handler
);
215 boolean isReceiving();
218 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
220 public void receiveMessages(
221 Optional
<Duration
> timeout
, Optional
<Integer
> maxMessages
, ReceiveMessageHandler handler
222 ) throws IOException
, AlreadyReceivingException
;
224 void setReceiveConfig(ReceiveConfig receiveConfig
);
226 boolean hasCaughtUpWithOldMessages();
228 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
230 void sendContacts() throws IOException
;
232 List
<Recipient
> getRecipients(
233 boolean onlyContacts
,
234 Optional
<Boolean
> blocked
,
235 Collection
<RecipientIdentifier
.Single
> address
,
236 Optional
<String
> name
239 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
241 Group
getGroup(GroupId groupId
);
243 List
<Identity
> getIdentities();
245 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
248 * Trust this the identity with this fingerprint
250 * @param recipient account of the identity
251 * @param fingerprint Fingerprint
253 boolean trustIdentityVerified(
254 RecipientIdentifier
.Single recipient
, byte[] fingerprint
255 ) throws UnregisteredRecipientException
;
258 * Trust this the identity with this safety number
260 * @param recipient account of the identity
261 * @param safetyNumber Safety number
263 boolean trustIdentityVerifiedSafetyNumber(
264 RecipientIdentifier
.Single recipient
, String safetyNumber
265 ) throws UnregisteredRecipientException
;
268 * Trust this the identity with this scannable safety number
270 * @param recipient account of the identity
271 * @param safetyNumber Scannable safety number
273 boolean trustIdentityVerifiedSafetyNumber(
274 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
275 ) throws UnregisteredRecipientException
;
278 * Trust all keys of this identity without verification
280 * @param recipient account of the identity
282 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
284 void addAddressChangedListener(Runnable listener
);
286 void addClosedListener(Runnable listener
);
288 InputStream
retrieveAttachment(final String id
) throws IOException
;
291 void close() throws IOException
;
293 interface ReceiveMessageHandler
{
295 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
298 void handleMessage(MessageEnvelope envelope
, Throwable e
);