]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/DaemonCommand.java
Refactor register and verify
[signal-cli] / src / main / java / org / asamk / signal / commands / DaemonCommand.java
index 9b6c0d63b331a66ee766d27ffd7684c4f0e7510d..c5ee2edce8304a8975432437c38186d3eda531c1 100644 (file)
@@ -3,10 +3,12 @@ package org.asamk.signal.commands;
 import net.sourceforge.argparse4j.impl.Arguments;
 import net.sourceforge.argparse4j.inf.Namespace;
 import net.sourceforge.argparse4j.inf.Subparser;
+
 import org.asamk.signal.DbusReceiveMessageHandler;
 import org.asamk.signal.JsonDbusReceiveMessageHandler;
+import org.asamk.signal.dbus.DbusSignalImpl;
 import org.asamk.signal.manager.Manager;
-import org.freedesktop.dbus.DBusConnection;
+import org.freedesktop.dbus.connections.impl.DBusConnection;
 import org.freedesktop.dbus.exceptions.DBusException;
 
 import java.io.IOException;
@@ -33,21 +35,17 @@ public class DaemonCommand implements LocalCommand {
 
     @Override
     public int handleCommand(final Namespace ns, final Manager m) {
-        if (!m.isRegistered()) {
-            System.err.println("User is not registered.");
-            return 1;
-        }
         DBusConnection conn = null;
         try {
             try {
-                int busType;
+                DBusConnection.DBusBusType busType;
                 if (ns.getBoolean("system")) {
-                    busType = DBusConnection.SYSTEM;
+                    busType = DBusConnection.DBusBusType.SYSTEM;
                 } else {
-                    busType = DBusConnection.SESSION;
+                    busType = DBusConnection.DBusBusType.SESSION;
                 }
                 conn = DBusConnection.getConnection(busType);
-                conn.exportObject(SIGNAL_OBJECTPATH, m);
+                conn.exportObject(SIGNAL_OBJECTPATH, new DbusSignalImpl(m));
                 conn.requestBusName(SIGNAL_BUSNAME);
             } catch (UnsatisfiedLinkError e) {
                 System.err.println("Missing native library dependency for dbus service: " + e.getMessage());
@@ -58,7 +56,13 @@ public class DaemonCommand implements LocalCommand {
             }
             boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
             try {
-                m.receiveMessages(1, TimeUnit.HOURS, false, ignoreAttachments, ns.getBoolean("json") ? new JsonDbusReceiveMessageHandler(m, conn, SIGNAL_OBJECTPATH) : new DbusReceiveMessageHandler(m, conn, SIGNAL_OBJECTPATH));
+                m.receiveMessages(1,
+                        TimeUnit.HOURS,
+                        false,
+                        ignoreAttachments,
+                        ns.getBoolean("json")
+                                ? new JsonDbusReceiveMessageHandler(m, conn, SIGNAL_OBJECTPATH)
+                                : new DbusReceiveMessageHandler(m, conn, SIGNAL_OBJECTPATH));
                 return 0;
             } catch (IOException e) {
                 System.err.println("Error while receiving messages: " + e.getMessage());