]> nmode's Git Repositories - signal-cli/commitdiff
Dbus get/setConfiguration methods
authorJohn Freed <okgithub@johnfreed.com>
Mon, 4 Oct 2021 06:48:56 +0000 (08:48 +0200)
committerJohn Freed <okgithub@johnfreed.com>
Mon, 4 Oct 2021 06:48:56 +0000 (08:48 +0200)
implement:

- getConfiguration() -> [readReceipts<b>, unidentifiedDeliveryIndicators<b>, typingIndicators<b>, linkPreviews<b>] -> <>::

- setConfiguration(readReceipts<b>, unidentifiedDeliveryIndicators<b>, typingIndicators<b>, linkPreviews<b>) -> <>::

Update documentation

lib/src/main/java/org/asamk/signal/manager/Manager.java
lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java
man/signal-cli-dbus.5.adoc
src/main/java/org/asamk/Signal.java
src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java
src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java

index 7a4219660dd959c6af3cc14af8e5fafe77b182e1..943b5e7580526dfbe84dc147ddb18e1c6513acb1 100644 (file)
@@ -105,6 +105,8 @@ public interface Manager extends Closeable {
             final Boolean linkPreviews
     ) throws IOException, NotMasterDeviceException;
 
+    List<Boolean> getConfiguration() throws IOException, NotMasterDeviceException;
+
     void setProfile(
             String givenName, String familyName, String about, String aboutEmoji, Optional<File> avatar
     ) throws IOException;
index 0fd1eb33cf0d69a937f45ab6e52c4d0a91b2ccb8..b8414329d77ccc14b7037a8ca7ef658d3faa4541 100644 (file)
@@ -347,6 +347,19 @@ public class ManagerImpl implements Manager {
         syncHelper.sendConfigurationMessage();
     }
 
