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
.StickerPackInvalidException
;
38 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
39 import org
.asamk
.signal
.manager
.api
.TypingAction
;
40 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
41 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
42 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
43 import org
.asamk
.signal
.manager
.api
.UserStatus
;
44 import org
.slf4j
.Logger
;
45 import org
.slf4j
.LoggerFactory
;
46 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
48 import java
.io
.Closeable
;
50 import java
.io
.IOException
;
51 import java
.io
.InputStream
;
52 import java
.time
.Duration
;
53 import java
.util
.Collection
;
54 import java
.util
.List
;
56 import java
.util
.Optional
;
59 public interface Manager
extends Closeable
{
61 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
62 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
65 static boolean isSignalClientAvailable() {
66 final Logger logger
= LoggerFactory
.getLogger(Manager
.class);
69 org
.signal
.libsignal
.internal
.Native
.UuidCiphertext_CheckValidContents(new byte[0]);
70 } catch (Exception e
) {
71 logger
.trace("Expected exception when checking libsignal-client: {}", e
.getMessage());
74 } catch (UnsatisfiedLinkError e
) {
75 logger
.warn("Failed to call libsignal-client: {}", e
.getMessage());
80 String
getSelfNumber();
83 * This is used for checking a set of phone numbers for registration on Signal
85 * @param numbers The set of phone number in question
86 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
87 * @throws IOException if it's unable to get the contacts to check if they're registered
89 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
, RateLimitException
;
91 void updateAccountAttributes(String deviceName
) throws IOException
;
93 Configuration
getConfiguration();
95 void updateConfiguration(Configuration configuration
) throws NotPrimaryDeviceException
;
98 * Update the user's profile.
99 * If a field is null, the previous value will be kept.
101 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
104 * Set a username for the account.
105 * If the username is null, it will be deleted.
107 String
setUsername(String username
) throws IOException
, InvalidUsernameException
;
110 * Set a username for the account.
111 * If the username is null, it will be deleted.
113 void deleteUsername() throws IOException
;
115 void startChangeNumber(
116 String newNumber
, boolean voiceVerification
, String captcha
117 ) throws RateLimitException
, IOException
, CaptchaRequiredException
, NonNormalizedPhoneNumberException
, NotPrimaryDeviceException
;
119 void finishChangeNumber(
120 String newNumber
, String verificationCode
, String pin
121 ) throws IncorrectPinException
, PinLockedException
, IOException
, NotPrimaryDeviceException
;
123 void unregister() throws IOException
;
125 void deleteAccount() throws IOException
;
127 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
129 List
<Device
> getLinkedDevices() throws IOException
;
131 void removeLinkedDevices(int deviceId
) throws IOException
;
133 void addDeviceLink(DeviceLinkUrl linkUri
) throws IOException
, InvalidDeviceLinkException
, NotPrimaryDeviceException
;
135 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
137 List
<Group
> getGroups();
139 SendGroupMessageResults
quitGroup(
140 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
141 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
143 void deleteGroup(GroupId groupId
) throws IOException
;
145 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
146 String name
, Set
<RecipientIdentifier
.Single
> members
, String avatarFile
147 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
149 SendGroupMessageResults
updateGroup(
150 final GroupId groupId
, final UpdateGroup updateGroup
151 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
153 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
154 GroupInviteLinkUrl inviteLinkUrl
155 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
157 SendMessageResults
sendTypingMessage(
158 TypingAction action
, Set
<RecipientIdentifier
> recipients
159 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
161 SendMessageResults
sendReadReceipt(
162 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
165 SendMessageResults
sendViewedReceipt(
166 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
169 SendMessageResults
sendMessage(
170 Message message
, Set
<RecipientIdentifier
> recipients
171 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
173 SendMessageResults
sendEditMessage(
174 Message message
, Set
<RecipientIdentifier
> recipients
, long editTargetTimestamp
175 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
177 SendMessageResults
sendRemoteDeleteMessage(
178 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
179 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
181 SendMessageResults
sendMessageReaction(
184 RecipientIdentifier
.Single targetAuthor
,
185 long targetSentTimestamp
,
186 Set
<RecipientIdentifier
> recipients
,
187 final boolean isStory
188 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
190 SendMessageResults
sendPaymentNotificationMessage(
191 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
192 ) throws IOException
;
194 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
196 void hideRecipient(RecipientIdentifier
.Single recipient
);
198 void deleteRecipient(RecipientIdentifier
.Single recipient
);
200 void deleteContact(RecipientIdentifier
.Single recipient
);
203 RecipientIdentifier
.Single recipient
, String givenName
, final String familyName
204 ) throws NotPrimaryDeviceException
, UnregisteredRecipientException
;
206 void setContactsBlocked(
207 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
208 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
210 void setGroupsBlocked(
211 Collection
<GroupId
> groupId
, boolean blocked
212 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
215 * Change the expiration timer for a contact
217 void setExpirationTimer(
218 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
219 ) throws IOException
, UnregisteredRecipientException
;
222 * Upload the sticker pack from path.
224 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
225 * @return if successful, returns the URL to install the sticker pack in the signal app
227 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
229 void installStickerPack(StickerPackUrl url
) throws IOException
;
231 List
<StickerPack
> getStickerPacks();
233 void requestAllSyncData() throws IOException
;
236 * Add a handler to receive new messages.
237 * Will start receiving messages from server, if not already started.
239 default void addReceiveHandler(ReceiveMessageHandler handler
) {
240 addReceiveHandler(handler
, false);
243 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
246 * Remove a handler to receive new messages.
247 * Will stop receiving messages from server, if this was the last registered receiver.
249 void removeReceiveHandler(ReceiveMessageHandler handler
);
251 boolean isReceiving();
254 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
256 void receiveMessages(
257 Optional
<Duration
> timeout
, Optional
<Integer
> maxMessages
, ReceiveMessageHandler handler
258 ) throws IOException
, AlreadyReceivingException
;
260 void stopReceiveMessages();
262 void setReceiveConfig(ReceiveConfig receiveConfig
);
264 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
266 void sendContacts() throws IOException
;
268 List
<Recipient
> getRecipients(
269 boolean onlyContacts
,
270 Optional
<Boolean
> blocked
,
271 Collection
<RecipientIdentifier
.Single
> address
,
272 Optional
<String
> name
275 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
277 Group
getGroup(GroupId groupId
);
279 List
<Identity
> getIdentities();
281 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
284 * Trust this the identity with this fingerprint/safetyNumber
286 * @param recipient account of the identity
288 boolean trustIdentityVerified(
289 RecipientIdentifier
.Single recipient
, IdentityVerificationCode verificationCode
290 ) throws UnregisteredRecipientException
;
293 * Trust all keys of this identity without verification
295 * @param recipient account of the identity
297 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
299 void addAddressChangedListener(Runnable listener
);
301 void addClosedListener(Runnable listener
);
303 InputStream
retrieveAttachment(final String id
) throws IOException
;
308 interface ReceiveMessageHandler
{
310 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
313 void handleMessage(MessageEnvelope envelope
, Throwable e
);