]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/UpdateContactCommand.java
Extract dbus client command handling
[signal-cli] / src / main / java / org / asamk / signal / commands / UpdateContactCommand.java
index b138b4391a25d5da3d8fed3eb1de88167e2a28c7..7ff91e9be25e1f5e1a43ddc3b4d2b37513ecebdd 100644 (file)
@@ -7,7 +7,8 @@ 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.manager.Manager;
 import org.asamk.signal.commands.exceptions.IOErrorException;
 import org.asamk.signal.commands.exceptions.UserErrorException;
 import org.asamk.signal.manager.Manager;
-import org.asamk.signal.manager.NotMasterDeviceException;
+import org.asamk.signal.manager.api.NotPrimaryDeviceException;
+import org.asamk.signal.manager.api.UnregisteredRecipientException;
 import org.asamk.signal.output.OutputWriter;
 import org.asamk.signal.util.CommandUtil;
 
 import org.asamk.signal.output.OutputWriter;
 import org.asamk.signal.util.CommandUtil;
 
@@ -25,6 +26,8 @@ public class UpdateContactCommand implements JsonRpcLocalCommand {
         subparser.help("Update the details of a given contact");
         subparser.addArgument("recipient").help("Contact number");
         subparser.addArgument("-n", "--name").help("New contact name");
         subparser.help("Update the details of a given contact");
         subparser.addArgument("recipient").help("Contact number");
         subparser.addArgument("-n", "--name").help("New contact name");
+        subparser.addArgument("--given-name").help("New contact given name");
+        subparser.addArgument("--family-name").help("New contact family name");
         subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
     }
 
         subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
     }
 
@@ -41,14 +44,23 @@ public class UpdateContactCommand implements JsonRpcLocalCommand {
                 m.setExpirationTimer(recipient, expiration);
             }
 
                 m.setExpirationTimer(recipient, expiration);
             }
 
-            var name = ns.getString("name");
-            if (name != null) {
-                m.setContactName(recipient, name);
+            var givenName = ns.getString("given-name");
+            var familyName = ns.getString("family-name");
+            if (givenName == null) {
+                givenName = ns.getString("name");
+                if (givenName != null && familyName == null) {
+                    familyName = "";
+                }
+            }
+            if (givenName != null || familyName != null) {
+                m.setContactName(recipient, givenName, familyName);
             }
         } catch (IOException e) {
             throw new IOErrorException("Update contact error: " + e.getMessage(), e);
             }
         } catch (IOException e) {
             throw new IOErrorException("Update contact error: " + e.getMessage(), e);
-        } catch (NotMasterDeviceException e) {
+        } catch (NotPrimaryDeviceException e) {
             throw new UserErrorException("This command doesn't work on linked devices.");
             throw new UserErrorException("This command doesn't work on linked devices.");
+        } catch (UnregisteredRecipientException e) {
+            throw new UserErrorException("The user " + e.getSender().getIdentifier() + " is not registered.");
         }
     }
 }
         }
     }
 }