+    @Override
+    public List<Boolean> getConfiguration() throws IOException, NotMasterDeviceException {
+        if (!account.isMasterDevice()) {
+            throw new NotMasterDeviceException();
+        }
+        final var configurationStore = account.getConfigurationStore();
+        final Boolean readReceipts = configurationStore.getReadReceipts();
+        final Boolean unidentifiedDeliveryIndicators = configurationStore.getUnidentifiedDeliveryIndicators();
+        final Boolean typingIndicators = configurationStore.getTypingIndicators();
+        final Boolean linkPreviews = configurationStore.getLinkPreviews();
+        return List.of(readReceipts, unidentifiedDeliveryIndicators, typingIndicators, linkPreviews);
+    }
+
     /**
      * @param givenName  if null, the previous givenName will be kept
      * @param familyName if null, the previous familyName will be kept
index e7cd083f16305891151f167b6dec0dffcaa370d8..56b28ddf1f75181affa5b1701028201bd580c82d 100755 (executable)
@@ -263,7 +263,7 @@ Exceptions: Failure, InvalidNumber
 
 getContactName(number<s>) -> name<s>::
 * number  : Phone number
-* name    : Contact's name in local storage (from the master device for a linked account, or the one set with setContactName); if not set, contact's profile name is used
+* name    : Contact's name in local storage (from the primary device for a linked account, or the one set with setContactName); if not set, contact's profile name is used
 
 setContactName(number<s>,name<>) -> <>::
 * number  : Phone number
@@ -361,7 +361,27 @@ uploadStickerPack(stickerPackPath<s>) -> url<s>::
 * stickerPackPath : Path to the manifest.json file or a zip file in the same directory
 * url             : URL of sticker pack after successful upload
 
-Exception: Failure
+Exception: Failure, IOError
+
+getConfiguration() -> [readReceipts<b>, unidentifiedDeliveryIndicators<b>, typingIndicators<b>, linkPreviews<b>] -> <>::
+* readReceipts                   : Should Signal send read receipts (true/false).
+* unidentifiedDeliveryIndicators : Should Signal show unidentified delivery indicators (true/false).
+* typingIndicators               : Should Signal send/show typing indicators (true/false).
+* linkPreviews                   : Should Signal generate link previews (true/false).
+
+Gets an array of four booleans as indicated. Only works from primary device.
+
+Exceptions: IOError, UserError
+
+setConfiguration(readReceipts<b>, unidentifiedDeliveryIndicators<b>, typingIndicators<b>, linkPreviews<b>) -> <>::
+* readReceipts                   : Should Signal send read receipts (true/false).
+* unidentifiedDeliveryIndicators : Should Signal show unidentified delivery indicators (true/false).
+* typingIndicators               : Should Signal send/show typing indicators (true/false).
+* linkPreviews                   : Should Signal generate link previews (true/false).
+
+Update Signal configurations and sync them to linked devices. Only works from primary device.
+
+Exceptions: IOError, UserError
 
 == Signals
 
index b88000858c38e1b4b1b15c82e782ae2e49157263..cf909fa0dce48fedf4d7a4db3b765a53aea3a6c7 100644 (file)
@@ -141,6 +141,10 @@ public interface Signal extends DBusInterface {
 
     String uploadStickerPack(String stickerPackPath) throws Error.Failure;
 
+    void setConfiguration(boolean readReceipts, boolean unidentifiedDeliveryIndicators, boolean typingIndicators, boolean linkPreviews) throws Error.IOError, Error.UserError;
+
+    List<Boolean> getConfiguration();
+
     class MessageReceived extends DBusSignal {
 
         private final long timestamp;
@@ -317,5 +321,19 @@ public interface Signal extends DBusInterface {
                 super(message);
             }
         }
+
+        class IOError extends DBusExecutionException {
+
+            public IOError(final String message) {
+                super(message);
+            }
+        }
+
+        class UserError extends DBusExecutionException {
+
+            public UserError(final String message) {
+                super(message);
+            }
+        }
     }
 }
index 3124a5b05ed8ee655418a466bab56c44c5edc83d..bfd7fde9764ed552aeca4f84590d2193c3806c29 100644 (file)
@@ -108,7 +108,17 @@ public class DbusManagerImpl implements Manager {
             final Boolean typingIndicators,
             final Boolean linkPreviews
     ) throws IOException {
-        throw new UnsupportedOperationException();
+        signal.setConfiguration(
+                readReceipts,
+                unidentifiedDeliveryIndicators,
+                typingIndicators,
+                linkPreviews
+                );
+    }
+
+    @Override
+    public List<Boolean> getConfiguration() {
+        return signal.getConfiguration();
     }
 
     @Override
index ab9c89b2ee6afd3f087356d7bfcbece2a5b60bd5..55f994753d642561e54d3e6095ade4469f9ce6d8 100644 (file)
@@ -1,6 +1,7 @@
 package org.asamk.signal.dbus;
 
 import org.asamk.Signal;
+import org.asamk.Signal.Error;
 import org.asamk.signal.BaseConfig;
 import org.asamk.signal.manager.AttachmentInvalidException;
 import org.asamk.signal.manager.Manager;
@@ -683,12 +684,36 @@ public class DbusSignalImpl implements Signal {
         try {
             return m.uploadStickerPack(path).toString();
         } catch (IOException e) {
-            throw new Error.Failure("Upload error (maybe image size is too large):" + e.getMessage());
+            throw new Error.IOError("Upload error (maybe image size is too large):" + e.getMessage());
         } catch (StickerPackInvalidException e) {
             throw new Error.Failure("Invalid sticker pack: " + e.getMessage());
         }
     }
 
+    @Override
+    public void setConfiguration(boolean readReceipts, boolean unidentifiedDeliveryIndicators, boolean typingIndicators, boolean linkPreviews) {
+          try {
+              m.updateConfiguration(readReceipts, unidentifiedDeliveryIndicators, typingIndicators, linkPreviews);
+          } catch (IOException e) {
+              throw new Error.IOError("UpdateAccount error: " + e.getMessage());
+          } catch (NotMasterDeviceException e) {
+              throw new Error.UserError("This command doesn't work on linked devices.");
+          }
+    }
+
+    @Override
+    public List<Boolean> getConfiguration() {
+        List<Boolean> config = new ArrayList<>(4);
+        try {
+            config = m.getConfiguration();
+        } catch (IOException e) {
+            throw new Error.IOError("Configuration storage error: " + e.getMessage());
+        } catch (NotMasterDeviceException e) {
+            throw new Error.UserError("This command doesn't work on linked devices.");
+        }
+        return config;
+    }
+
     private static void checkSendMessageResult(long timestamp, SendMessageResult result) throws DBusExecutionException {
         var error = ErrorUtils.getErrorMessageFromSendMessageResult(result);