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
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
39 import java
.io
.Closeable
;
41 import java
.io
.IOException
;
42 import java
.io
.InputStream
;
44 import java
.time
.Duration
;
45 import java
.util
.Collection
;
46 import java
.util
.List
;
48 import java
.util
.Optional
;
51 public interface Manager
extends Closeable
{
53 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
54 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
57 String
getSelfNumber();
60 * This is used for checking a set of phone numbers for registration on Signal
62 * @param numbers The set of phone number in question
63 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
64 * @throws IOException if it's unable to get the contacts to check if they're registered
66 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
;
68 void updateAccountAttributes(String deviceName
) throws IOException
;
70 Configuration
getConfiguration();
72 void updateConfiguration(Configuration configuration
) throws IOException
, NotPrimaryDeviceException
;
75 * Update the user's profile.
76 * If a field is null, the previous value will be kept.
78 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
81 * Set a username for the account.
82 * If the username is null, it will be deleted.
84 String
setUsername(String username
) throws IOException
, InvalidUsernameException
;
87 * Set a username for the account.
88 * If the username is null, it will be deleted.
90 void deleteUsername() throws IOException
;
92 void unregister() throws IOException
;
94 void deleteAccount() throws IOException
;
96 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
98 List
<Device
> getLinkedDevices() throws IOException
;
100 void removeLinkedDevices(int deviceId
) throws IOException
;
102 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
104 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
106 List
<Group
> getGroups();
108 SendGroupMessageResults
quitGroup(
109 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
110 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
112 void deleteGroup(GroupId groupId
) throws IOException
;
114 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
115 String name
, Set
<RecipientIdentifier
.Single
> members
, String avatarFile
116 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
118 SendGroupMessageResults
updateGroup(
119 final GroupId groupId
, final UpdateGroup updateGroup
120 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
122 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
123 GroupInviteLinkUrl inviteLinkUrl
124 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
126 SendMessageResults
sendTypingMessage(
127 TypingAction action
, Set
<RecipientIdentifier
> recipients
128 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
130 SendMessageResults
sendReadReceipt(
131 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
132 ) throws IOException
;
134 SendMessageResults
sendViewedReceipt(
135 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
136 ) throws IOException
;
138 SendMessageResults
sendMessage(
139 Message message
, Set
<RecipientIdentifier
> recipients
140 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
142 SendMessageResults
sendEditMessage(
143 Message message
, Set
<RecipientIdentifier
> recipients
, long editTargetTimestamp
144 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
146 SendMessageResults
sendRemoteDeleteMessage(
147 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
148 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
150 SendMessageResults
sendMessageReaction(
153 RecipientIdentifier
.Single targetAuthor
,
154 long targetSentTimestamp
,
155 Set
<RecipientIdentifier
> recipients
,
156 final boolean isStory
157 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
159 SendMessageResults
sendPaymentNotificationMessage(
160 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
161 ) throws IOException
;
163 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
165 void deleteRecipient(RecipientIdentifier
.Single recipient
);
167 void deleteContact(RecipientIdentifier
.Single recipient
);
170 RecipientIdentifier
.Single recipient
, String givenName
, final String familyName
171 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
173 void setContactsBlocked(
174 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
175 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
177 void setGroupsBlocked(
178 Collection
<GroupId
> groupId
, boolean blocked
179 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
182 * Change the expiration timer for a contact
184 void setExpirationTimer(
185 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
186 ) throws IOException
, UnregisteredRecipientException
;
189 * Upload the sticker pack from path.
191 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
192 * @return if successful, returns the URL to install the sticker pack in the signal app
194 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
196 List
<StickerPack
> getStickerPacks();
198 void requestAllSyncData() throws IOException
;
201 * Add a handler to receive new messages.
202 * Will start receiving messages from server, if not already started.
204 default void addReceiveHandler(ReceiveMessageHandler handler
) {
205 addReceiveHandler(handler
, false);
208 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
211 * Remove a handler to receive new messages.
212 * Will stop receiving messages from server, if this was the last registered receiver.
214 void removeReceiveHandler(ReceiveMessageHandler handler
);
216 boolean isReceiving();
219 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
221 void receiveMessages(
222 Optional
<Duration
> timeout
, Optional
<Integer
> maxMessages
, ReceiveMessageHandler handler
223 ) throws IOException
, AlreadyReceivingException
;
225 void setReceiveConfig(ReceiveConfig receiveConfig
);
227 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
229 void sendContacts() throws IOException
;
231 List
<Recipient
> getRecipients(
232 boolean onlyContacts
,
233 Optional
<Boolean
> blocked
,
234 Collection
<RecipientIdentifier
.Single
> address
,
235 Optional
<String
> name
238 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
240 Group
getGroup(GroupId groupId
);
242 List
<Identity
> getIdentities();
244 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
247 * Trust this the identity with this fingerprint
249 * @param recipient account of the identity
250 * @param fingerprint Fingerprint
252 boolean trustIdentityVerified(
253 RecipientIdentifier
.Single recipient
, byte[] fingerprint
254 ) throws UnregisteredRecipientException
;
257 * Trust this the identity with this safety number
259 * @param recipient account of the identity
260 * @param safetyNumber Safety number
262 boolean trustIdentityVerifiedSafetyNumber(
263 RecipientIdentifier
.Single recipient
, String safetyNumber
264 ) throws UnregisteredRecipientException
;
267 * Trust this the identity with this scannable safety number
269 * @param recipient account of the identity
270 * @param safetyNumber Scannable safety number
272 boolean trustIdentityVerifiedSafetyNumber(
273 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
274 ) throws UnregisteredRecipientException
;
277 * Trust all keys of this identity without verification
279 * @param recipient account of the identity
281 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
283 void addAddressChangedListener(Runnable listener
);
285 void addClosedListener(Runnable listener
);
287 InputStream
retrieveAttachment(final String id
) throws IOException
;
290 void close() throws IOException
;
292 interface ReceiveMessageHandler
{
294 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
297 void handleMessage(MessageEnvelope envelope
, Throwable e
);