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
.api
.NotPrimaryDeviceException
;
11 import org
.asamk
.signal
.manager
.api
.UnregisteredRecipientException
;
12 import org
.asamk
.signal
.output
.OutputWriter
;
13 import org
.asamk
.signal
.util
.CommandUtil
;
15 import java
.io
.IOException
;
17 public class UpdateContactCommand
implements JsonRpcLocalCommand
{
20 public String
getName() {
21 return "updateContact";
25 public void attachToSubparser(final Subparser subparser
) {
26 subparser
.help("Update the details of a given contact");
27 subparser
.addArgument("recipient").help("Contact number");
28 subparser
.addArgument("-n", "--name").help("New contact name");
29 subparser
.addArgument("--given-name").help("New contact given name");
30 subparser
.addArgument("--family-name").help("New contact family name");
31 subparser
.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
35 public void handleCommand(
36 final Namespace ns
, final Manager m
, final OutputWriter outputWriter
37 ) throws CommandException
{
38 var recipientString
= ns
.getString("recipient");
39 var recipient
= CommandUtil
.getSingleRecipientIdentifier(recipientString
, m
.getSelfNumber());
42 var expiration
= ns
.getInt("expiration");
43 if (expiration
!= null) {
44 m
.setExpirationTimer(recipient
, expiration
);
47 var givenName
= ns
.getString("given-name");
48 var familyName
= ns
.getString("family-name");
49 if (givenName
== null) {
50 givenName
= ns
.getString("name");
51 if (givenName
!= null && familyName
== null) {
55 if (givenName
!= null || familyName
!= null) {
56 m
.setContactName(recipient
, givenName
, familyName
);
58 } catch (IOException e
) {
59 throw new IOErrorException("Update contact error: " + e
.getMessage(), e
);
60 } catch (NotPrimaryDeviceException e
) {
61 throw new UserErrorException("This command doesn't work on linked devices.");
62 } catch (UnregisteredRecipientException e
) {
63 throw new UserErrorException("The user " + e
.getSender().getIdentifier() + " is not registered.");