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
.UserStatus
;
25 import org
.asamk
.signal
.manager
.groups
.GroupId
;
26 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
27 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
28 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
29 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
30 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
31 import org
.asamk
.signal
.manager
.storage
.recipients
.Contact
;
32 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
33 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientAddress
;
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 * @param givenName if null, the previous givenName will be kept
72 * @param familyName if null, the previous familyName will be kept
73 * @param about if null, the previous about text will be kept
74 * @param aboutEmoji if null, the previous about emoji will be kept
75 * @param avatar if avatar is null the image from the local avatar store is used (if present),
78 String givenName
, String familyName
, String about
, String aboutEmoji
, Optional
<File
> avatar
81 void unregister() throws IOException
;
83 void deleteAccount() throws IOException
;
85 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
87 List
<Device
> getLinkedDevices() throws IOException
;
89 void removeLinkedDevices(int deviceId
) throws IOException
;
91 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
93 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotMasterDeviceException
;
95 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
97 List
<Group
> getGroups();
99 SendGroupMessageResults
quitGroup(
100 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
101 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
103 void deleteGroup(GroupId groupId
) throws IOException
;
105 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
106 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
107 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
109 SendGroupMessageResults
updateGroup(
110 final GroupId groupId
, final UpdateGroup updateGroup
111 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
113 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
114 GroupInviteLinkUrl inviteLinkUrl
115 ) throws IOException
, InactiveGroupLinkException
;
117 SendMessageResults
sendTypingMessage(
118 TypingAction action
, Set
<RecipientIdentifier
> recipients
119 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
121 SendMessageResults
sendReadReceipt(
122 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
123 ) throws IOException
;
125 SendMessageResults
sendViewedReceipt(
126 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
127 ) throws IOException
;
129 SendMessageResults
sendMessage(
130 Message message
, Set
<RecipientIdentifier
> recipients
131 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
133 SendMessageResults
sendRemoteDeleteMessage(
134 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
135 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
137 SendMessageResults
sendMessageReaction(
140 RecipientIdentifier
.Single targetAuthor
,
141 long targetSentTimestamp
,
142 Set
<RecipientIdentifier
> recipients
143 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
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 NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
155 void setContactsBlocked(
156 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
157 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
159 void setGroupsBlocked(
160 Collection
<GroupId
> groupId
, boolean blocked
161 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
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 setIgnoreAttachments(boolean ignoreAttachments
);
212 boolean hasCaughtUpWithOldMessages();
214 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
216 void sendContacts() throws IOException
;
218 List
<Pair
<RecipientAddress
, Contact
>> getContacts();
220 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
222 Group
getGroup(GroupId groupId
);
224 List
<Identity
> getIdentities();
226 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
229 * Trust this the identity with this fingerprint
231 * @param recipient account of the identity
232 * @param fingerprint Fingerprint
234 boolean trustIdentityVerified(
235 RecipientIdentifier
.Single recipient
, byte[] fingerprint
236 ) throws UnregisteredRecipientException
;
239 * Trust this the identity with this safety number
241 * @param recipient account of the identity
242 * @param safetyNumber Safety number
244 boolean trustIdentityVerifiedSafetyNumber(
245 RecipientIdentifier
.Single recipient
, String safetyNumber
246 ) throws UnregisteredRecipientException
;
249 * Trust this the identity with this scannable safety number
251 * @param recipient account of the identity
252 * @param safetyNumber Scannable safety number
254 boolean trustIdentityVerifiedSafetyNumber(
255 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
256 ) throws UnregisteredRecipientException
;
259 * Trust all keys of this identity without verification
261 * @param recipient account of the identity
263 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
265 void addAddressChangedListener(Runnable listener
);
267 void addClosedListener(Runnable listener
);
270 void close() throws IOException
;
272 interface ReceiveMessageHandler
{
274 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
277 void handleMessage(MessageEnvelope envelope
, Throwable e
);