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").help("New contact name");
22 subparser
.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
26 public void handleCommand(final Namespace ns
, final Manager m
) throws CommandException
{
27 var number
= ns
.getString("number");
30 var expiration
= ns
.getInt("expiration");
31 if (expiration
!= null) {
32 m
.setExpirationTimer(number
, expiration
);
35 var name
= ns
.getString("name");
37 m
.setContactName(number
, name
);
39 } catch (InvalidNumberException e
) {
40 throw new UserErrorException("Invalid contact number: " + e
.getMessage());
41 } catch (IOException e
) {
42 throw new IOErrorException("Update contact error: " + e
.getMessage());
43 } catch (NotMasterDeviceException e
) {
44 throw new UserErrorException("This command doesn't work on linked devices.");