]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/UpdateContactCommand.java
Add sendTyping command
[signal-cli] / src / main / java / org / asamk / signal / commands / UpdateContactCommand.java
index c8ad613b9ba1fceecfaeed24416fa22916414b00..6192af67b1edb65c98f08a3726020585b80829c3 100644 (file)
@@ -7,6 +7,7 @@ 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.manager.NotMasterDeviceException;
 import org.whispersystems.signalservice.api.util.InvalidNumberException;
 
 import java.io.IOException;
@@ -15,13 +16,13 @@ public class UpdateContactCommand implements LocalCommand {
 
     @Override
     public void attachToSubparser(final Subparser subparser) {
+        subparser.help("Update the details of a given contact");
         subparser.addArgument("number").help("Contact number");
         subparser.addArgument("-n", "--name").required(true).help("New contact name");
         subparser.addArgument("-e", "--expiration")
                 .required(false)
                 .type(int.class)
                 .help("Set expiration time of messages (seconds)");
-        subparser.help("Update the details of a given contact");
     }
 
     @Override
@@ -30,16 +31,18 @@ public class UpdateContactCommand implements LocalCommand {
         var name = ns.getString("name");
 
         try {
-            m.setContactName(number, name);
-
             var expiration = ns.getInt("expiration");
             if (expiration != null) {
                 m.setExpirationTimer(number, expiration);
             }
+
+            m.setContactName(number, name);
         } catch (InvalidNumberException e) {
             throw new UserErrorException("Invalid contact number: " + e.getMessage());
         } catch (IOException e) {
             throw new IOErrorException("Update contact error: " + e.getMessage());
+        } catch (NotMasterDeviceException e) {
+            throw new UserErrorException("This command doesn't work on linked devices.");
         }
     }
 }