Add removeContact command

Closes #335
This commit is contained in:
AsamK 2021-11-26 20:50:54 +01:00
parent 5cd5697aea
commit 7e7e4150e1
14 changed files with 167 additions and 7 deletions

View file

@ -26,6 +26,7 @@ public class Commands {
addCommand(new QuitGroupCommand());
addCommand(new ReceiveCommand());
addCommand(new RegisterCommand());
addCommand(new RemoveContactCommand());
addCommand(new RemoveDeviceCommand());
addCommand(new RemoteDeleteCommand());
addCommand(new RemovePinCommand());

View file

@ -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);
}
}
}

View file

@ -381,6 +381,16 @@ public class DbusManagerImpl implements Manager {
return new SendMessageResults(0, Map.of());
}
@Override
public void deleteRecipient(final RecipientIdentifier.Single recipient) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public void deleteContact(final RecipientIdentifier.Single recipient) throws IOException {
throw new UnsupportedOperationException();
}
@Override
public void setContactName(
final RecipientIdentifier.Single recipient, final String name