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
.DeviceLinkUrl
;
8 import org
.asamk
.signal
.manager
.api
.Group
;
9 import org
.asamk
.signal
.manager
.api
.GroupId
;
10 import org
.asamk
.signal
.manager
.api
.GroupInviteLinkUrl
;
11 import org
.asamk
.signal
.manager
.api
.GroupNotFoundException
;
12 import org
.asamk
.signal
.manager
.api
.GroupSendingNotAllowedException
;
13 import org
.asamk
.signal
.manager
.api
.Identity
;
14 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
15 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
16 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
17 import org
.asamk
.signal
.manager
.api
.InvalidUsernameException
;
18 import org
.asamk
.signal
.manager
.api
.LastGroupAdminException
;
19 import org
.asamk
.signal
.manager
.api
.Message
;
20 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
21 import org
.asamk
.signal
.manager
.api
.NotAGroupMemberException
;
22 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
23 import org
.asamk
.signal
.manager
.api
.Pair
;
24 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
25 import org
.asamk
.signal
.manager
.api
.ReceiveConfig
;
26 import org
.asamk
.signal
.manager
.api
.Recipient
;
27 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
28 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
29 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
30 import org
.asamk
.signal
.manager
.api
.StickerPack
;
31 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
32 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
33 import org
.asamk
.signal
.manager
.api
.TypingAction
;
34 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
35 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
36 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
37 import org
.asamk
.signal
.manager
.api
.UserStatus
;
38 import org
.slf4j
.Logger
;
39 import org
.slf4j
.LoggerFactory
;
40 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
42 import java
.io
.Closeable
;
44 import java
.io
.IOException
;
45 import java
.io
.InputStream
;
46 import java
.time
.Duration
;
47 import java
.util
.Collection
;
48 import java
.util
.List
;
50 import java
.util
.Optional
;
53 public interface Manager
extends Closeable
{
55 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
56 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
59 static boolean isSignalClientAvailable() {
60 final Logger logger
= LoggerFactory
.getLogger(Manager
.class);
63 org
.signal
.libsignal
.internal
.Native
.UuidCiphertext_CheckValidContents(new byte[0]);
64 } catch (Exception e
) {
65 logger
.trace("Expected exception when checking libsignal-client: {}", e
.getMessage());
68 } catch (UnsatisfiedLinkError e
) {
69 logger
.warn("Failed to call libsignal-client: {}", e
.getMessage());
74 String
getSelfNumber();
77 * This is used for checking a set of phone numbers for registration on Signal
79 * @param numbers The set of phone number in question
80 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
81 * @throws IOException if it's unable to get the contacts to check if they're registered
83 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
;
85 void updateAccountAttributes(String deviceName
) throws IOException
;
87 Configuration
getConfiguration();
89 void updateConfiguration(Configuration configuration
) throws IOException
, NotPrimaryDeviceException
;
92 * Update the user's profile.
93 * If a field is null, the previous value will be kept.
95 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
98 * Set a username for the account.
99 * If the username is null, it will be deleted.
101 String
setUsername(String username
) throws IOException
, InvalidUsernameException
;
104 * Set a username for the account.
105 * If the username is null, it will be deleted.
107 void deleteUsername() throws IOException
;
109 void unregister() throws IOException
;
111 void deleteAccount() throws IOException
;
113 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
115 List
<Device
> getLinkedDevices() throws IOException
;
117 void removeLinkedDevices(int deviceId
) throws IOException
;
119 void addDeviceLink(DeviceLinkUrl linkUri
) throws IOException
, InvalidDeviceLinkException
;
121 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
123 List
<Group
> getGroups();
125 SendGroupMessageResults
quitGroup(
126 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
127 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
129 void deleteGroup(GroupId groupId
) throws IOException
;
131 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
132 String name
, Set
<RecipientIdentifier
.Single
> members
, String avatarFile
133 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
135 SendGroupMessageResults
updateGroup(
136 final GroupId groupId
, final UpdateGroup updateGroup
137 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
139 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
140 GroupInviteLinkUrl inviteLinkUrl
141 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
143 SendMessageResults
sendTypingMessage(
144 TypingAction action
, Set
<RecipientIdentifier
> recipients
145 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
147 SendMessageResults
sendReadReceipt(
148 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
149 ) throws IOException
;
151 SendMessageResults
sendViewedReceipt(
152 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
153 ) throws IOException
;
155 SendMessageResults
sendMessage(
156 Message message
, Set
<RecipientIdentifier
> recipients
157 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
159 SendMessageResults
sendEditMessage(
160 Message message
, Set
<RecipientIdentifier
> recipients
, long editTargetTimestamp
161 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
163 SendMessageResults
sendRemoteDeleteMessage(
164 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
165 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
167 SendMessageResults
sendMessageReaction(
170 RecipientIdentifier
.Single targetAuthor
,
171 long targetSentTimestamp
,
172 Set
<RecipientIdentifier
> recipients
,
173 final boolean isStory
174 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
176 SendMessageResults
sendPaymentNotificationMessage(
177 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
178 ) throws IOException
;
180 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
182 void deleteRecipient(RecipientIdentifier
.Single recipient
);
184 void deleteContact(RecipientIdentifier
.Single recipient
);
187 RecipientIdentifier
.Single recipient
, String givenName
, final String familyName
188 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
190 void setContactsBlocked(
191 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
192 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
194 void setGroupsBlocked(
195 Collection
<GroupId
> groupId
, boolean blocked
196 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
199 * Change the expiration timer for a contact
201 void setExpirationTimer(
202 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
203 ) throws IOException
, UnregisteredRecipientException
;
206 * Upload the sticker pack from path.
208 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
209 * @return if successful, returns the URL to install the sticker pack in the signal app
211 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
213 List
<StickerPack
> getStickerPacks();
215 void requestAllSyncData() throws IOException
;
218 * Add a handler to receive new messages.
219 * Will start receiving messages from server, if not already started.
221 default void addReceiveHandler(ReceiveMessageHandler handler
) {
222 addReceiveHandler(handler
, false);
225 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
228 * Remove a handler to receive new messages.
229 * Will stop receiving messages from server, if this was the last registered receiver.
231 void removeReceiveHandler(ReceiveMessageHandler handler
);
233 boolean isReceiving();
236 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
238 void receiveMessages(
239 Optional
<Duration
> timeout
, Optional
<Integer
> maxMessages
, ReceiveMessageHandler handler
240 ) throws IOException
, AlreadyReceivingException
;
242 void setReceiveConfig(ReceiveConfig receiveConfig
);
244 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
246 void sendContacts() throws IOException
;
248 List
<Recipient
> getRecipients(
249 boolean onlyContacts
,
250 Optional
<Boolean
> blocked
,
251 Collection
<RecipientIdentifier
.Single
> address
,
252 Optional
<String
> name
255 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
257 Group
getGroup(GroupId groupId
);
259 List
<Identity
> getIdentities();
261 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
264 * Trust this the identity with this fingerprint
266 * @param recipient account of the identity
267 * @param fingerprint Fingerprint
269 boolean trustIdentityVerified(
270 RecipientIdentifier
.Single recipient
, byte[] fingerprint
271 ) throws UnregisteredRecipientException
;
274 * Trust this the identity with this safety number
276 * @param recipient account of the identity
277 * @param safetyNumber Safety number
279 boolean trustIdentityVerifiedSafetyNumber(
280 RecipientIdentifier
.Single recipient
, String safetyNumber
281 ) throws UnregisteredRecipientException
;
284 * Trust this the identity with this scannable safety number
286 * @param recipient account of the identity
287 * @param safetyNumber Scannable safety number
289 boolean trustIdentityVerifiedSafetyNumber(
290 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
291 ) throws UnregisteredRecipientException
;
294 * Trust all keys of this identity without verification
296 * @param recipient account of the identity
298 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
300 void addAddressChangedListener(Runnable listener
);
302 void addClosedListener(Runnable listener
);
304 InputStream
retrieveAttachment(final String id
) throws IOException
;
307 void close() throws IOException
;
309 interface ReceiveMessageHandler
{
311 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
314 void handleMessage(MessageEnvelope envelope
, Throwable e
);