]> nmode's Git Repositories - signal-cli/commitdiff
Merge branch master into dbus_updateConfiguration
authorJohn Freed <okgithub@johnfreed.com>
Thu, 14 Oct 2021 13:24:07 +0000 (15:24 +0200)
committerJohn Freed <okgithub@johnfreed.com>
Thu, 14 Oct 2021 13:24:07 +0000 (15:24 +0200)
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 733e3dccc285fe831e966e03c646ef5c207fa1c2..93afd9a691d59ca2970fde2b021bd37c434d5fde 100644 (file)
@@ -103,6 +103,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 d2ffaaabe577d8c6d2a7bf749a24fe70712ce457..a4121e29279e44e5befe13dd47e577647d34126e 100644 (file)
@@ -344,6 +344,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 550585805d35d6bd4025d101c99eee7d97828d0b..1a0fbfaaa76cd495b8d8628413b38b63aae80963 100755 (executable)
@@ -529,7 +529,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
 
-Exceptions: 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
 
 version() -> version<s>::
 * version : Version string of signal-cli
index 349671b37bffb05e9fa058862046adb8b2afd6af..28c192a09557281bac20361cd4b9058c14925fe3 100644 (file)
@@ -160,6 +160,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();
+
     void submitRateLimitChallenge(String challenge, String captchaString) throws IOErrorException;
 
     class MessageReceived extends DBusSignal {
@@ -447,5 +451,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 59422e6922354ad01b454e2976dcbbb00ea6f11c..a8f071f7a6723c4510944a12b4490c1ab305cc62 100644 (file)
@@ -107,7 +107,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 2cf3c813ff8adaa6965004998667001f1abd6fd9..c6e3273ae4bfdad834908ede0837dd6df4883498 100644 (file)
@@ -696,12 +696,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);