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
.Group
;
8 import org
.asamk
.signal
.manager
.api
.Identity
;
9 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
10 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
11 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
12 import org
.asamk
.signal
.manager
.api
.InvalidUsernameException
;
13 import org
.asamk
.signal
.manager
.api
.Message
;
14 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
15 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
16 import org
.asamk
.signal
.manager
.api
.Pair
;
17 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
18 import org
.asamk
.signal
.manager
.api
.ReceiveConfig
;
19 import org
.asamk
.signal
.manager
.api
.Recipient
;
20 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
21 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
22 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
23 import org
.asamk
.signal
.manager
.api
.StickerPack
;
24 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
25 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
26 import org
.asamk
.signal
.manager
.api
.TypingAction
;
27 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
28 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
29 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
30 import org
.asamk
.signal
.manager
.api
.UserStatus
;
31 import org
.asamk
.signal
.manager
.groups
.GroupId
;
32 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
33 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
34 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
35 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
36 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
37 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
38 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
40 import java
.io
.Closeable
;
42 import java
.io
.IOException
;
43 import java
.io
.InputStream
;
45 import java
.time
.Duration
;
46 import java
.util
.Collection
;
47 import java
.util
.List
;
49 import java
.util
.Optional
;
52 public interface Manager
extends Closeable
{
54 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
55 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
58 String
getSelfNumber();
61 * This is used for checking a set of phone numbers for registration on Signal
63 * @param numbers The set of phone number in question
64 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
65 * @throws IOException if it's unable to get the contacts to check if they're registered
67 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
;
69 void updateAccountAttributes(String deviceName
) throws IOException
;
71 Configuration
getConfiguration();
73 void updateConfiguration(Configuration configuration
) throws IOException
, NotPrimaryDeviceException
;
76 * Update the user's profile.
77 * If a field is null, the previous value will be kept.
79 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
82 * Set a username for the account.
83 * If the username is null, it will be deleted.
85 String
setUsername(String username
) throws IOException
, InvalidUsernameException
;
88 * Set a username for the account.
89 * If the username is null, it will be deleted.
91 void deleteUsername() throws IOException
;
93 void unregister() throws IOException
;
95 void deleteAccount() throws IOException
;
97 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
99 List
<Device
> getLinkedDevices() throws IOException
;
101 void removeLinkedDevices(int deviceId
) throws IOException
;
103 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
105 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
107 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
109 List
<Group
> getGroups();
111 SendGroupMessageResults
quitGroup(
112 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
113 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
115 void deleteGroup(GroupId groupId
) throws IOException
;
117 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
118 String name
, Set
<RecipientIdentifier
.Single
> members
, String avatarFile
119 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
121 SendGroupMessageResults
updateGroup(
122 final GroupId groupId
, final UpdateGroup updateGroup
123 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
125 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
126 GroupInviteLinkUrl inviteLinkUrl
127 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
129 SendMessageResults
sendTypingMessage(
130 TypingAction action
, Set
<RecipientIdentifier
> recipients
131 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
133 SendMessageResults
sendReadReceipt(
134 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
135 ) throws IOException
;
137 SendMessageResults
sendViewedReceipt(
138 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
139 ) throws IOException
;
141 SendMessageResults
sendMessage(
142 Message message
, Set
<RecipientIdentifier
> recipients
143 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
145 SendMessageResults
sendEditMessage(
146 Message message
, Set
<RecipientIdentifier
> recipients
, long editTargetTimestamp
147 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
149 SendMessageResults
sendRemoteDeleteMessage(
150 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
151 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
153 SendMessageResults
sendMessageReaction(
156 RecipientIdentifier
.Single targetAuthor
,
157 long targetSentTimestamp
,
158 Set
<RecipientIdentifier
> recipients
,
159 final boolean isStory
160 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
162 SendMessageResults
sendPaymentNotificationMessage(
163 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
164 ) throws IOException
;
166 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
168 void deleteRecipient(RecipientIdentifier
.Single recipient
);
170 void deleteContact(RecipientIdentifier
.Single recipient
);
173 RecipientIdentifier
.Single recipient
, String givenName
, final String familyName
174 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
176 void setContactsBlocked(
177 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
178 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
180 void setGroupsBlocked(
181 Collection
<GroupId
> groupId
, boolean blocked
182 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
185 * Change the expiration timer for a contact
187 void setExpirationTimer(
188 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
189 ) throws IOException
, UnregisteredRecipientException
;
192 * Upload the sticker pack from path.
194 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
195 * @return if successful, returns the URL to install the sticker pack in the signal app
197 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
199 List
<StickerPack
> getStickerPacks();
201 void requestAllSyncData() throws IOException
;
204 * Add a handler to receive new messages.
205 * Will start receiving messages from server, if not already started.
207 default void addReceiveHandler(ReceiveMessageHandler handler
) {
208 addReceiveHandler(handler
, false);
211 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
214 * Remove a handler to receive new messages.
215 * Will stop receiving messages from server, if this was the last registered receiver.
217 void removeReceiveHandler(ReceiveMessageHandler handler
);
219 boolean isReceiving();
222 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
224 public void receiveMessages(
225 Optional
<Duration
> timeout
, Optional
<Integer
> maxMessages
, ReceiveMessageHandler handler
226 ) throws IOException
, AlreadyReceivingException
;
228 void setReceiveConfig(ReceiveConfig receiveConfig
);
230 boolean hasCaughtUpWithOldMessages();
232 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
234 void sendContacts() throws IOException
;
236 List
<Recipient
> getRecipients(
237 boolean onlyContacts
,
238 Optional
<Boolean
> blocked
,
239 Collection
<RecipientIdentifier
.Single
> address
,
240 Optional
<String
> name
243 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
245 Group
getGroup(GroupId groupId
);
247 List
<Identity
> getIdentities();
249 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
252 * Trust this the identity with this fingerprint
254 * @param recipient account of the identity
255 * @param fingerprint Fingerprint
257 boolean trustIdentityVerified(
258 RecipientIdentifier
.Single recipient
, byte[] fingerprint
259 ) throws UnregisteredRecipientException
;
262 * Trust this the identity with this safety number
264 * @param recipient account of the identity
265 * @param safetyNumber Safety number
267 boolean trustIdentityVerifiedSafetyNumber(
268 RecipientIdentifier
.Single recipient
, String safetyNumber
269 ) throws UnregisteredRecipientException
;
272 * Trust this the identity with this scannable safety number
274 * @param recipient account of the identity
275 * @param safetyNumber Scannable safety number
277 boolean trustIdentityVerifiedSafetyNumber(
278 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
279 ) throws UnregisteredRecipientException
;
282 * Trust all keys of this identity without verification
284 * @param recipient account of the identity
286 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
288 void addAddressChangedListener(Runnable listener
);
290 void addClosedListener(Runnable listener
);
292 InputStream
retrieveAttachment(final String id
) throws IOException
;
295 void close() throws IOException
;
297 interface ReceiveMessageHandler
{
299 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
302 void handleMessage(MessageEnvelope envelope
, Throwable e
);