1 package org
.asamk
.signal
.manager
;
3 import org
.asamk
.signal
.manager
.api
.AlreadyReceivingException
;
4 import org
.asamk
.signal
.manager
.api
.AttachmentInvalidException
;
5 import org
.asamk
.signal
.manager
.api
.Configuration
;
6 import org
.asamk
.signal
.manager
.api
.Device
;
7 import org
.asamk
.signal
.manager
.api
.Group
;
8 import org
.asamk
.signal
.manager
.api
.Identity
;
9 import org
.asamk
.signal
.manager
.api
.InactiveGroupLinkException
;
10 import org
.asamk
.signal
.manager
.api
.InvalidDeviceLinkException
;
11 import org
.asamk
.signal
.manager
.api
.InvalidStickerException
;
12 import org
.asamk
.signal
.manager
.api
.Message
;
13 import org
.asamk
.signal
.manager
.api
.MessageEnvelope
;
14 import org
.asamk
.signal
.manager
.api
.NotPrimaryDeviceException
;
15 import org
.asamk
.signal
.manager
.api
.Pair
;
16 import org
.asamk
.signal
.manager
.api
.PendingAdminApprovalException
;
17 import org
.asamk
.signal
.manager
.api
.ReceiveConfig
;
18 import org
.asamk
.signal
.manager
.api
.Recipient
;
19 import org
.asamk
.signal
.manager
.api
.RecipientIdentifier
;
20 import org
.asamk
.signal
.manager
.api
.SendGroupMessageResults
;
21 import org
.asamk
.signal
.manager
.api
.SendMessageResults
;
22 import org
.asamk
.signal
.manager
.api
.StickerPack
;
23 import org
.asamk
.signal
.manager
.api
.StickerPackInvalidException
;
24 import org
.asamk
.signal
.manager
.api
.StickerPackUrl
;
25 import org
.asamk
.signal
.manager
.api
.TypingAction
;
26 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
27 import org
.asamk
.signal
.manager
.api
.UpdateGroup
;
28 import org
.asamk
.signal
.manager
.api
.UpdateProfile
;
29 import org
.asamk
.signal
.manager
.api
.UserStatus
;
30 import org
.asamk
.signal
.manager
.groups
.GroupId
;
31 import org
.asamk
.signal
.manager
.groups
.GroupInviteLinkUrl
;
32 import org
.asamk
.signal
.manager
.groups
.GroupNotFoundException
;
33 import org
.asamk
.signal
.manager
.groups
.GroupSendingNotAllowedException
;
34 import org
.asamk
.signal
.manager
.groups
.LastGroupAdminException
;
35 import org
.asamk
.signal
.manager
.groups
.NotAGroupMemberException
;
36 import org
.asamk
.signal
.manager
.storage
.recipients
.Profile
;
37 import org
.whispersystems
.signalservice
.api
.util
.PhoneNumberFormatter
;
39 import java
.io
.Closeable
;
41 import java
.io
.IOException
;
43 import java
.time
.Duration
;
44 import java
.util
.Collection
;
45 import java
.util
.List
;
47 import java
.util
.Optional
;
50 public interface Manager
extends Closeable
{
52 static boolean isValidNumber(final String e164Number
, final String countryCode
) {
53 return PhoneNumberFormatter
.isValidNumber(e164Number
, countryCode
);
56 String
getSelfNumber();
59 * This is used for checking a set of phone numbers for registration on Signal
61 * @param numbers The set of phone number in question
62 * @return A map of numbers to canonicalized number and uuid. If a number is not registered the uuid is null.
63 * @throws IOException if it's unable to get the contacts to check if they're registered
65 Map
<String
, UserStatus
> getUserStatus(Set
<String
> numbers
) throws IOException
;
67 void updateAccountAttributes(String deviceName
) throws IOException
;
69 Configuration
getConfiguration();
71 void updateConfiguration(Configuration configuration
) throws IOException
, NotPrimaryDeviceException
;
74 * Update the user's profile.
75 * If a field is null, the previous value will be kept.
77 void updateProfile(UpdateProfile updateProfile
) throws IOException
;
79 void unregister() throws IOException
;
81 void deleteAccount() throws IOException
;
83 void submitRateLimitRecaptchaChallenge(String challenge
, String captcha
) throws IOException
;
85 List
<Device
> getLinkedDevices() throws IOException
;
87 void removeLinkedDevices(int deviceId
) throws IOException
;
89 void addDeviceLink(URI linkUri
) throws IOException
, InvalidDeviceLinkException
;
91 void setRegistrationLockPin(Optional
<String
> pin
) throws IOException
, NotPrimaryDeviceException
;
93 Profile
getRecipientProfile(RecipientIdentifier
.Single recipient
) throws IOException
, UnregisteredRecipientException
;
95 List
<Group
> getGroups();
97 SendGroupMessageResults
quitGroup(
98 GroupId groupId
, Set
<RecipientIdentifier
.Single
> groupAdmins
99 ) throws GroupNotFoundException
, IOException
, NotAGroupMemberException
, LastGroupAdminException
, UnregisteredRecipientException
;
101 void deleteGroup(GroupId groupId
) throws IOException
;
103 Pair
<GroupId
, SendGroupMessageResults
> createGroup(
104 String name
, Set
<RecipientIdentifier
.Single
> members
, File avatarFile
105 ) throws IOException
, AttachmentInvalidException
, UnregisteredRecipientException
;
107 SendGroupMessageResults
updateGroup(
108 final GroupId groupId
, final UpdateGroup updateGroup
109 ) throws IOException
, GroupNotFoundException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
;
111 Pair
<GroupId
, SendGroupMessageResults
> joinGroup(
112 GroupInviteLinkUrl inviteLinkUrl
113 ) throws IOException
, InactiveGroupLinkException
, PendingAdminApprovalException
;
115 SendMessageResults
sendTypingMessage(
116 TypingAction action
, Set
<RecipientIdentifier
> recipients
117 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
119 SendMessageResults
sendReadReceipt(
120 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
121 ) throws IOException
;
123 SendMessageResults
sendViewedReceipt(
124 RecipientIdentifier
.Single sender
, List
<Long
> messageIds
125 ) throws IOException
;
127 SendMessageResults
sendMessage(
128 Message message
, Set
<RecipientIdentifier
> recipients
129 ) throws IOException
, AttachmentInvalidException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
, UnregisteredRecipientException
, InvalidStickerException
;
131 SendMessageResults
sendRemoteDeleteMessage(
132 long targetSentTimestamp
, Set
<RecipientIdentifier
> recipients
133 ) throws IOException
, NotAGroupMemberException
, GroupNotFoundException
, GroupSendingNotAllowedException
;
135 SendMessageResults
sendMessageReaction(
138 RecipientIdentifier
.Single targetAuthor
,
139 long targetSentTimestamp
,
140 Set
<RecipientIdentifier
> recipients
,
141 final boolean isStory
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 givenName
, final String familyName
156 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
158 void setContactsBlocked(
159 Collection
<RecipientIdentifier
.Single
> recipient
, boolean blocked
160 ) throws NotPrimaryDeviceException
, IOException
, UnregisteredRecipientException
;
162 void setGroupsBlocked(
163 Collection
<GroupId
> groupId
, boolean blocked
164 ) throws GroupNotFoundException
, IOException
, NotPrimaryDeviceException
;
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 public void receiveMessages(
207 Optional
<Duration
> timeout
, Optional
<Integer
> maxMessages
, ReceiveMessageHandler handler
208 ) throws IOException
, AlreadyReceivingException
;
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
);