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
.CaptchaRequiredException
;
6 import org
.asamk
.signal
.manager
.api
.Configuration
;
7 import org
.asamk
.signal
.manager
.api
.Device
;
8 import org
.asamk
.signal
.manager
.api
.DeviceLinkUrl
;
9 import org
.asamk
.signal
.manager
.api
.Group
;
10 import org
.asamk
.signal
.manager
.api
.GroupId
;
11 import org
.asamk
.signal
.manager
.api
.GroupInviteLinkUrl
;
12 import org
.asamk
.signal
.manager
.api
.GroupNotFoundException
;
13 import org
.asamk
.signal
.manager
.api
.GroupSendingNotAllowedException
;
14 import org
.asamk
.signal
.manager
.api
.Identity
;
15 import org
.asamk
.signal
.manager
.api
.IdentityVerificationCode
;
16 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
17 import org
.asamk
.signal
.manager
.api
.IncorrectPinException
;
18 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
19 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
20 import org
.asamk
.signal
.manager
.api
.InvalidUsernameException
;
21 import org
.asamk
.signal
.manager
.api
.LastGroupAdminException
;
22 import org
.asamk
.signal
.manager
.api
.Message
;
23 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
24 import org
.asamk
.signal
.manager
.api
.NonNormalizedPhoneNumberException
;
25 import org
.asamk
.signal
.manager
.api
.NotAGroupMemberException
;
26 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
27 import org
.asamk
.signal
.manager
.api
.Pair
;
28 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
29 import org
.asamk
.signal
.manager
.api
.PinLockedException
;
30 import org
.asamk
.signal
.manager
.api
.RateLimitException
;
31 import org
.asamk
.signal
.manager
.api
.ReceiveConfig
;
32 import org
.asamk
.signal
.manager
.api
.Recipient
;
33 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
34 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
35 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
36 import org
.asamk
.signal
.manager
.api
.StickerPack
;
37 import org
.asamk
.signal
.manager
.api
.StickerPackId
;
38 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
39 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
40 import org
.asamk
.signal
.manager
.api
.TypingAction
;
41 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
42 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
43 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
44 import org
.asamk
.signal
.manager
.api
.UserStatus
;
45 import org
.asamk
.signal
.manager
.api
.UsernameLinkUrl
;
46 import org
.slf4j
.Logger
;
47 import org
.slf4j
.LoggerFactory
;
48 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
50 import java
.io
.Closeable
;
52 import java
.io
.IOException
;
53 import java
.io
.InputStream
;
54 import java
.time
.Duration
;
55 import java
.util
.Collection
;
56 import java
.util
.List
;
58 import java
.util
.Optional
;
61 public interface Manager
extends Closeable
{
63 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
64 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
67 static boolean isSignalClientAvailable() {
68 final Logger logger
= LoggerFactory
.getLogger(Manager
.class);
71 org
.signal
.libsignal
.internal
.Native
.UuidCiphertext_CheckValidContents(new byte[0]);
72 } catch (Exception e
) {
73 logger
.trace("Expected exception when checking libsignal-client: {}", e
.getMessage());
76 } catch (UnsatisfiedLinkError e
) {
77 logger
.warn("Failed to call libsignal-client: {}", e
.getMessage());
82 String
getSelfNumber();
85 * This is used for checking a set of phone numbers for registration on Signal
87 * @param numbers The set of phone number in question
88 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
89 * @throws IOException if it's unable to get the contacts to check if they're registered
91 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
, RateLimitException
;
93 void updateAccountAttributes(String deviceName
, Boolean unrestrictedUnidentifiedSender
) throws IOException
;
95 Configuration
getConfiguration();
97 void updateConfiguration(Configuration configuration
) throws NotPrimaryDeviceException
;
100 * Update the user's profile.
101 * If a field is null, the previous value will be kept.
103 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
105 String
getUsername();
107 UsernameLinkUrl
getUsernameLink();
110 * Set a username for the account.
111 * If the username is null, it will be deleted.
113 void setUsername(String username
) throws IOException
, InvalidUsernameException
;
116 * Set a username for the account.
117 * If the username is null, it will be deleted.
119 void deleteUsername() throws IOException
;
121 void startChangeNumber(
122 String newNumber
, boolean voiceVerification
, String captcha
123 ) throws RateLimitException
, IOException
, CaptchaRequiredException
, NonNormalizedPhoneNumberException
, NotPrimaryDeviceException
;
125 void finishChangeNumber(
126 String newNumber
, String verificationCode
, String pin
127 ) throws IncorrectPinException
, PinLockedException
, IOException
, NotPrimaryDeviceException
;
129 void unregister() throws IOException
;
131 void deleteAccount() throws IOException
;
133 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
135 List
<Device
> getLinkedDevices() throws IOException
;
137 void removeLinkedDevices(int deviceId
) throws IOException
;
139 void addDeviceLink(DeviceLinkUrl linkUri
) throws IOException
, InvalidDeviceLinkException
, NotPrimaryDeviceException
;
141 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
143 List
<Group
> getGroups();
145 SendGroupMessageResults
quitGroup(
146 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
147 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
149 void deleteGroup(GroupId groupId
) throws IOException
;
151 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
152 String name
, Set
<RecipientIdentifier
.Single
> members
, String avatarFile
153 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
155 SendGroupMessageResults
updateGroup(
156 final GroupId groupId
, final UpdateGroup updateGroup
157 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
159 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
160 GroupInviteLinkUrl inviteLinkUrl
161 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
163 SendMessageResults
sendTypingMessage(
164 TypingAction action
, Set
<RecipientIdentifier
> recipients
165 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
167 SendMessageResults
sendReadReceipt(
168 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
171 SendMessageResults
sendViewedReceipt(
172 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
175 SendMessageResults
sendMessage(
176 Message message
, Set
<RecipientIdentifier
> recipients
, boolean notifySelf
177 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
179 SendMessageResults
sendEditMessage(
180 Message message
, Set
<RecipientIdentifier
> recipients
, long editTargetTimestamp
181 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
183 SendMessageResults
sendRemoteDeleteMessage(
184 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
185 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
187 SendMessageResults
sendMessageReaction(
190 RecipientIdentifier
.Single targetAuthor
,
191 long targetSentTimestamp
,
192 Set
<RecipientIdentifier
> recipients
,
193 final boolean isStory
194 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
196 SendMessageResults
sendPaymentNotificationMessage(
197 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
198 ) throws IOException
;
200 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
202 void hideRecipient(RecipientIdentifier
.Single recipient
);
204 void deleteRecipient(RecipientIdentifier
.Single recipient
);
206 void deleteContact(RecipientIdentifier
.Single recipient
);
209 RecipientIdentifier
.Single recipient
, String givenName
, final String familyName
210 ) throws NotPrimaryDeviceException
, UnregisteredRecipientException
;
212 void setContactsBlocked(
213 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
214 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
216 void setGroupsBlocked(
217 Collection
<GroupId
> groupId
, boolean blocked
218 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
221 * Change the expiration timer for a contact
223 void setExpirationTimer(
224 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
225 ) throws IOException
, UnregisteredRecipientException
;
228 * Upload the sticker pack from path.
230 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
231 * @return if successful, returns the URL to install the sticker pack in the signal app
233 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
235 void installStickerPack(StickerPackUrl url
) throws IOException
;
237 List
<StickerPack
> getStickerPacks();
239 void requestAllSyncData() throws IOException
;
242 * Add a handler to receive new messages.
243 * Will start receiving messages from server, if not already started.
245 default void addReceiveHandler(ReceiveMessageHandler handler
) {
246 addReceiveHandler(handler
, false);
249 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
252 * Remove a handler to receive new messages.
253 * Will stop receiving messages from server, if this was the last registered receiver.
255 void removeReceiveHandler(ReceiveMessageHandler handler
);
257 boolean isReceiving();
260 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
262 void receiveMessages(
263 Optional
<Duration
> timeout
, Optional
<Integer
> maxMessages
, ReceiveMessageHandler handler
264 ) throws IOException
, AlreadyReceivingException
;
266 void stopReceiveMessages();
268 void setReceiveConfig(ReceiveConfig receiveConfig
);
270 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
272 void sendContacts() throws IOException
;
274 List
<Recipient
> getRecipients(
275 boolean onlyContacts
,
276 Optional
<Boolean
> blocked
,
277 Collection
<RecipientIdentifier
.Single
> address
,
278 Optional
<String
> name
281 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
283 Group
getGroup(GroupId groupId
);
285 List
<Identity
> getIdentities();
287 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
290 * Trust this the identity with this fingerprint/safetyNumber
292 * @param recipient account of the identity
294 boolean trustIdentityVerified(
295 RecipientIdentifier
.Single recipient
, IdentityVerificationCode verificationCode
296 ) throws UnregisteredRecipientException
;
299 * Trust all keys of this identity without verification
301 * @param recipient account of the identity
303 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
305 void addAddressChangedListener(Runnable listener
);
307 void addClosedListener(Runnable listener
);
309 InputStream
retrieveAttachment(final String id
) throws IOException
;
311 InputStream
retrieveContactAvatar(final RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
313 InputStream
retrieveProfileAvatar(final RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
315 InputStream
retrieveGroupAvatar(final GroupId groupId
) throws IOException
;
317 InputStream
retrieveSticker(final StickerPackId stickerPackId
, final int stickerId
) throws IOException
;
322 interface ReceiveMessageHandler
{
324 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
327 void handleMessage(MessageEnvelope envelope
, Throwable e
);