]> nmode's Git Repositories - signal-cli/commitdiff
Implement configuration properties for dbus
authorJohn Freed <okgithub@johnfreed.com>
Sun, 7 Nov 2021 09:59:14 +0000 (10:59 +0100)
committerAsamK <asamk@gmx.de>
Sun, 7 Nov 2021 09:59:14 +0000 (10:59 +0100)
Closes #759

commit 169bb518bf6a43bd0bf14e1291f055017a5d5937
Author: John Freed <okgithub@johnfreed.com>
Date:   Fri Oct 15 08:53:34 2021 +0200

    remove org.asamk.signal.manager.api.Configuration

commit 27ecfee382f0f1402f452a9f5fb1079b2f9c9fc5
Author: John Freed <okgithub@johnfreed.com>
Date:   Fri Oct 15 08:40:13 2021 +0200

    add a DBus "daemon running" indicator

commit 94b3d9e2ed91b002751df0e04adba3cbc79e6bd1
Author: John Freed <okgithub@johnfreed.com>
Date:   Fri Oct 15 08:20:03 2021 +0200

    changing most DBus logger.info to logger.debug

commit 15da0601272db4b907bf94240b436667870cea87
Author: John Freed <okgithub@johnfreed.com>
Date:   Fri Oct 15 00:09:26 2021 +0200

    Configuration for Dbus and main

    Main program subcommand
    - fix logic to take into account previously unset flags
    - provide output in json and plain-text formats

    new Dbus Properties:
    - ConfigurationReadReceipts
    - ConfigurationUnidentifiedDeliveryIndicators
    - ConfigurationTypingIndicators
    - ConfigurationLinkPreviews

    removed getConfiguration and setConfiguration methods

    updated documentation

commit 09da3aae62d34de33b73dc53870090c23efe078a
Merge: 3c40b11 18ad9fb
Author: John Freed <okgithub@johnfreed.com>
Date:   Thu Oct 14 15:24:07 2021 +0200

    Merge branch master into dbus_updateConfiguration

commit 3c40b11b8a6a0619e92de6d54262966aee27fd5d
Merge: 8416d4a cadcc6c
Author: John Freed <okgithub@johnfreed.com>
Date:   Sat Oct 9 14:08:08 2021 +0200

    Merge branch master into dbus_updateConfiguration

commit 8416d4ac475af5c512d963bf79e62e933592e20a
Author: John Freed <okgithub@johnfreed.com>
Date:   Mon Oct 4 08:48:56 2021 +0200

    Dbus get/setConfiguration methods

    implement:

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

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

    Update documentation

man/signal-cli-dbus.5.adoc
src/main/java/org/asamk/Signal.java
src/main/java/org/asamk/signal/commands/DaemonCommand.java
src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java

index 1bc0b879fd201928c646d684b6d3bd8b03895488..870678e32efe43afa1338f85d123f26c9c50821e 100755 (executable)
@@ -364,6 +364,26 @@ removeDevice() -> <>::
 
 Exceptions: Failure
 
+=== Configuration properties
+The configuration's object path, which exists only for primary devices, is constructed as follows:
+"/org/asamk/Signal/" + DBusNumber + "/Configuration"
+* DBusNumber  : recipient's phone number, with underscore (_) replacing plus (+)
+
+Configurations have the following (case-sensitive) properties:
+* ReadReceipts<b>                   : should send read receipts (true/false)
+* UnidentifiedDeliveryIndicators<b> : should show unidentified delivery indicators (true/false)
+* TypingIndicators<b>               : should send/show typing indicators (true/false)
+* LinkPreviews<b>                   : should generate link previews (true/false)
+
+To get a property, use (replacing `--session` with `--system` if needed):
+`dbus-send --session --dest=org.asamk.Signal --print-reply $OBJECT_PATH org.freedesktop.DBus.Properties.Get string:org.asamk.Signal.Configuration string:$PROPERTY_NAME`
+
+To set a property, use:
+`dbus-send --session --dest=org.asamk.Signal --print-reply $OBJECT_PATH org.freedesktop.DBus.Properties.Set string:org.asamk.Signal.Configuration string:$PROPERTY_NAME variant:$PROPERTY_TYPE:$PROPERTY_VALUE`
+
+To get all properties, use:
+`dbus-send --session --dest=org.asamk.Signal --print-reply $OBJECT_PATH org.freedesktop.DBus.Properties.GetAll string:org.asamk.Signal.Configuration`
+
 === Other methods
 
 getContactName(number<s>) -> name<s>::
