]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/commands/UpdateContactCommand.java
ae84893d9c542a7e1552a67ffd152b939084c63d
1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
4 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
6 import java
.io
.IOException
;
8 import org
.asamk
.signal
.manager
.Manager
;
9 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
11 public class UpdateContactCommand
implements LocalCommand
{
14 public void attachToSubparser(final Subparser subparser
) {
15 subparser
.addArgument("number")
16 .help("Contact number");
17 subparser
.addArgument("-n", "--name")
19 .help("New contact name");
20 subparser
.addArgument("-e", "--expiration")
23 .help("Set expiration time of messages (seconds)");
24 subparser
.help("Update the details of a given contact");
28 public int handleCommand(final Namespace ns
, final Manager m
) {
29 if (!m
.isRegistered()) {
30 System
.err
.println("User is not registered.");
34 String number
= ns
.getString("number");
35 String name
= ns
.getString("name");
38 m
.setContactName(number
, name
);
40 Integer expiration
= ns
.getInt("expiration");
41 if (expiration
!= null) {
42 m
.setExpirationTimer(number
, expiration
);
44 } catch (InvalidNumberException e
) {
45 System
.out
.println("Invalid contact number: " + e
.getMessage());
46 } catch (IOException e
) {
47 System
.err
.println("Update contact error: " + e
.getMessage());