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
.Profile
;
32 import org
.asamk
.signal
.manager
.storage
.recipients
.Recipient
;
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
.Collection
;
41 import java
.util
.List
;
43 import java
.util
.Optional
;
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
, UserStatus
> getUserStatus(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
sendPaymentNotificationMessage(
145 byte[] receipt
, String note
, RecipientIdentifier
.Single recipient
146 ) throws IOException
;
148 SendMessageResults
sendEndSessionMessage(Set
<RecipientIdentifier
.Single
> recipients
) throws IOException
;
150 void deleteRecipient(RecipientIdentifier
.Single recipient
);
152 void deleteContact(RecipientIdentifier
.Single recipient
);
155 RecipientIdentifier
.Single recipient
, String name
156 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
158 void setContactsBlocked(
159 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
160 ) throws NotMasterDeviceException
, IOException
, UnregisteredRecipientException
;
162 void setGroupsBlocked(
163 Collection
<GroupId
> groupId
, boolean blocked
164 ) throws GroupNotFoundException
, IOException
, NotMasterDeviceException
;
167 * Change the expiration timer for a contact
169 void setExpirationTimer(
170 RecipientIdentifier
.Single recipient
, int messageExpirationTimer
171 ) throws IOException
, UnregisteredRecipientException
;
174 * Upload the sticker pack from path.
176 * @param path Path can be a path to a manifest.json file or to a zip file that contains a manifest.json file
177 * @return if successful, returns the URL to install the sticker pack in the signal app
179 StickerPackUrl
uploadStickerPack(File path
) throws IOException
, StickerPackInvalidException
;
181 List
<StickerPack
> getStickerPacks();
183 void requestAllSyncData() throws IOException
;
186 * Add a handler to receive new messages.
187 * Will start receiving messages from server, if not already started.
189 default void addReceiveHandler(ReceiveMessageHandler handler
) {
190 addReceiveHandler(handler
, false);
193 void addReceiveHandler(ReceiveMessageHandler handler
, final boolean isWeakListener
);
196 * Remove a handler to receive new messages.
197 * Will stop receiving messages from server, if this was the last registered receiver.
199 void removeReceiveHandler(ReceiveMessageHandler handler
);
201 boolean isReceiving();
204 * Receive new messages from server, returns if no new message arrive in a timespan of timeout.
206 void receiveMessages(Duration timeout
, ReceiveMessageHandler handler
) throws IOException
;
209 * Receive new messages from server, returns only if the thread is interrupted.
211 void receiveMessages(ReceiveMessageHandler handler
) throws IOException
;
213 void setIgnoreAttachments(boolean ignoreAttachments
);
215 boolean hasCaughtUpWithOldMessages();
217 boolean isContactBlocked(RecipientIdentifier
.Single recipient
);
219 void sendContacts() throws IOException
;
221 List
<Recipient
> getRecipients(
222 boolean onlyContacts
,
223 Optional
<Boolean
> blocked
,
224 Collection
<RecipientIdentifier
.Single
> address
,
225 Optional
<String
> name
228 String
getContactOrProfileName(RecipientIdentifier
.Single recipient
);
230 Group
getGroup(GroupId groupId
);
232 List
<Identity
> getIdentities();
234 List
<Identity
> getIdentities(RecipientIdentifier
.Single recipient
);
237 * Trust this the identity with this fingerprint
239 * @param recipient account of the identity
240 * @param fingerprint Fingerprint
242 boolean trustIdentityVerified(
243 RecipientIdentifier
.Single recipient
, byte[] fingerprint
244 ) throws UnregisteredRecipientException
;
247 * Trust this the identity with this safety number
249 * @param recipient account of the identity
250 * @param safetyNumber Safety number
252 boolean trustIdentityVerifiedSafetyNumber(
253 RecipientIdentifier
.Single recipient
, String safetyNumber
254 ) throws UnregisteredRecipientException
;
257 * Trust this the identity with this scannable safety number
259 * @param recipient account of the identity
260 * @param safetyNumber Scannable safety number
262 boolean trustIdentityVerifiedSafetyNumber(
263 RecipientIdentifier
.Single recipient
, byte[] safetyNumber
264 ) throws UnregisteredRecipientException
;
267 * Trust all keys of this identity without verification
269 * @param recipient account of the identity
271 boolean trustIdentityAllKeys(RecipientIdentifier
.Single recipient
) throws UnregisteredRecipientException
;
273 void addAddressChangedListener(Runnable listener
);
275 void addClosedListener(Runnable listener
);
278 void close() throws IOException
;
280 interface ReceiveMessageHandler
{
282 ReceiveMessageHandler EMPTY
= (envelope
, e
) -> {
285 void handleMessage(MessageEnvelope envelope
, Throwable e
);