Contact config - message expiration time (#308)

Co-authored-by: Matus Kosut <matus.kosut@ntnu.no>
This commit is contained in:
Matúš Košút 2020-05-16 22:55:53 +02:00 committed by GitHub
parent 1e0aa8929d
commit b382a4260b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 4 deletions

View file

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

View file

@ -3,6 +3,8 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import java.io.IOException;
import org.asamk.signal.manager.Manager;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
@ -15,6 +17,10 @@ public class UpdateContactCommand implements LocalCommand {
subparser.addArgument("-n", "--name")
.required(true)
.help("New contact name");
subparser.addArgument("-e", "--expiration")
.required(false)
.type(int.class)
.help("Set expiration time of messages (seconds)");
subparser.help("Update the details of a given contact");
}
@ -30,8 +36,16 @@ public class UpdateContactCommand implements LocalCommand {
try {
m.setContactName(number, name);
Integer expiration = ns.getInt("expiration");
if (expiration != null) {
m.setExpirationTimer(number, expiration);
}
} catch (InvalidNumberException e) {
System.out.println("Invalid contact number: " + e.getMessage());
} catch (IOException e) {
System.err.println("Update contact error: " + e.getMessage());
return 3;
}
return 0;

View file

@ -758,10 +758,23 @@ public class Manager implements Closeable {
/**
* Change the expiration timer for a contact
*/
public void setExpirationTimer(SignalServiceAddress address, int messageExpirationTimer) {
ContactInfo c = account.getContactStore().getContact(address);
c.messageExpirationTime = messageExpirationTimer;
account.getContactStore().updateContact(c);
public void setExpirationTimer(SignalServiceAddress address, int messageExpirationTimer) throws IOException {
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder();
ContactInfo contact = account.getContactStore().getContact(address);
contact.messageExpirationTime = messageExpirationTimer;
account.getContactStore().updateContact(contact);
account.save();
messageBuilder.withExpiration(messageExpirationTimer);
messageBuilder.asExpirationUpdate();
sendMessage(messageBuilder, Collections.singleton(address));
}
/**
* Change the expiration timer for a contact
*/
public void setExpirationTimer(String number, int messageExpirationTimer) throws IOException, InvalidNumberException {
SignalServiceAddress address = canonicalizeAndResolveSignalServiceAddress(number);
setExpirationTimer(address, messageExpirationTimer);
}
/**