mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 11:00:38 +00:00
parent
5cd5697aea
commit
7e7e4150e1
14 changed files with 167 additions and 7 deletions
|
@ -0,0 +1,49 @@
|
|||
package org.asamk.signal.commands;
|
||||
|
||||
import net.sourceforge.argparse4j.impl.Arguments;
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.output.OutputWriter;
|
||||
import org.asamk.signal.util.CommandUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RemoveContactCommand implements JsonRpcLocalCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "removeContact";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.help("Remove the details of a given contact");
|
||||
subparser.addArgument("recipient").help("Contact number");
|
||||
subparser.addArgument("--forget")
|
||||
.action(Arguments.storeTrue())
|
||||
.help("Delete all data associated with this contact, including identity keys and sessions.");
|
||||
}
|
||||
|
||||
@Override
|
||||
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.getSelfNumber());
|
||||
|
||||
var forget = Boolean.TRUE == ns.getBoolean("forget");
|
||||
try {
|
||||
if (forget) {
|
||||
m.deleteRecipient(recipient);
|
||||
} else {
|
||||
m.deleteContact(recipient);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IOErrorException("Remove contact error: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue