]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/App.java
Refactor ReceiveCommand in dbus mode and remove ExtendedDbusCommand
[signal-cli] / src / main / java / org / asamk / signal / App.java
index bffbded51128d28893e57bb41c308ceb5b107a74..720a58499e9c12accc64ee329781704b3c865749 100644 (file)
@@ -8,7 +8,6 @@ import net.sourceforge.argparse4j.inf.Namespace;
 import org.asamk.Signal;
 import org.asamk.signal.commands.Command;
 import org.asamk.signal.commands.Commands;
-import org.asamk.signal.commands.ExtendedDbusCommand;
 import org.asamk.signal.commands.LocalCommand;
 import org.asamk.signal.commands.MultiLocalCommand;
 import org.asamk.signal.commands.ProvisioningCommand;
@@ -32,7 +31,6 @@ import org.freedesktop.dbus.exceptions.DBusException;
 import org.freedesktop.dbus.exceptions.DBusExecutionException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.whispersystems.signalservice.api.util.PhoneNumberFormatter;
 
 import java.io.File;
 import java.io.IOException;
@@ -117,8 +115,8 @@ public class App {
 
         var username = ns.getString("username");
 
-        final var useDbus = ns.getBoolean("dbus");
-        final var useDbusSystem = ns.getBoolean("dbus-system");
+        final var useDbus = Boolean.TRUE.equals(ns.getBoolean("dbus"));
+        final var useDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system"));
         if (useDbus || useDbusSystem) {
             // If username is null, it will connect to the default object path
             initDbusClient(command, username, useDbusSystem, outputWriter);
@@ -133,7 +131,7 @@ public class App {
             dataPath = getDefaultDataPath();
         }
 
-        if (!ServiceConfig.getCapabilities().isGv2()) {
+        if (!ServiceConfig.isZkgroupAvailable()) {
             logger.warn("WARNING: Support for new group V2 is disabled,"
                     + " because the required native library dependency is missing: libzkgroup");
         }
@@ -152,20 +150,20 @@ public class App {
                 ? TrustNewIdentity.ON_FIRST_USE
                 : trustNewIdentityCli == TrustNewIdentityCli.ALWAYS ? TrustNewIdentity.ALWAYS : TrustNewIdentity.NEVER;
 
-        if (command instanceof ProvisioningCommand) {
+        if (command instanceof ProvisioningCommand provisioningCommand) {
             if (username != null) {
                 throw new UserErrorException("You cannot specify a username (phone number) when linking");
             }
 
-            handleProvisioningCommand((ProvisioningCommand) command, dataPath, serviceEnvironment, outputWriter);
+            handleProvisioningCommand(provisioningCommand, dataPath, serviceEnvironment, outputWriter);
             return;
         }
 
         if (username == null) {
             var usernames = Manager.getAllLocalNumbers(dataPath);
 
-            if (command instanceof MultiLocalCommand) {
-                handleMultiLocalCommand((MultiLocalCommand) command,
+            if (command instanceof MultiLocalCommand multiLocalCommand) {
+                handleMultiLocalCommand(multiLocalCommand,
                         dataPath,
                         serviceEnvironment,
                         usernames,
@@ -182,12 +180,12 @@ public class App {
             }
 
             username = usernames.get(0);
-        } else if (!PhoneNumberFormatter.isValidNumber(username, null)) {
+        } else if (!Manager.isValidNumber(username, null)) {
             throw new UserErrorException("Invalid username (phone number), make sure you include the country code.");
         }
 
-        if (command instanceof RegistrationCommand) {
-            handleRegistrationCommand((RegistrationCommand) command, username, dataPath, serviceEnvironment);
+        if (command instanceof RegistrationCommand registrationCommand) {
+            handleRegistrationCommand(registrationCommand, username, dataPath, serviceEnvironment);
             return;
         }
 
@@ -345,11 +343,9 @@ public class App {
     private void handleCommand(
             Command command, Signal ts, DBusConnection dBusConn, OutputWriter outputWriter
     ) throws CommandException {
-        if (command instanceof ExtendedDbusCommand) {
-            ((ExtendedDbusCommand) command).handleCommand(ns, ts, dBusConn, outputWriter);
-        } else if (command instanceof LocalCommand) {
+        if (command instanceof LocalCommand localCommand) {
             try {
-                ((LocalCommand) command).handleCommand(ns, new DbusManagerImpl(ts), outputWriter);
+                localCommand.handleCommand(ns, new DbusManagerImpl(ts, dBusConn), outputWriter);
             } catch (UnsupportedOperationException e) {
                 throw new UserErrorException("Command is not yet implemented via dbus", e);
             } catch (DBusExecutionException e) {