1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.manager
.api
.AttachmentInvalidException
;
4 import org
.asamk
.signal
.manager
.api
.Configuration
;
5 import org
.asamk
.signal
.manager
.api
.Device
;
6 import org
.asamk
.signal
.manager
.api
.Group
;
7 import org
.asamk
.signal
.manager
.api
.Identity
;
8 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
9 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
10 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
11 import org
.asamk
.signal
.manager
.api
.Message
;
12 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
13 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
14 import org
.asamk
.signal
.manager
.api
.Pair
;
15 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
16 import org
.asamk
.signal
.manager
.api
.ReceiveConfig
;
17 import org
.asamk
.signal
.manager
.api
.Recipient
;
18 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
19 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
20 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
21 import org
.asamk
.signal
.manager
.api
.StickerPack
;
22 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
23 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
24 import org
.asamk
.signal
.manager
.api
.TypingAction
;
25 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
26 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
27 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
28 import org
.asamk
.signal
.manager
.api
.UserStatus
;
29 import org
.asamk
.signal
.manager
.groups
.GroupId
;
30 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
31 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
32 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
33 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
34 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
35 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
36 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
38 import java
.io
.Closeable
;
40 import java
.io
.IOException
;
42 import java
.time
.Duration
;
43 import java
.util
.Collection
;
44 import java
.util
.List
;
46 import java
.util
.Optional
;
49 public interface Manager
extends Closeable
{
51 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
52 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
55 String
getSelfNumber();
58 * This is used for checking a set of phone numbers for registration on Signal
60 * @param numbers The set of phone number in question
61 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
62 * @throws IOException if it's unable to get the contacts to check if they're registered
64 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
;
66 void updateAccountAttributes(String deviceName
) throws IOException
;
68 Configuration
getConfiguration();
70 void updateConfiguration(Configuration configuration
) throws IOException
, NotPrimaryDeviceException
;
73 * Update the user's profile.
74 * If a field is null, the previous value will be kept.
76 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
78 void unregister() throws IOException
;
80 void deleteAccount() throws IOException
;
82 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
84 List
<Device
> getLinkedDevices() throws IOException
;
86 void removeLinkedDevices(int deviceId
) throws IOException
;
88 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
90 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
92 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
94 List
<Group
> getGroups();
96 SendGroupMessageResults
quitGroup(
97 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
98 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
100 void deleteGroup(GroupId groupId
) throws IOException
;
102 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
103 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
104 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
106 SendGroupMessageResults
updateGroup(
107 final GroupId groupId
, final UpdateGroup updateGroup
108 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
110 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
111 GroupInviteLinkUrl inviteLinkUrl
112 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
114 SendMessageResults
sendTypingMessage(
115 TypingAction action
, Set
<RecipientIdentifier
> recipients
116 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
118 SendMessageResults
sendReadReceipt(
119 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
120 ) throws IOException
;
122 SendMessageResults
sendViewedReceipt(
123 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
124 ) throws IOException
;
126 SendMessageResults
sendMessage(
127 Message message
, Set
<RecipientIdentifier
> recipients
128 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
130 SendMessageResults
sendRemoteDeleteMessage(
131 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
132 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
134 SendMessageResults
sendMessageReaction(
137 RecipientIdentifier
.Single targetAuthor
,
138 long targetSentTimestamp
,
139 Set
<RecipientIdentifier
> recipients
,
140 final boolean isStory
141 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
143 SendMessageResults
sendPaymentNotificationMessage(
144 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
145 ) throws IOException
;
147 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
149 void deleteRecipient(RecipientIdentifier
.Single recipient
);
151 void deleteContact(RecipientIdentifier
.Single recipient
);
154 RecipientIdentifier
.Single recipient
, String givenName
, final String familyName
155 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
157 void setContactsBlocked(
158 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
159 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
161 void setGroupsBlocked(
162 Collection
<GroupId
> groupId
, boolean blocked
163 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
166 * Change the expiration timer for a contact
168 void setExpirationTimer(
169 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
170 ) throws IOException
, UnregisteredRecipientException
;
173 * Upload the sticker pack from path.
175 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
176 * @return if successful, returns the URL to install the sticker pack in the signal app
178 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
180 List
<StickerPack
> getStickerPacks();
182 void requestAllSyncData() throws IOException
;
185 * Add a handler to receive new messages.
186 * Will start receiving messages from server, if not already started.
188 default void addReceiveHandler(ReceiveMessageHandler handler
) {
189 addReceiveHandler(handler
, false);
192 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
195 * Remove a handler to receive new messages.
196 * Will stop receiving messages from server, if this was the last registered receiver.
198 void removeReceiveHandler(ReceiveMessageHandler handler
);
200 boolean isReceiving();
203 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
205 void receiveMessages(Duration timeout
, ReceiveMessageHandler handler
) throws IOException
;
208 * Receive new messages from server, returns only if the thread is interrupted.
210 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
212 void setReceiveConfig(ReceiveConfig receiveConfig
);
214 boolean hasCaughtUpWithOldMessages();
216 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
218 void sendContacts() throws IOException
;
220 List
<Recipient
> getRecipients(
221 boolean onlyContacts
,
222 Optional
<Boolean
> blocked
,
223 Collection
<RecipientIdentifier
.Single
> address
,
224 Optional
<String
> name
227 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
229 Group
getGroup(GroupId groupId
);
231 List
<Identity
> getIdentities();
233 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
236 * Trust this the identity with this fingerprint
238 * @param recipient account of the identity
239 * @param fingerprint Fingerprint
241 boolean trustIdentityVerified(
242 RecipientIdentifier
.Single recipient
, byte[] fingerprint
243 ) throws UnregisteredRecipientException
;
246 * Trust this the identity with this safety number
248 * @param recipient account of the identity
249 * @param safetyNumber Safety number
251 boolean trustIdentityVerifiedSafetyNumber(
252 RecipientIdentifier
.Single recipient
, String safetyNumber
253 ) throws UnregisteredRecipientException
;
256 * Trust this the identity with this scannable safety number
258 * @param recipient account of the identity
259 * @param safetyNumber Scannable safety number
261 boolean trustIdentityVerifiedSafetyNumber(
262 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
263 ) throws UnregisteredRecipientException
;
266 * Trust all keys of this identity without verification
268 * @param recipient account of the identity
270 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
272 void addAddressChangedListener(Runnable listener
);
274 void addClosedListener(Runnable listener
);
277 void close() throws IOException
;
279 interface ReceiveMessageHandler
{
281 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
284 void handleMessage(MessageEnvelope envelope
, Throwable e
);