X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/b91c162159c7c28d049ceb8889c419791573d3bb..fc0a9b4102feef185e4a09881e3b079b82df3da7:/lib/src/main/java/org/asamk/signal/manager/Manager.java diff --git a/lib/src/main/java/org/asamk/signal/manager/Manager.java b/lib/src/main/java/org/asamk/signal/manager/Manager.java index d2eb0f8f..0a8762d9 100644 --- a/lib/src/main/java/org/asamk/signal/manager/Manager.java +++ b/lib/src/main/java/org/asamk/signal/manager/Manager.java @@ -1,29 +1,27 @@ package org.asamk.signal.manager; import org.asamk.signal.manager.api.Device; +import org.asamk.signal.manager.api.Group; +import org.asamk.signal.manager.api.Identity; import org.asamk.signal.manager.api.Message; import org.asamk.signal.manager.api.RecipientIdentifier; import org.asamk.signal.manager.api.SendGroupMessageResults; import org.asamk.signal.manager.api.SendMessageResults; import org.asamk.signal.manager.api.TypingAction; +import org.asamk.signal.manager.api.UpdateGroup; import org.asamk.signal.manager.config.ServiceConfig; import org.asamk.signal.manager.config.ServiceEnvironment; import org.asamk.signal.manager.groups.GroupId; import org.asamk.signal.manager.groups.GroupInviteLinkUrl; -import org.asamk.signal.manager.groups.GroupLinkState; import org.asamk.signal.manager.groups.GroupNotFoundException; -import org.asamk.signal.manager.groups.GroupPermission; import org.asamk.signal.manager.groups.GroupSendingNotAllowedException; import org.asamk.signal.manager.groups.LastGroupAdminException; import org.asamk.signal.manager.groups.NotAGroupMemberException; import org.asamk.signal.manager.storage.SignalAccount; -import org.asamk.signal.manager.storage.groups.GroupInfo; -import org.asamk.signal.manager.storage.identities.IdentityInfo; import org.asamk.signal.manager.storage.identities.TrustNewIdentity; import org.asamk.signal.manager.storage.recipients.Contact; import org.asamk.signal.manager.storage.recipients.Profile; -import org.asamk.signal.manager.storage.recipients.RecipientId; -import org.whispersystems.libsignal.IdentityKey; +import org.asamk.signal.manager.storage.recipients.RecipientAddress; import org.whispersystems.libsignal.InvalidKeyException; import org.whispersystems.libsignal.util.Pair; import org.whispersystems.libsignal.util.guava.Optional; @@ -51,7 +49,7 @@ import java.util.stream.Collectors; public interface Manager extends Closeable { static Manager init( - String username, + String number, File settingsPath, ServiceEnvironment serviceEnvironment, String userAgent, @@ -59,11 +57,11 @@ public interface Manager extends Closeable { ) throws IOException, NotRegisteredException { var pathConfig = PathConfig.createDefault(settingsPath); - if (!SignalAccount.userExists(pathConfig.getDataPath(), username)) { + if (!SignalAccount.userExists(pathConfig.getDataPath(), number)) { throw new NotRegisteredException(); } - var account = SignalAccount.load(pathConfig.getDataPath(), username, true, trustNewIdentity); + var account = SignalAccount.load(pathConfig.getDataPath(), number, true, trustNewIdentity); if (!account.isRegistered()) { throw new NotRegisteredException(); @@ -74,7 +72,7 @@ public interface Manager extends Closeable { return new ManagerImpl(account, pathConfig, serviceEnvironmentConfig, userAgent); } - static List getAllLocalUsernames(File settingsPath) { + static List getAllLocalNumbers(File settingsPath) { var pathConfig = PathConfig.createDefault(settingsPath); final var dataPath = pathConfig.getDataPath(); final var files = dataPath.listFiles(); @@ -90,11 +88,7 @@ public interface Manager extends Closeable { .collect(Collectors.toList()); } - String getUsername(); - - RecipientId getSelfRecipientId(); - - int getDeviceId(); + String getSelfNumber(); void checkAccountState() throws IOException; @@ -102,6 +96,13 @@ public interface Manager extends Closeable { void updateAccountAttributes(String deviceName) throws IOException; + void updateConfiguration( + final Boolean readReceipts, + final Boolean unidentifiedDeliveryIndicators, + final Boolean typingIndicators, + final Boolean linkPreviews + ) throws IOException, NotMasterDeviceException; + void setProfile( String givenName, String familyName, String about, String aboutEmoji, Optional avatar ) throws IOException; @@ -114,15 +115,15 @@ public interface Manager extends Closeable { List getLinkedDevices() throws IOException; - void removeLinkedDevices(int deviceId) throws IOException; + void removeLinkedDevices(long deviceId) throws IOException; void addDeviceLink(URI linkUri) throws IOException, InvalidKeyException; void setRegistrationLockPin(Optional pin) throws IOException, UnauthenticatedResponseException; - Profile getRecipientProfile(RecipientId recipientId); + Profile getRecipientProfile(RecipientIdentifier.Single recipient) throws UnregisteredUserException; - List getGroups(); + List getGroups(); SendGroupMessageResults quitGroup( GroupId groupId, Set groupAdmins @@ -135,20 +136,7 @@ public interface Manager extends Closeable { ) throws IOException, AttachmentInvalidException; SendGroupMessageResults updateGroup( - GroupId groupId, - String name, - String description, - Set members, - Set removeMembers, - Set admins, - Set removeAdmins, - boolean resetGroupLink, - GroupLinkState groupLinkState, - GroupPermission addMemberPermission, - GroupPermission editDetailsPermission, - File avatarFile, - Integer expirationTimer, - Boolean isAnnouncementGroup + final GroupId groupId, final UpdateGroup updateGroup ) throws IOException, GroupNotFoundException, AttachmentInvalidException, NotAGroupMemberException, GroupSendingNotAllowedException; Pair joinGroup( @@ -195,7 +183,7 @@ public interface Manager extends Closeable { void setGroupBlocked( GroupId groupId, boolean blocked - ) throws GroupNotFoundException, IOException; + ) throws GroupNotFoundException, IOException, NotMasterDeviceException; void setExpirationTimer( RecipientIdentifier.Single recipient, int messageExpirationTimer @@ -205,13 +193,31 @@ public interface Manager extends Closeable { void requestAllSyncData() throws IOException; - void receiveMessages( - long timeout, - TimeUnit unit, - boolean returnOnTimeout, - boolean ignoreAttachments, - ReceiveMessageHandler handler - ) throws IOException; + /** + * Add a handler to receive new messages. + * Will start receiving messages from server, if not already started. + */ + void addReceiveHandler(ReceiveMessageHandler handler); + + /** + * Remove a handler to receive new messages. + * Will stop receiving messages from server, if this was the last registered receiver. + */ + void removeReceiveHandler(ReceiveMessageHandler handler); + + boolean isReceiving(); + + /** + * Receive new messages from server, returns if no new message arrive in a timespan of timeout. + */ + void receiveMessages(long timeout, TimeUnit unit, ReceiveMessageHandler handler) throws IOException; + + /** + * Receive new messages from server, returns only if the thread is interrupted. + */ + void receiveMessages(ReceiveMessageHandler handler) throws IOException; + + void setIgnoreAttachments(boolean ignoreAttachments); boolean hasCaughtUpWithOldMessages(); @@ -221,15 +227,15 @@ public interface Manager extends Closeable { void sendContacts() throws IOException; - List> getContacts(); + List> getContacts(); - String getContactOrProfileName(RecipientIdentifier.Single recipientIdentifier); + String getContactOrProfileName(RecipientIdentifier.Single recipient); - GroupInfo getGroup(GroupId groupId); + Group getGroup(GroupId groupId); - List getIdentities(); + List getIdentities(); - List getIdentities(RecipientIdentifier.Single recipient); + List getIdentities(RecipientIdentifier.Single recipient); boolean trustIdentityVerified(RecipientIdentifier.Single recipient, byte[] fingerprint); @@ -239,16 +245,8 @@ public interface Manager extends Closeable { boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient); - String computeSafetyNumber(SignalServiceAddress theirAddress, IdentityKey theirIdentityKey); - - byte[] computeSafetyNumberForScanning(SignalServiceAddress theirAddress, IdentityKey theirIdentityKey); - SignalServiceAddress resolveSignalServiceAddress(SignalServiceAddress address); - SignalServiceAddress resolveSignalServiceAddress(UUID uuid); - - SignalServiceAddress resolveSignalServiceAddress(RecipientId recipientId); - @Override void close() throws IOException;