1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.manager
.api
.AttachmentInvalidException
;
4 import org
.asamk
.signal
.manager
.api
.Configuration
;
5 import org
.asamk
.signal
.manager
.api
.Device
;
6 import org
.asamk
.signal
.manager
.api
.Group
;
7 import org
.asamk
.signal
.manager
.api
.Identity
;
8 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
9 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
10 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
11 import org
.asamk
.signal
.manager
.api
.Message
;
12 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
13 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
14 import org
.asamk
.signal
.manager
.api
.Pair
;
15 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
16 import org
.asamk
.signal
.manager
.api
.ReceiveConfig
;
17 import org
.asamk
.signal
.manager
.api
.Recipient
;
18 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
19 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
20 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
21 import org
.asamk
.signal
.manager
.api
.StickerPack
;
22 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
23 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
24 import org
.asamk
.signal
.manager
.api
.TypingAction
;
25 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
26 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
27 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
28 import org
.asamk
.signal
.manager
.api
.UserStatus
;
29 import org
.asamk
.signal
.manager
.groups
.GroupId
;
30 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
31 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
32 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
33 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
34 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
35 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
36 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
38 import java
.io
.Closeable
;
40 import java
.io
.IOException
;
42 import java
.time
.Duration
;
43 import java
.util
.Collection
;
44 import java
.util
.List
;
46 import java
.util
.Optional
;
49 public interface Manager
extends Closeable
{
51 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
52 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
55 String
getSelfNumber();
58 * This is used for checking a set of phone numbers for registration on Signal
60 * @param numbers The set of phone number in question
61 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
62 * @throws IOException if it's unable to get the contacts to check if they're registered
64 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
;
66 void updateAccountAttributes(String deviceName
) throws IOException
;
68 Configuration
getConfiguration();
70 void updateConfiguration(Configuration configuration
) throws IOException
, NotPrimaryDeviceException
;
73 * Update the user's profile.
74 * If a field is null, the previous value will be kept.
76 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
78 void unregister() throws IOException
;
80 void deleteAccount() throws IOException
;
82 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
84 List
<Device
> getLinkedDevices() throws IOException
;
86 void removeLinkedDevices(int deviceId
) throws IOException
;
88 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
90 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
92 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
94 List
<Group
> getGroups();
96 SendGroupMessageResults
quitGroup(
97 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
98 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
100 void deleteGroup(GroupId groupId
) throws IOException
;
102 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
103 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
104 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
106 SendGroupMessageResults
updateGroup(
107 final GroupId groupId
, final UpdateGroup updateGroup
108 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
110 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
111 GroupInviteLinkUrl inviteLinkUrl
112 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
114 SendMessageResults
sendTypingMessage(
115 TypingAction action
, Set
<RecipientIdentifier
> recipients
116 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
118 SendMessageResults
sendReadReceipt(
119 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
120 ) throws IOException
;
122 SendMessageResults
sendViewedReceipt(
123 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
124 ) throws IOException
;
126 SendMessageResults
sendMessage(
127 Message message
, Set
<RecipientIdentifier
> recipients
128 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
130 SendMessageResults
sendRemoteDeleteMessage(
131 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
132 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
134 SendMessageResults
sendMessageReaction(
137 RecipientIdentifier
.Single targetAuthor
,
138 long targetSentTimestamp
,
139 Set
<RecipientIdentifier
> recipients
140 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
142 SendMessageResults
sendPaymentNotificationMessage(
143 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
144 ) throws IOException
;
146 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
148 void deleteRecipient(RecipientIdentifier
.Single recipient
);
150 void deleteContact(RecipientIdentifier
.Single recipient
);
153 RecipientIdentifier
.Single recipient
, String givenName
, final String familyName
154 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
156 void setContactsBlocked(
157 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
158 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
160 void setGroupsBlocked(
161 Collection
<GroupId
> groupId
, boolean blocked
162 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
165 * Change the expiration timer for a contact
167 void setExpirationTimer(
168 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
169 ) throws IOException
, UnregisteredRecipientException
;
172 * Upload the sticker pack from path.
174 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
175 * @return if successful, returns the URL to install the sticker pack in the signal app
177 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
179 List
<StickerPack
> getStickerPacks();
181 void requestAllSyncData() throws IOException
;
184 * Add a handler to receive new messages.
185 * Will start receiving messages from server, if not already started.
187 default void addReceiveHandler(ReceiveMessageHandler handler
) {
188 addReceiveHandler(handler
, false);
191 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
194 * Remove a handler to receive new messages.
195 * Will stop receiving messages from server, if this was the last registered receiver.
197 void removeReceiveHandler(ReceiveMessageHandler handler
);
199 boolean isReceiving();
202 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
204 void receiveMessages(Duration timeout
, ReceiveMessageHandler handler
) throws IOException
;
207 * Receive new messages from server, returns only if the thread is interrupted.
209 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
211 void setReceiveConfig(ReceiveConfig receiveConfig
);
213 boolean hasCaughtUpWithOldMessages();
215 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
217 void sendContacts() throws IOException
;
219 List
<Recipient
> getRecipients(
220 boolean onlyContacts
,
221 Optional
<Boolean
> blocked
,
222 Collection
<RecipientIdentifier
.Single
> address
,
223 Optional
<String
> name
226 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
228 Group
getGroup(GroupId groupId
);
230 List
<Identity
> getIdentities();
232 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
235 * Trust this the identity with this fingerprint
237 * @param recipient account of the identity
238 * @param fingerprint Fingerprint
240 boolean trustIdentityVerified(
241 RecipientIdentifier
.Single recipient
, byte[] fingerprint
242 ) throws UnregisteredRecipientException
;
245 * Trust this the identity with this safety number
247 * @param recipient account of the identity
248 * @param safetyNumber Safety number
250 boolean trustIdentityVerifiedSafetyNumber(
251 RecipientIdentifier
.Single recipient
, String safetyNumber
252 ) throws UnregisteredRecipientException
;
255 * Trust this the identity with this scannable safety number
257 * @param recipient account of the identity
258 * @param safetyNumber Scannable safety number
260 boolean trustIdentityVerifiedSafetyNumber(
261 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
262 ) throws UnregisteredRecipientException
;
265 * Trust all keys of this identity without verification
267 * @param recipient account of the identity
269 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
271 void addAddressChangedListener(Runnable listener
);
273 void addClosedListener(Runnable listener
);
276 void close() throws IOException
;
278 interface ReceiveMessageHandler
{
280 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
283 void handleMessage(MessageEnvelope envelope
, Throwable e
);