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
.NotMasterDeviceException
;
14 import org
.asamk
.signal
.manager
.api
.Pair
;
15 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
16 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
17 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
18 import org
.asamk
.signal
.manager
.api
.StickerPack
;
19 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
20 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
21 import org
.asamk
.signal
.manager
.api
.TypingAction
;
22 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
23 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
24 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
25 import org
.asamk
.signal
.manager
.api
.UserStatus
;
26 import org
.asamk
.signal
.manager
.groups
.GroupId
;
27 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
28 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
29 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
30 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
31 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
32 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
33 import org
.asamk
.signal
.manager
.storage
.recipients
.Recipient
;
34 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
36 import java
.io
.Closeable
;
38 import java
.io
.IOException
;
40 import java
.time
.Duration
;
41 import java
.util
.Collection
;
42 import java
.util
.List
;
44 import java
.util
.Optional
;
47 public interface Manager
extends Closeable
{
49 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
50 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
53 String
getSelfNumber();
56 * This is used for checking a set of phone numbers for registration on Signal
58 * @param numbers The set of phone number in question
59 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
60 * @throws IOException if it's unable to get the contacts to check if they're registered
62 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
;
64 void updateAccountAttributes(String deviceName
) throws IOException
;
66 Configuration
getConfiguration();
68 void updateConfiguration(Configuration configuration
) throws IOException
, NotMasterDeviceException
;
71 * Update the user's profile.
72 * If a field is null, the previous value will be kept.
74 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
76 void unregister() throws IOException
;
78 void deleteAccount() throws IOException
;
80 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
82 List
<Device
> getLinkedDevices() throws IOException
;
84 void removeLinkedDevices(int deviceId
) throws IOException
;
86 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
88 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotMasterDeviceException
;
90 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
92 List
<Group
> getGroups();
94 SendGroupMessageResults
quitGroup(
95 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
96 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
98 void deleteGroup(GroupId groupId
) throws IOException
;
100 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
101 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
102 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
104 SendGroupMessageResults
updateGroup(
105 final GroupId groupId
, final UpdateGroup updateGroup
106 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
108 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
109 GroupInviteLinkUrl inviteLinkUrl
110 ) throws IOException
, InactiveGroupLinkException
;
112 SendMessageResults
sendTypingMessage(
113 TypingAction action
, Set
<RecipientIdentifier
> recipients
114 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
116 SendMessageResults
sendReadReceipt(
117 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
118 ) throws IOException
;
120 SendMessageResults
sendViewedReceipt(
121 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
122 ) throws IOException
;
124 SendMessageResults
sendMessage(
125 Message message
, Set
<RecipientIdentifier
> recipients
126 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
128 SendMessageResults
sendRemoteDeleteMessage(
129 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
130 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
132 SendMessageResults
sendMessageReaction(
135 RecipientIdentifier
.Single targetAuthor
,
136 long targetSentTimestamp
,
137 Set
<RecipientIdentifier
> recipients
138 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
140 SendMessageResults
sendPaymentNotificationMessage(
141 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
142 ) throws IOException
;
144 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
146 void deleteRecipient(RecipientIdentifier
.Single recipient
);
148 void deleteContact(RecipientIdentifier
.Single recipient
);
151 RecipientIdentifier
.Single recipient
, String name
152 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
154 void setContactsBlocked(
155 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
156 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
158 void setGroupsBlocked(
159 Collection
<GroupId
> groupId
, boolean blocked
160 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
163 * Change the expiration timer for a contact
165 void setExpirationTimer(
166 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
167 ) throws IOException
, UnregisteredRecipientException
;
170 * Upload the sticker pack from path.
172 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
173 * @return if successful, returns the URL to install the sticker pack in the signal app
175 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
177 List
<StickerPack
> getStickerPacks();
179 void requestAllSyncData() throws IOException
;
182 * Add a handler to receive new messages.
183 * Will start receiving messages from server, if not already started.
185 default void addReceiveHandler(ReceiveMessageHandler handler
) {
186 addReceiveHandler(handler
, false);
189 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
192 * Remove a handler to receive new messages.
193 * Will stop receiving messages from server, if this was the last registered receiver.
195 void removeReceiveHandler(ReceiveMessageHandler handler
);
197 boolean isReceiving();
200 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
202 void receiveMessages(Duration timeout
, ReceiveMessageHandler handler
) throws IOException
;
205 * Receive new messages from server, returns only if the thread is interrupted.
207 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
209 void setIgnoreAttachments(boolean ignoreAttachments
);
211 boolean hasCaughtUpWithOldMessages();
213 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
215 void sendContacts() throws IOException
;
217 List
<Recipient
> getRecipients(
218 boolean onlyContacts
,
219 Optional
<Boolean
> blocked
,
220 Collection
<RecipientIdentifier
.Single
> address
,
221 Optional
<String
> name
224 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
226 Group
getGroup(GroupId groupId
);
228 List
<Identity
> getIdentities();
230 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
233 * Trust this the identity with this fingerprint
235 * @param recipient account of the identity
236 * @param fingerprint Fingerprint
238 boolean trustIdentityVerified(
239 RecipientIdentifier
.Single recipient
, byte[] fingerprint
240 ) throws UnregisteredRecipientException
;
243 * Trust this the identity with this safety number
245 * @param recipient account of the identity
246 * @param safetyNumber Safety number
248 boolean trustIdentityVerifiedSafetyNumber(
249 RecipientIdentifier
.Single recipient
, String safetyNumber
250 ) throws UnregisteredRecipientException
;
253 * Trust this the identity with this scannable safety number
255 * @param recipient account of the identity
256 * @param safetyNumber Scannable safety number
258 boolean trustIdentityVerifiedSafetyNumber(
259 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
260 ) throws UnregisteredRecipientException
;
263 * Trust all keys of this identity without verification
265 * @param recipient account of the identity
267 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
269 void addAddressChangedListener(Runnable listener
);
271 void addClosedListener(Runnable listener
);
274 void close() throws IOException
;
276 interface ReceiveMessageHandler
{
278 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
281 void handleMessage(MessageEnvelope envelope
, Throwable e
);