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
.ReceiveConfig
;
16 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
17 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
18 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
19 import org
.asamk
.signal
.manager
.api
.StickerPack
;
20 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
21 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
22 import org
.asamk
.signal
.manager
.api
.TypingAction
;
23 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
24 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
25 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
26 import org
.asamk
.signal
.manager
.api
.UserStatus
;
27 import org
.asamk
.signal
.manager
.groups
.GroupId
;
28 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
29 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
30 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
31 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
32 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
33 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
34 import org
.asamk
.signal
.manager
.storage
.recipients
.Recipient
;
35 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
37 import java
.io
.Closeable
;
39 import java
.io
.IOException
;
41 import java
.time
.Duration
;
42 import java
.util
.Collection
;
43 import java
.util
.List
;
45 import java
.util
.Optional
;
48 public interface Manager
extends Closeable
{
50 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
51 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
54 String
getSelfNumber();
57 * This is used for checking a set of phone numbers for registration on Signal
59 * @param numbers The set of phone number in question
60 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
61 * @throws IOException if it's unable to get the contacts to check if they're registered
63 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
;
65 void updateAccountAttributes(String deviceName
) throws IOException
;
67 Configuration
getConfiguration();
69 void updateConfiguration(Configuration configuration
) throws IOException
, NotPrimaryDeviceException
;
72 * Update the user's profile.
73 * If a field is null, the previous value will be kept.
75 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
77 void unregister() throws IOException
;
79 void deleteAccount() throws IOException
;
81 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
83 List
<Device
> getLinkedDevices() throws IOException
;
85 void removeLinkedDevices(int deviceId
) throws IOException
;
87 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
89 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
91 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
93 List
<Group
> getGroups();
95 SendGroupMessageResults
quitGroup(
96 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
97 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
99 void deleteGroup(GroupId groupId
) throws IOException
;
101 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
102 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
103 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
105 SendGroupMessageResults
updateGroup(
106 final GroupId groupId
, final UpdateGroup updateGroup
107 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
109 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
110 GroupInviteLinkUrl inviteLinkUrl
111 ) throws IOException
, InactiveGroupLinkException
;
113 SendMessageResults
sendTypingMessage(
114 TypingAction action
, Set
<RecipientIdentifier
> recipients
115 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
117 SendMessageResults
sendReadReceipt(
118 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
119 ) throws IOException
;
121 SendMessageResults
sendViewedReceipt(
122 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
123 ) throws IOException
;
125 SendMessageResults
sendMessage(
126 Message message
, Set
<RecipientIdentifier
> recipients
127 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
129 SendMessageResults
sendRemoteDeleteMessage(
130 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
131 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
133 SendMessageResults
sendMessageReaction(
136 RecipientIdentifier
.Single targetAuthor
,
137 long targetSentTimestamp
,
138 Set
<RecipientIdentifier
> recipients
139 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
141 SendMessageResults
sendPaymentNotificationMessage(
142 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
143 ) throws IOException
;
145 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
147 void deleteRecipient(RecipientIdentifier
.Single recipient
);
149 void deleteContact(RecipientIdentifier
.Single recipient
);
152 RecipientIdentifier
.Single recipient
, String name
153 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
155 void setContactsBlocked(
156 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
157 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
159 void setGroupsBlocked(
160 Collection
<GroupId
> groupId
, boolean blocked
161 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
164 * Change the expiration timer for a contact
166 void setExpirationTimer(
167 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
168 ) throws IOException
, UnregisteredRecipientException
;
171 * Upload the sticker pack from path.
173 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
174 * @return if successful, returns the URL to install the sticker pack in the signal app
176 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
178 List
<StickerPack
> getStickerPacks();
180 void requestAllSyncData() throws IOException
;
183 * Add a handler to receive new messages.
184 * Will start receiving messages from server, if not already started.
186 default void addReceiveHandler(ReceiveMessageHandler handler
) {
187 addReceiveHandler(handler
, false);
190 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
193 * Remove a handler to receive new messages.
194 * Will stop receiving messages from server, if this was the last registered receiver.
196 void removeReceiveHandler(ReceiveMessageHandler handler
);
198 boolean isReceiving();
201 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
203 void receiveMessages(Duration timeout
, ReceiveMessageHandler handler
) throws IOException
;
206 * Receive new messages from server, returns only if the thread is interrupted.
208 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
210 void setReceiveConfig(ReceiveConfig receiveConfig
);
212 boolean hasCaughtUpWithOldMessages();
214 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
216 void sendContacts() throws IOException
;
218 List
<Recipient
> getRecipients(
219 boolean onlyContacts
,
220 Optional
<Boolean
> blocked
,
221 Collection
<RecipientIdentifier
.Single
> address
,
222 Optional
<String
> name
225 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
227 Group
getGroup(GroupId groupId
);
229 List
<Identity
> getIdentities();
231 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
234 * Trust this the identity with this fingerprint
236 * @param recipient account of the identity
237 * @param fingerprint Fingerprint
239 boolean trustIdentityVerified(
240 RecipientIdentifier
.Single recipient
, byte[] fingerprint
241 ) throws UnregisteredRecipientException
;
244 * Trust this the identity with this safety number
246 * @param recipient account of the identity
247 * @param safetyNumber Safety number
249 boolean trustIdentityVerifiedSafetyNumber(
250 RecipientIdentifier
.Single recipient
, String safetyNumber
251 ) throws UnregisteredRecipientException
;
254 * Trust this the identity with this scannable safety number
256 * @param recipient account of the identity
257 * @param safetyNumber Scannable safety number
259 boolean trustIdentityVerifiedSafetyNumber(
260 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
261 ) throws UnregisteredRecipientException
;
264 * Trust all keys of this identity without verification
266 * @param recipient account of the identity
268 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
270 void addAddressChangedListener(Runnable listener
);
272 void addClosedListener(Runnable listener
);
275 void close() throws IOException
;
277 interface ReceiveMessageHandler
{
279 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
282 void handleMessage(MessageEnvelope envelope
, Throwable e
);