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
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
13 import java
.io
.IOException
;
15 public class UpdateContactCommand
implements LocalCommand
{
18 public void attachToSubparser(final Subparser subparser
) {
19 subparser
.help("Update the details of a given contact");
20 subparser
.addArgument("number").help("Contact number");
21 subparser
.addArgument("-n", "--name").required(true).help("New contact name");
22 subparser
.addArgument("-e", "--expiration")
25 .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");
31 var name
= ns
.getString("name");
34 var expiration
= ns
.getInt("expiration");
35 if (expiration
!= null) {
36 m
.setExpirationTimer(number
, expiration
);
39 m
.setContactName(number
, name
);
40 } catch (InvalidNumberException e
) {
41 throw new UserErrorException("Invalid contact number: " + e
.getMessage());
42 } catch (IOException e
) {
43 throw new IOErrorException("Update contact error: " + e
.getMessage());
44 } catch (NotMasterDeviceException e
) {
45 throw new UserErrorException("This command doesn't work on linked devices.");