index f512592bf3eed0720e805d608727973a96c21c9d..4e3514f753f3ec94fd819f1f4ab037f342f5dedb 100644 (file)
@@ -458,6 +458,12 @@ public interface Signal extends DBusInterface {
         void removeDevice() throws Error.Failure;
     }
 
+    @DBusProperty(name = "ReadReceipts", type = Boolean.class)
+    @DBusProperty(name = "UnidentifiedDeliveryIndicators", type = Boolean.class)
+    @DBusProperty(name = "TypingIndicators", type = Boolean.class)
+    @DBusProperty(name = "LinkPreviews", type = Boolean.class)
+    interface Configuration extends DBusInterface, Properties {}
+
     class StructGroup extends Struct {
 
         @Position(0)
index 0b165774540546e1e5cf0427e6e44bf631b5bade..ee9368f87fb521096ed0004c2bc8aaa0b83b9f8d 100644 (file)
@@ -69,6 +69,7 @@ public class DaemonCommand implements MultiLocalCommand {
             var t = run(conn, objectPath, m, outputWriter);
 
             conn.requestBusName(DbusConfig.getBusname());
+            logger.info("DBus daemon running in single-user mode for " + m.getSelfNumber());
 
             try {
                 t.join();
@@ -114,6 +115,7 @@ public class DaemonCommand implements MultiLocalCommand {
             }
 
             conn.requestBusName(DbusConfig.getBusname());
+            logger.info("DBus daemon running in mulit-account mode");
 
             signalControl.run();
         } catch (DBusException | IOException e) {
@@ -130,7 +132,7 @@ public class DaemonCommand implements MultiLocalCommand {
         final var initThread = new Thread(signal::initObjects);
         initThread.start();
 
-        logger.info("Exported dbus object: " + objectPath);
+        logger.debug("Exported dbus object: " + objectPath);
 
         final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
                 (JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);
index 8906ac47f8674a1242a61dfa3bfba779a50bb6a7..047b4f995e5a825182fee5adfed99036e7133e8a 100644 (file)
@@ -33,6 +33,8 @@ import org.freedesktop.dbus.connections.impl.DBusConnection;
 import org.freedesktop.dbus.exceptions.DBusException;
 import org.freedesktop.dbus.exceptions.DBusExecutionException;
 import org.freedesktop.dbus.types.Variant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.IOException;
@@ -62,6 +64,8 @@ public class DbusSignalImpl implements Signal {
     private final List<StructDevice> devices = new ArrayList<>();
     private final List<StructGroup> groups = new ArrayList<>();
 
+    private final static Logger logger = LoggerFactory.getLogger(DbusSignalImpl.class);
+
     public DbusSignalImpl(final Manager m, DBusConnection connection, final String objectPath) {
         this.m = m;
         this.connection = connection;
@@ -71,11 +75,13 @@ public class DbusSignalImpl implements Signal {
     public void initObjects() {
         updateDevices();
         updateGroups();
+        updateConfiguration();
     }
 
     public void close() {
         unExportDevices();
         unExportGroups();
+        unExportConfiguration();
     }
 
     @Override
@@ -835,6 +841,7 @@ public class DbusSignalImpl implements Signal {
             final var deviceObjectPath = object.getObjectPath();
             try {
                 connection.exportObject(object);
+                logger.debug("Exported dbus object: " + deviceObjectPath);
             } catch (DBusException e) {
                 e.printStackTrace();
             }
@@ -871,6 +878,7 @@ public class DbusSignalImpl implements Signal {
             final var object = new DbusSignalGroupImpl(g.groupId());
             try {
                 connection.exportObject(object);
+                logger.debug("Exported dbus object: " + object.getObjectPath());
             } catch (DBusException e) {
                 e.printStackTrace();
             }
@@ -885,6 +893,26 @@ public class DbusSignalImpl implements Signal {
         this.groups.clear();
     }
 
+    private static String getConfigurationObjectPath(String basePath) {
+        return basePath + "/Configuration";
+    }
+
+    private void updateConfiguration() {
+        try {
+            unExportConfiguration();
+            final var object = new DbusSignalConfigurationImpl();
+            connection.exportObject(object);
+            logger.debug("Exported dbus object: " + objectPath + "/Configuration");
+        } catch (DBusException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void unExportConfiguration() {
+        final var objectPath = getConfigurationObjectPath(this.objectPath);
+        connection.unExportObject(objectPath);
+    }
+
     public class DbusSignalDeviceImpl extends DbusProperties implements Signal.Device {
 
         private final org.asamk.signal.manager.api.Device device;
@@ -927,6 +955,78 @@ public class DbusSignalImpl implements Signal {
         }
     }
 
+    public class DbusSignalConfigurationImpl extends DbusProperties implements Signal.Configuration {
+
+        public DbusSignalConfigurationImpl(
+        ) {
+            super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
+                    List.of(new DbusProperty<>("ReadReceipts", this::getReadReceipts, this::setReadReceipts),
+                            new DbusProperty<>("UnidentifiedDeliveryIndicators",
+                                    this::getUnidentifiedDeliveryIndicators,
+                                    this::setUnidentifiedDeliveryIndicators),
+                            new DbusProperty<>("TypingIndicators",
+                                    this::getTypingIndicators,
+                                    this::setTypingIndicators),
+                            new DbusProperty<>("LinkPreviews", this::getLinkPreviews, this::setLinkPreviews))));
+
+        }
+
+        @Override
+        public String getObjectPath() {
+            return getConfigurationObjectPath(objectPath);
+        }
+
+        public void setReadReceipts(Boolean readReceipts) {
+            setConfiguration(readReceipts, null, null, null);
+        }
+
+        public void setUnidentifiedDeliveryIndicators(Boolean unidentifiedDeliveryIndicators) {
+            setConfiguration(null, unidentifiedDeliveryIndicators, null, null);
+        }
+
+        public void setTypingIndicators(Boolean typingIndicators) {
+            setConfiguration(null, null, typingIndicators, null);
+        }
+
+        public void setLinkPreviews(Boolean linkPreviews) {
+            setConfiguration(null, null, null, linkPreviews);
+        }
+
+        private void setConfiguration(
+                Boolean readReceipts,
+                Boolean unidentifiedDeliveryIndicators,
+                Boolean typingIndicators,
+                Boolean linkPreviews
+        ) {
+            try {
+                m.updateConfiguration(new org.asamk.signal.manager.api.Configuration(Optional.ofNullable(readReceipts),
+                        Optional.ofNullable(unidentifiedDeliveryIndicators),
+                        Optional.ofNullable(typingIndicators),
+                        Optional.ofNullable(linkPreviews)));
+            } catch (IOException e) {
+                throw new Error.Failure("UpdateAccount error: " + e.getMessage());
+            } catch (NotMasterDeviceException e) {
+                throw new Error.Failure("This command doesn't work on linked devices.");
+            }
+        }
+
+        private boolean getReadReceipts() {
+            return m.getConfiguration().readReceipts().orElse(false);
+        }
+
+        private boolean getUnidentifiedDeliveryIndicators() {
+            return m.getConfiguration().unidentifiedDeliveryIndicators().orElse(false);
+        }
+
+        private boolean getTypingIndicators() {
+            return m.getConfiguration().typingIndicators().orElse(false);
+        }
+
+        private boolean getLinkPreviews() {
+            return m.getConfiguration().linkPreviews().orElse(false);
+        }
+    }
+
     public class DbusSignalGroupImpl extends DbusProperties implements Signal.Group {
 
         private final GroupId groupId;