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
.groups
.GroupId
;
25 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
26 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
27 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
28 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
29 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
30 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
31 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
32 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
33 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
35 import java
.io
.Closeable
;
37 import java
.io
.IOException
;
39 import java
.time
.Duration
;
40 import java
.util
.List
;
42 import java
.util
.Optional
;
44 import java
.util
.UUID
;
46 public interface Manager
extends Closeable
{
48 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
49 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
52 String
getSelfNumber();
55 * This is used for checking a set of phone numbers for registration on Signal
57 * @param numbers The set of phone number in question
58 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
59 * @throws IOException if it's unable to get the contacts to check if they're registered
61 Map
<String
, Pair
<String
, UUID
>> areUsersRegistered(Set
<String
> numbers
) throws IOException
;
63 void updateAccountAttributes(String deviceName
) throws IOException
;
65 Configuration
getConfiguration();
67 void updateConfiguration(Configuration configuration
) throws IOException
, NotMasterDeviceException
;
70 * @param givenName if null, the previous givenName will be kept
71 * @param familyName if null, the previous familyName will be kept
72 * @param about if null, the previous about text will be kept
73 * @param aboutEmoji if null, the previous about emoji will be kept
74 * @param avatar if avatar is null the image from the local avatar store is used (if present),
77 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
80 void unregister() throws IOException
;
82 void deleteAccount() throws IOException
;
84 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
86 List
<Device
> getLinkedDevices() throws IOException
;
88 void removeLinkedDevices(int deviceId
) throws IOException
;
90 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
92 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotMasterDeviceException
;
94 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
96 List
<Group
> getGroups();
98 SendGroupMessageResults
quitGroup(
99 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
100 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
102 void deleteGroup(GroupId groupId
) throws IOException
;
104 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
105 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
106 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
108 SendGroupMessageResults
updateGroup(
109 final GroupId groupId
, final UpdateGroup updateGroup
110 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
112 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
113 GroupInviteLinkUrl inviteLinkUrl
114 ) throws IOException
, InactiveGroupLinkException
;
116 SendMessageResults
sendTypingMessage(
117 TypingAction action
, Set
<RecipientIdentifier
> recipients
118 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
120 SendMessageResults
sendReadReceipt(
121 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
122 ) throws IOException
;
124 SendMessageResults
sendViewedReceipt(
125 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
126 ) throws IOException
;
128 SendMessageResults
sendMessage(
129 Message message
, Set
<RecipientIdentifier
> recipients
130 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
132 SendMessageResults
sendRemoteDeleteMessage(
133 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
134 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
136 SendMessageResults
sendMessageReaction(
139 RecipientIdentifier
.Single targetAuthor
,
140 long targetSentTimestamp
,
141 Set
<RecipientIdentifier
> recipients
142 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
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 setContactBlocked(
155 RecipientIdentifier
.Single recipient
, boolean blocked
156 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
158 void setGroupBlocked(
159 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
<Pair
<RecipientAddress
, Contact
>> getContacts();
219 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
221 Group
getGroup(GroupId groupId
);
223 List
<Identity
> getIdentities();
225 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
228 * Trust this the identity with this fingerprint
230 * @param recipient account of the identity
231 * @param fingerprint Fingerprint
233 boolean trustIdentityVerified(
234 RecipientIdentifier
.Single recipient
, byte[] fingerprint
235 ) throws UnregisteredRecipientException
;
238 * Trust this the identity with this safety number
240 * @param recipient account of the identity
241 * @param safetyNumber Safety number
243 boolean trustIdentityVerifiedSafetyNumber(
244 RecipientIdentifier
.Single recipient
, String safetyNumber
245 ) throws UnregisteredRecipientException
;
248 * Trust this the identity with this scannable safety number
250 * @param recipient account of the identity
251 * @param safetyNumber Scannable safety number
253 boolean trustIdentityVerifiedSafetyNumber(
254 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
255 ) throws UnregisteredRecipientException
;
258 * Trust all keys of this identity without verification
260 * @param recipient account of the identity
262 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
264 void addClosedListener(Runnable listener
);
267 void close() throws IOException
;
269 interface ReceiveMessageHandler
{
271 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
274 void handleMessage(MessageEnvelope envelope
, Throwable e
);