]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/commands/UpdateContactCommand.java
da090209c47f5090de8e95f001a11ebb2289dba2
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
.manager
.Manager
;
7 import org
.whispersystems
.signalservice
.api
.util
.InvalidNumberException
;
9 import java
.io
.IOException
;
11 public class UpdateContactCommand
implements LocalCommand
{
14 public void attachToSubparser(final Subparser subparser
) {
15 subparser
.addArgument("number").help("Contact number");
16 subparser
.addArgument("-n", "--name").required(true).help("New contact name");
17 subparser
.addArgument("-e", "--expiration")
20 .help("Set expiration time of messages (seconds)");
21 subparser
.help("Update the details of a given contact");
25 public int handleCommand(final Namespace ns
, final Manager m
) {
26 if (!m
.isRegistered()) {
27 System
.err
.println("User is not registered.");
31 String number
= ns
.getString("number");
32 String name
= ns
.getString("name");
35 m
.setContactName(number
, name
);
37 Integer expiration
= ns
.getInt("expiration");
38 if (expiration
!= null) {
39 m
.setExpirationTimer(number
, expiration
);
41 } catch (InvalidNumberException e
) {
42 System
.err
.println("Invalid contact number: " + e
.getMessage());
44 } catch (IOException e
) {
45 System
.err
.println("Update contact error: " + e
.getMessage());