1 package org
.asamk
.signal
.manager
;
3 import com
.google
.i18n
.phonenumbers
.PhoneNumberUtil
;
5 import org
.asamk
.signal
.manager
.api
.AlreadyReceivingException
;
6 import org
.asamk
.signal
.manager
.api
.AttachmentInvalidException
;
7 import org
.asamk
.signal
.manager
.api
.CaptchaRejectedException
;
8 import org
.asamk
.signal
.manager
.api
.CaptchaRequiredException
;
9 import org
.asamk
.signal
.manager
.api
.Configuration
;
10 import org
.asamk
.signal
.manager
.api
.Device
;
11 import org
.asamk
.signal
.manager
.api
.DeviceLimitExceededException
;
12 import org
.asamk
.signal
.manager
.api
.DeviceLinkUrl
;
13 import org
.asamk
.signal
.manager
.api
.Group
;
14 import org
.asamk
.signal
.manager
.api
.GroupId
;
15 import org
.asamk
.signal
.manager
.api
.GroupInviteLinkUrl
;
16 import org
.asamk
.signal
.manager
.api
.GroupNotFoundException
;
17 import org
.asamk
.signal
.manager
.api
.GroupSendingNotAllowedException
;
18 import org
.asamk
.signal
.manager
.api
.Identity
;
19 import org
.asamk
.signal
.manager
.api
.IdentityVerificationCode
;
20 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
21 import org
.asamk
.signal
.manager
.api
.IncorrectPinException
;
22 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
23 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
24 import org
.asamk
.signal
.manager
.api
.InvalidUsernameException
;
25 import org
.asamk
.signal
.manager
.api
.LastGroupAdminException
;
26 import org
.asamk
.signal
.manager
.api
.Message
;
27 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
28 import org
.asamk
.signal
.manager
.api
.NonNormalizedPhoneNumberException
;
29 import org
.asamk
.signal
.manager
.api
.NotAGroupMemberException
;
30 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
31 import org
.asamk
.signal
.manager
.api
.Pair
;
32 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
33 import org
.asamk
.signal
.manager
.api
.PinLockMissingException
;
34 import org
.asamk
.signal
.manager
.api
.PinLockedException
;
35 import org
.asamk
.signal
.manager
.api
.RateLimitException
;
36 import org
.asamk
.signal
.manager
.api
.ReceiveConfig
;
37 import org
.asamk
.signal
.manager
.api
.Recipient
;
38 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
39 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
40 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
41 import org
.asamk
.signal
.manager
.api
.StickerPack
;
42 import org
.asamk
.signal
.manager
.api
.StickerPackId
;
43 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
44 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
45 import org
.asamk
.signal
.manager
.api
.TypingAction
;
46 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
47 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
48 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
49 import org
.asamk
.signal
.manager
.api
.UserStatus
;
50 import org
.asamk
.signal
.manager
.api
.UsernameLinkUrl
;
51 import org
.asamk
.signal
.manager
.api
.UsernameStatus
;
52 import org
.asamk
.signal
.manager
.api
.VerificationMethodNotAvailableException
;
53 import org
.slf4j
.Logger
;
54 import org
.slf4j
.LoggerFactory
;
56 import java
.io
.Closeable
;
58 import java
.io
.IOException
;
59 import java
.io
.InputStream
;
60 import java
.time
.Duration
;
61 import java
.util
.Collection
;
62 import java
.util
.List
;
64 import java
.util
.Optional
;
67 public interface Manager
extends Closeable
{
69 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
70 return PhoneNumberUtil
.getInstance().isPossibleNumber(e164Number
, countryCode
);
73 static boolean isSignalClientAvailable() {
74 final Logger logger
= LoggerFactory
.getLogger(Manager
.class);
77 org
.signal
.libsignal
.internal
.Native
.UuidCiphertext_CheckValidContents(new byte[0]);
78 } catch (Exception e
) {
79 logger
.trace("Expected exception when checking libsignal-client: {}", e
.getMessage());
82 } catch (UnsatisfiedLinkError e
) {
83 logger
.warn("Failed to call libsignal-client: {}", e
.getMessage());
88 String
getSelfNumber();
91 * This is used for checking a set of phone numbers for registration on Signal
93 * @param numbers The set of phone number in question
94 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
95 * @throws IOException if it's unable to get the contacts to check if they're registered
97 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
, RateLimitException
;
99 Map
<String
, UsernameStatus
> getUsernameStatus(Set
<String
> usernames
) throws IOException
;
101 void updateAccountAttributes(
103 Boolean unrestrictedUnidentifiedSender
,
104 final Boolean discoverableByNumber
,
105 final Boolean numberSharing
106 ) throws IOException
;
108 Configuration
getConfiguration();
110 void updateConfiguration(Configuration configuration
) throws NotPrimaryDeviceException
;
113 * Update the user's profile.
114 * If a field is null, the previous value will be kept.
116 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
118 String
getUsername();
120 UsernameLinkUrl
getUsernameLink();
123 * Set a username for the account.
124 * If the username is null, it will be deleted.
126 void setUsername(String username
) throws IOException
, InvalidUsernameException
;
129 * Set a username for the account.
130 * If the username is null, it will be deleted.
132 void deleteUsername() throws IOException
;
134 void startChangeNumber(
136 boolean voiceVerification
,
138 ) throws RateLimitException
, IOException
, CaptchaRequiredException
, NonNormalizedPhoneNumberException
, NotPrimaryDeviceException
, VerificationMethodNotAvailableException
;
140 void finishChangeNumber(
142 String verificationCode
,
144 ) throws IncorrectPinException
, PinLockedException
, IOException
, NotPrimaryDeviceException
, PinLockMissingException
;
146 void unregister() throws IOException
;
148 void deleteAccount() throws IOException
;
150 void submitRateLimitRecaptchaChallenge(
153 ) throws IOException
, CaptchaRejectedException
;
155 List
<Device
> getLinkedDevices() throws IOException
;
157 void removeLinkedDevices(int deviceId
) throws IOException
, NotPrimaryDeviceException
;
159 void addDeviceLink(DeviceLinkUrl linkUri
) throws IOException
, InvalidDeviceLinkException
, NotPrimaryDeviceException
, DeviceLimitExceededException
;
161 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
163 List
<Group
> getGroups();
165 SendGroupMessageResults
quitGroup(
167 Set
<RecipientIdentifier
.Single
> groupAdmins
168 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
170 void deleteGroup(GroupId groupId
) throws IOException
;
172 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
174 Set
<RecipientIdentifier
.Single
> members
,
176 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
178 SendGroupMessageResults
updateGroup(
179 final GroupId groupId
,
180 final UpdateGroup updateGroup
181 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
183 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
184 GroupInviteLinkUrl inviteLinkUrl
185 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
187 SendMessageResults
sendTypingMessage(
189 Set
<RecipientIdentifier
> recipients
190 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
192 SendMessageResults
sendReadReceipt(RecipientIdentifier
.Single sender
, List
<Long
> messageIds
);
194 SendMessageResults
sendViewedReceipt(RecipientIdentifier
.Single sender
, List
<Long
> messageIds
);
196 SendMessageResults
sendMessage(
198 Set
<RecipientIdentifier
> recipients
,
200 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
202 SendMessageResults
sendEditMessage(
204 Set
<RecipientIdentifier
> recipients
,
205 long editTargetTimestamp
206 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
208 SendMessageResults
sendRemoteDeleteMessage(
209 long targetSentTimestamp
,
210 Set
<RecipientIdentifier
> recipients
211 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
213 SendMessageResults
sendMessageReaction(
216 RecipientIdentifier
.Single targetAuthor
,
217 long targetSentTimestamp
,
218 Set
<RecipientIdentifier
> recipients
,
219 final boolean isStory
220 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
222 SendMessageResults
sendPaymentNotificationMessage(
225 RecipientIdentifier
.Single recipient
226 ) throws IOException
;
228 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
230 SendMessageResults
sendMessageRequestResponse(
231 MessageEnvelope
.Sync
.MessageRequestResponse
.Type type
,
232 Set
<RecipientIdentifier
> recipientIdentifiers
235 void hideRecipient(RecipientIdentifier
.Single recipient
);
237 void deleteRecipient(RecipientIdentifier
.Single recipient
);
239 void deleteContact(RecipientIdentifier
.Single recipient
);
242 final RecipientIdentifier
.Single recipient
,
243 final String givenName
,
244 final String familyName
,
245 final String nickGivenName
,
246 final String nickFamilyName
,
248 ) throws NotPrimaryDeviceException
, UnregisteredRecipientException
;
250 void setContactsBlocked(
251 Collection
<RecipientIdentifier
.Single
> recipient
,
253 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
255 void setGroupsBlocked(
256 Collection
<GroupId
> groupId
,
258 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
261 * Change the expiration timer for a contact
263 void setExpirationTimer(
264 RecipientIdentifier
.Single recipient
,
265 int messageExpirationTimer
266 ) throws IOException
, UnregisteredRecipientException
;
269 * Upload the sticker pack from path.
271 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
272 * @return if successful, returns the URL to install the sticker pack in the signal app
274 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
276 void installStickerPack(StickerPackUrl url
) throws IOException
;
278 List
<StickerPack
> getStickerPacks();
280 void requestAllSyncData() throws IOException
;
283 * Add a handler to receive new messages.
284 * Will start receiving messages from server, if not already started.
286 default void addReceiveHandler(ReceiveMessageHandler handler
) {
287 addReceiveHandler(handler
, false);
290 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
293 * Remove a handler to receive new messages.
294 * Will stop receiving messages from server, if this was the last registered receiver.
296 void removeReceiveHandler(ReceiveMessageHandler handler
);
298 boolean isReceiving();
301 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
303 void receiveMessages(
304 Optional
<Duration
> timeout
,
305 Optional
<Integer
> maxMessages
,
306 ReceiveMessageHandler handler
307 ) throws IOException
, AlreadyReceivingException
;
309 void stopReceiveMessages();
311 void setReceiveConfig(ReceiveConfig receiveConfig
);
313 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
315 void sendContacts() throws IOException
;
317 List
<Recipient
> getRecipients(
318 boolean onlyContacts
,
319 Optional
<Boolean
> blocked
,
320 Collection
<RecipientIdentifier
.Single
> address
,
321 Optional
<String
> name
324 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
326 Group
getGroup(GroupId groupId
);
328 List
<Identity
> getIdentities();
330 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
333 * Trust this the identity with this fingerprint/safetyNumber
335 * @param recipient account of the identity
337 boolean trustIdentityVerified(
338 RecipientIdentifier
.Single recipient
,
339 IdentityVerificationCode verificationCode
340 ) throws UnregisteredRecipientException
;
343 * Trust all keys of this identity without verification
345 * @param recipient account of the identity
347 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
349 void addAddressChangedListener(Runnable listener
);
351 void addClosedListener(Runnable listener
);
353 InputStream
retrieveAttachment(final String id
) throws IOException
;
355 InputStream
retrieveContactAvatar(final RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
357 InputStream
retrieveProfileAvatar(final RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
359 InputStream
retrieveGroupAvatar(final GroupId groupId
) throws IOException
;
361 InputStream
retrieveSticker(final StickerPackId stickerPackId
, final int stickerId
) throws IOException
;
366 interface ReceiveMessageHandler
{
368 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
371 void handleMessage(MessageEnvelope envelope
, Throwable e
);