refactor pr review

This commit is contained in:
Matus Kosut 2020-05-16 14:55:39 +02:00
parent 97631fbe06
commit 77e48bf041
3 changed files with 17 additions and 6 deletions

View file

@ -252,6 +252,10 @@ Specify the contact phone number.
*-n*, *--name*:: *-n*, *--name*::
Specify the new name for this contact. Specify the new name for this contact.
*-e*, *--expiration*::
Set expiration time of messages (seconds).
By default expiration is set to 0, no expiration.
=== block === block
Block the given contacts or groups (no messages will be received). Block the given contacts or groups (no messages will be received).

View file

@ -18,7 +18,7 @@ public class UpdateContactCommand implements LocalCommand {
subparser.addArgument("-e", "--expiration") subparser.addArgument("-e", "--expiration")
.required(false) .required(false)
.type(int.class) .type(int.class)
.help("Specify expiration time of messages"); .help("Set expiration time of messages (seconds)");
subparser.help("Update the details of a given contact"); subparser.help("Update the details of a given contact");
} }
@ -35,9 +35,8 @@ public class UpdateContactCommand implements LocalCommand {
try { try {
m.setContactName(number, name); m.setContactName(number, name);
int expiration = 0; Integer expiration = ns.getInt("expiration");
if (ns.getInt("expiration") != null) { if (expiration != null) {
expiration = ns.getInt("expiration");
m.setExpirationTimer(number, expiration); m.setExpirationTimer(number, expiration);
} }
} catch (InvalidNumberException e) { } catch (InvalidNumberException e) {

View file

@ -810,13 +810,21 @@ public class Manager implements Signal, Closeable {
/** /**
* Change the expiration timer for a contact * Change the expiration timer for a contact
*/ */
public void setExpirationTimer(String number, int messageExpirationTimer) throws InvalidNumberException { public void setExpirationTimer(SignalServiceAddress address, int messageExpirationTimer) {
ContactInfo c = account.getContactStore().getContact(canonicalizeAndResolveSignalServiceAddress(number)); ContactInfo c = account.getContactStore().getContact(address);
c.messageExpirationTime = messageExpirationTimer; c.messageExpirationTime = messageExpirationTimer;
account.getContactStore().updateContact(c); account.getContactStore().updateContact(c);
account.save(); account.save();
} }
/**
* Change the expiration timer for a contact
*/
public void setExpirationTimer(String number, int messageExpirationTimer) throws InvalidNumberException {
SignalServiceAddress address = canonicalizeAndResolveSignalServiceAddress(number);
setExpirationTimer(address, messageExpirationTimer);
}
/** /**
* Change the expiration timer for a group * Change the expiration timer for a group
*/ */