]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/UpdateConfigurationCommand.java
Configuration for Dbus and main
[signal-cli] / src / main / java / org / asamk / signal / commands / UpdateConfigurationCommand.java
index 9ca126d059c39cb9dbc943bc10f07da8e9806e9c..1588a72d896accfc1efdde7936b07f930a76e54b 100644 (file)
@@ -3,7 +3,9 @@ package org.asamk.signal.commands;
 import net.sourceforge.argparse4j.inf.Namespace;
 import net.sourceforge.argparse4j.inf.Subparser;
 
 import net.sourceforge.argparse4j.inf.Namespace;
 import net.sourceforge.argparse4j.inf.Subparser;
 
+import org.asamk.signal.JsonWriter;
 import org.asamk.signal.OutputWriter;
 import org.asamk.signal.OutputWriter;
+import org.asamk.signal.PlainTextWriter;
 import org.asamk.signal.commands.exceptions.CommandException;
 import org.asamk.signal.commands.exceptions.IOErrorException;
 import org.asamk.signal.commands.exceptions.UserErrorException;
 import org.asamk.signal.commands.exceptions.CommandException;
 import org.asamk.signal.commands.exceptions.IOErrorException;
 import org.asamk.signal.commands.exceptions.UserErrorException;
@@ -11,6 +13,9 @@ import org.asamk.signal.manager.Manager;
 import org.asamk.signal.manager.NotMasterDeviceException;
 
 import java.io.IOException;
 import org.asamk.signal.manager.NotMasterDeviceException;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 public class UpdateConfigurationCommand implements JsonRpcLocalCommand {
 
 
 public class UpdateConfigurationCommand implements JsonRpcLocalCommand {
 
@@ -40,12 +45,59 @@ public class UpdateConfigurationCommand implements JsonRpcLocalCommand {
     public void handleCommand(
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
     public void handleCommand(
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
-        final var readReceipts = ns.getBoolean("read-receipts");
-        final var unidentifiedDeliveryIndicators = ns.getBoolean("unidentified-delivery-indicators");
-        final var typingIndicators = ns.getBoolean("typing-indicators");
-        final var linkPreviews = ns.getBoolean("link-previews");
+        var readReceipts = ns.getBoolean("read-receipts");
+        var unidentifiedDeliveryIndicators = ns.getBoolean("unidentified-delivery-indicators");
+        var typingIndicators = ns.getBoolean("typing-indicators");
+        var linkPreviews = ns.getBoolean("link-previews");
+        List<Boolean> configuration = new ArrayList<>(4);
+
+        try {
+            configuration = m.getConfiguration();
+        } catch (IOException | NotMasterDeviceException e) {
+            throw new CommandException(e.getMessage());
+        }
+
+        if (readReceipts == null) {
+            try {
+                readReceipts = configuration.get(0);
+            } catch (NullPointerException e) {
+                readReceipts = true;
+            }
+        }
+        if (unidentifiedDeliveryIndicators == null) {
+            try {
+                unidentifiedDeliveryIndicators = configuration.get(1);
+            } catch (NullPointerException e) {
+                unidentifiedDeliveryIndicators = true;
+            }
+        }
+        if (typingIndicators == null) {
+            try {
+                typingIndicators = configuration.get(2);
+            } catch (NullPointerException e) {
+                typingIndicators = true;
+            }
+        }
+        if (linkPreviews == null) {
+            try {
+                linkPreviews = configuration.get(3);
+            } catch (NullPointerException e) {
+                linkPreviews = true;
+            }
+        }
         try {
             m.updateConfiguration(readReceipts, unidentifiedDeliveryIndicators, typingIndicators, linkPreviews);
         try {
             m.updateConfiguration(readReceipts, unidentifiedDeliveryIndicators, typingIndicators, linkPreviews);
+            if (outputWriter instanceof JsonWriter) {
+                final var writer = (JsonWriter) outputWriter;
+                writer.write(Map.of("readReceipts", readReceipts, "unidentifiedDeliveryIndicators", unidentifiedDeliveryIndicators, "typingIndicators", typingIndicators, "linkPreviews", linkPreviews));
+            } else {
+                final var writer = (PlainTextWriter) outputWriter;
+                writer.println("readReceipts=" + readReceipts
+                        + "\nunidentifiedDeliveryIndicators=" + unidentifiedDeliveryIndicators
+                        + "\ntypingIndicators=" + typingIndicators
+                        + "\nlinkPreviews=" + linkPreviews
+                        );
+            }
         } catch (IOException e) {
             throw new IOErrorException("UpdateAccount error: " + e.getMessage(), e);
         } catch (NotMasterDeviceException e) {
         } catch (IOException e) {
             throw new IOErrorException("UpdateAccount error: " + e.getMessage(), e);
         } catch (NotMasterDeviceException e) {