1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
6 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
7 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
8 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
9 import org
.asamk
.signal
.manager
.Manager
;
10 import org
.asamk
.signal
.manager
.NotMasterDeviceException
;
11 import org
.asamk
.signal
.output
.OutputWriter
;
12 import org
.asamk
.signal
.util
.CommandUtil
;
14 import java
.io
.IOException
;
16 public class UpdateContactCommand
implements JsonRpcLocalCommand
{
19 public String
getName() {
20 return "updateContact";
24 public void attachToSubparser(final Subparser subparser
) {
25 subparser
.help("Update the details of a given contact");
26 subparser
.addArgument("recipient").help("Contact number");
27 subparser
.addArgument("-n", "--name").help("New contact name");
28 subparser
.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
32 public void handleCommand(
33 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
34 ) throws CommandException
{
35 var recipientString
= ns
.getString("recipient");
36 var recipient
= CommandUtil
.getSingleRecipientIdentifier(recipientString
, m
.getSelfNumber());
39 var expiration
= ns
.getInt("expiration");
40 if (expiration
!= null) {
41 m
.setExpirationTimer(recipient
, expiration
);
44 var name
= ns
.getString("name");
46 m
.setContactName(recipient
, name
);
48 } catch (IOException e
) {
49 throw new IOErrorException("Update contact error: " + e
.getMessage(), e
);
50 } catch (NotMasterDeviceException e
) {
51 throw new UserErrorException("This command doesn't work on linked devices.");