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
.OutputWriter
;
7 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
8 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
9 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
10 import org
.asamk
.signal
.manager
.Manager
;
11 import org
.asamk
.signal
.manager
.NotMasterDeviceException
;
12 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
14 import java
.io
.IOException
;
16 public class UpdateContactCommand
implements JsonRpcLocalCommand
{
18 public UpdateContactCommand(final OutputWriter outputWriter
) {
21 public static void attachToSubparser(final Subparser subparser
) {
22 subparser
.help("Update the details of a given contact");
23 subparser
.addArgument("number").help("Contact number");
24 subparser
.addArgument("-n", "--name").help("New contact name");
25 subparser
.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
29 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
30 var number
= ns
.getString("number");
33 var expiration
= ns
.getInt("expiration");
34 if (expiration
!= null) {
35 m
.setExpirationTimer(number
, expiration
);
38 var name
= ns
.getString("name");
40 m
.setContactName(number
, name
);
42 } catch (InvalidNumberException e
) {
43 throw new UserErrorException("Invalid contact number: " + e
.getMessage());
44 } catch (IOException e
) {
45 throw new IOErrorException("Update contact error: " + e
.getMessage());
46 } catch (NotMasterDeviceException e
) {
47 throw new UserErrorException("This command doesn't work on linked devices.");