mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Contact config - message expiration time (#308)
Co-authored-by: Matus Kosut <matus.kosut@ntnu.no>
This commit is contained in:
parent
1e0aa8929d
commit
b382a4260b
3 changed files with 35 additions and 4 deletions
|
@ -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).
|
||||||
|
To disable expiration set expiration time to 0.
|
||||||
|
|
||||||
=== block
|
=== block
|
||||||
|
|
||||||
Block the given contacts or groups (no messages will be received).
|
Block the given contacts or groups (no messages will be received).
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.asamk.signal.commands;
|
||||||
import net.sourceforge.argparse4j.inf.Namespace;
|
import net.sourceforge.argparse4j.inf.Namespace;
|
||||||
import net.sourceforge.argparse4j.inf.Subparser;
|
import net.sourceforge.argparse4j.inf.Subparser;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.asamk.signal.manager.Manager;
|
import org.asamk.signal.manager.Manager;
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
|
||||||
|
@ -15,6 +17,10 @@ public class UpdateContactCommand implements LocalCommand {
|
||||||
subparser.addArgument("-n", "--name")
|
subparser.addArgument("-n", "--name")
|
||||||
.required(true)
|
.required(true)
|
||||||
.help("New contact name");
|
.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");
|
subparser.help("Update the details of a given contact");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +36,16 @@ public class UpdateContactCommand implements LocalCommand {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m.setContactName(number, name);
|
m.setContactName(number, name);
|
||||||
|
|
||||||
|
Integer expiration = ns.getInt("expiration");
|
||||||
|
if (expiration != null) {
|
||||||
|
m.setExpirationTimer(number, expiration);
|
||||||
|
}
|
||||||
} catch (InvalidNumberException e) {
|
} catch (InvalidNumberException e) {
|
||||||
System.out.println("Invalid contact number: " + e.getMessage());
|
System.out.println("Invalid contact number: " + e.getMessage());
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Update contact error: " + e.getMessage());
|
||||||
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -758,10 +758,23 @@ public class Manager implements Closeable {
|
||||||
/**
|
/**
|
||||||
* Change the expiration timer for a contact
|
* Change the expiration timer for a contact
|
||||||
*/
|
*/
|
||||||
public void setExpirationTimer(SignalServiceAddress address, int messageExpirationTimer) {
|
public void setExpirationTimer(SignalServiceAddress address, int messageExpirationTimer) throws IOException {
|
||||||
ContactInfo c = account.getContactStore().getContact(address);
|
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder();
|
||||||
c.messageExpirationTime = messageExpirationTimer;
|
ContactInfo contact = account.getContactStore().getContact(address);
|
||||||
account.getContactStore().updateContact(c);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue