- public int handleCommand(final Namespace ns, final Manager m) {
- if (!m.isRegistered()) {
- System.err.println("User is not registered.");
- return 1;
+ public void handleCommand(
+ final Namespace ns, final Manager m, final OutputWriter outputWriter
+ ) throws CommandException {
+ var recipientString = ns.getString("recipient");
+ var recipient = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getUsername());
+
+ try {
+ var expiration = ns.getInt("expiration");
+ if (expiration != null) {
+ m.setExpirationTimer(recipient, expiration);
+ }
+
+ var name = ns.getString("name");
+ if (name != null) {
+ m.setContactName(recipient, name);
+ }
+ } catch (IOException e) {
+ throw new IOErrorException("Update contact error: " + e.getMessage(), e);
+ } catch (NotMasterDeviceException e) {
+ throw new UserErrorException("This command doesn't work on linked devices.");