]> nmode's Git Repositories - signal-cli/commitdiff
Add exportObject helper method
authorAsamK <asamk@gmx.de>
Sun, 7 Nov 2021 10:04:41 +0000 (11:04 +0100)
committerAsamK <asamk@gmx.de>
Sun, 7 Nov 2021 10:04:41 +0000 (11:04 +0100)
lib/src/main/java/org/asamk/signal/manager/helper/StorageHelper.java
src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java

index b68e65b481f62e29d7ebae24c63d09fff240ec89..7c7b34cca24c29395739d996447966ed8d94ce61 100644 (file)
@@ -97,7 +97,7 @@ public class StorageHelper {
                 (contact == null || !contact.isBlocked()) && contactRecord.isBlocked()
         )) {
             final var newContact = (contact == null ? Contact.newBuilder() : Contact.newBuilder(contact)).withBlocked(
-                    contactRecord.isBlocked())
+                            contactRecord.isBlocked())
                     .withName((contactRecord.getGivenName().or("") + " " + contactRecord.getFamilyName().or("")).trim())
                     .build();
             account.getContactStore().storeContact(recipientId, newContact);
index 047b4f995e5a825182fee5adfed99036e7133e8a..9f6f1340766d4a51c8209d56eb12b04b32cc57f7 100644 (file)
@@ -32,6 +32,7 @@ import org.freedesktop.dbus.DBusPath;
 import org.freedesktop.dbus.connections.impl.DBusConnection;
 import org.freedesktop.dbus.exceptions.DBusException;
 import org.freedesktop.dbus.exceptions.DBusExecutionException;
+import org.freedesktop.dbus.interfaces.DBusInterface;
 import org.freedesktop.dbus.types.Variant;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -839,12 +840,7 @@ public class DbusSignalImpl implements Signal {
         linkedDevices.forEach(d -> {
             final var object = new DbusSignalDeviceImpl(d);
             final var deviceObjectPath = object.getObjectPath();
-            try {
-                connection.exportObject(object);
-                logger.debug("Exported dbus object: " + deviceObjectPath);
-            } catch (DBusException e) {
-                e.printStackTrace();
-            }
+            exportObject(object);
             if (d.isThisDevice()) {
                 thisDevice = new DBusPath(deviceObjectPath);
             }
@@ -876,12 +872,7 @@ public class DbusSignalImpl implements Signal {
 
         groups.forEach(g -> {
             final var object = new DbusSignalGroupImpl(g.groupId());
-            try {
-                connection.exportObject(object);
-                logger.debug("Exported dbus object: " + object.getObjectPath());
-            } catch (DBusException e) {
-                e.printStackTrace();
-            }
+            exportObject(object);
             this.groups.add(new StructGroup(new DBusPath(object.getObjectPath()),
                     g.groupId().serialize(),
                     emptyIfNull(g.title())));
@@ -898,14 +889,9 @@ public class DbusSignalImpl implements Signal {
     }
 
     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();
-        }
+        unExportConfiguration();
+        final var object = new DbusSignalConfigurationImpl();
+        exportObject(object);
     }
 
     private void unExportConfiguration() {
@@ -913,6 +899,15 @@ public class DbusSignalImpl implements Signal {
         connection.unExportObject(objectPath);
     }
 
+    private void exportObject(final DBusInterface object) {
+        try {
+            connection.exportObject(object);
+            logger.debug("Exported dbus object: " + object.getObjectPath());
+        } catch (DBusException e) {
+            e.printStackTrace();
+        }
+    }
+
     public class DbusSignalDeviceImpl extends DbusProperties implements Signal.Device {
 
         private final org.asamk.signal.manager.api.Device device;