X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/2ab42ca5471e8fc1e1a31cde954e19564178f114..00b3be044ea01a45a34a22c0197c754472760294:/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 b4579274..8b373e38 100644 --- a/lib/src/main/java/org/asamk/signal/manager/Manager.java +++ b/lib/src/main/java/org/asamk/signal/manager/Manager.java @@ -1,5 +1,6 @@ package org.asamk.signal.manager; +import org.asamk.signal.manager.api.Configuration; import org.asamk.signal.manager.api.Device; import org.asamk.signal.manager.api.Group; import org.asamk.signal.manager.api.Identity; @@ -32,6 +33,7 @@ import java.io.Closeable; import java.io.File; import java.io.IOException; import java.net.URI; +import java.time.Duration; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -39,7 +41,6 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; public interface Manager extends Closeable { @@ -59,6 +60,7 @@ public interface Manager extends Closeable { var account = SignalAccount.load(pathConfig.dataPath(), number, true, trustNewIdentity); if (!account.isRegistered()) { + account.close(); throw new NotRegisteredException(); } @@ -75,7 +77,7 @@ public interface Manager extends Closeable { return PhoneNumberFormatter.isValidNumber(e164Number, countryCode); } - static List getAllLocalNumbers(File settingsPath) { + static List getAllLocalAccountNumbers(File settingsPath) { var pathConfig = PathConfig.createDefault(settingsPath); final var dataPath = pathConfig.dataPath(); final var files = dataPath.listFiles(); @@ -88,7 +90,7 @@ public interface Manager extends Closeable { .filter(File::isFile) .map(File::getName) .filter(file -> PhoneNumberFormatter.isValidNumber(file, null)) - .collect(Collectors.toList()); + .toList(); } String getSelfNumber(); @@ -99,12 +101,9 @@ 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; + Configuration getConfiguration(); + + void updateConfiguration(Configuration configuration) throws IOException, NotMasterDeviceException; void setProfile( String givenName, String familyName, String about, String aboutEmoji, Optional avatar @@ -146,17 +145,17 @@ public interface Manager extends Closeable { GroupInviteLinkUrl inviteLinkUrl ) throws IOException, InactiveGroupLinkException; - void sendTypingMessage( + SendMessageResults sendTypingMessage( TypingAction action, Set recipients - ) throws IOException, UntrustedIdentityException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException; + ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException; - void sendReadReceipt( + SendMessageResults sendReadReceipt( RecipientIdentifier.Single sender, List messageIds - ) throws IOException, UntrustedIdentityException; + ) throws IOException; - void sendViewedReceipt( + SendMessageResults sendViewedReceipt( RecipientIdentifier.Single sender, List messageIds - ) throws IOException, UntrustedIdentityException; + ) throws IOException; SendMessageResults sendMessage( Message message, Set recipients @@ -176,6 +175,10 @@ public interface Manager extends Closeable { SendMessageResults sendEndSessionMessage(Set recipients) throws IOException; + void deleteRecipient(RecipientIdentifier.Single recipient) throws IOException; + + void deleteContact(RecipientIdentifier.Single recipient) throws IOException; + void setContactName( RecipientIdentifier.Single recipient, String name ) throws NotMasterDeviceException, IOException; @@ -200,7 +203,11 @@ public interface Manager extends Closeable { * Add a handler to receive new messages. * Will start receiving messages from server, if not already started. */ - void addReceiveHandler(ReceiveMessageHandler handler); + default void addReceiveHandler(ReceiveMessageHandler handler) { + addReceiveHandler(handler, false); + } + + void addReceiveHandler(ReceiveMessageHandler handler, final boolean isWeakListener); /** * Remove a handler to receive new messages. @@ -213,7 +220,7 @@ public interface Manager extends Closeable { /** * 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; + void receiveMessages(Duration timeout, ReceiveMessageHandler handler) throws IOException; /** * Receive new messages from server, returns only if the thread is interrupted. @@ -226,8 +233,6 @@ public interface Manager extends Closeable { boolean isContactBlocked(RecipientIdentifier.Single recipient); - File getAttachmentFile(String attachmentId); - void sendContacts() throws IOException; List> getContacts(); @@ -248,11 +253,16 @@ public interface Manager extends Closeable { boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient); + void addClosedListener(Runnable listener); + @Override void close() throws IOException; interface ReceiveMessageHandler { + ReceiveMessageHandler EMPTY = (envelope, e) -> { + }; + void handleMessage(MessageEnvelope envelope, Throwable e); } }