mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
parent
55dde93811
commit
22add1cbee
13 changed files with 170 additions and 9 deletions
|
@ -13,6 +13,7 @@ public class Commands {
|
|||
addCommand(new AddDeviceCommand());
|
||||
addCommand(new BlockCommand());
|
||||
addCommand(new DaemonCommand());
|
||||
addCommand(new DeleteLocalAccountDataCommand());
|
||||
addCommand(new FinishLinkCommand());
|
||||
addCommand(new GetUserStatusCommand());
|
||||
addCommand(new JoinGroupCommand());
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package org.asamk.signal.commands;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import net.sourceforge.argparse4j.impl.Arguments;
|
||||
import net.sourceforge.argparse4j.inf.Namespace;
|
||||
import net.sourceforge.argparse4j.inf.Subparser;
|
||||
|
||||
import org.asamk.signal.OutputType;
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.manager.RegistrationManager;
|
||||
import org.asamk.signal.output.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DeleteLocalAccountDataCommand implements RegistrationCommand, JsonRpcRegistrationCommand<Map<String, Object>> {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "deleteLocalAccountData";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachToSubparser(final Subparser subparser) {
|
||||
subparser.help(
|
||||
"Delete all local data for this account. Data should only be deleted if the account is unregistered. CAUTION: This cannot be undone.");
|
||||
subparser.addArgument("--ignore-registered")
|
||||
.help("Delete the account data even though the account is still registered on the Signal servers.")
|
||||
.action(Arguments.storeTrue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(final Namespace ns, final RegistrationManager m) throws CommandException {
|
||||
try {
|
||||
final var ignoreRegistered = Boolean.TRUE.equals(ns.getBoolean("ignore-registered"));
|
||||
if (m.isRegistered() && !ignoreRegistered) {
|
||||
throw new UserErrorException(
|
||||
"Not deleting account, it is still registered. Use --ignore-registered to delete it anyway.");
|
||||
}
|
||||
|
||||
m.deleteLocalAccountData();
|
||||
} catch (IOException e) {
|
||||
throw new IOErrorException("Deletion error: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeReference<Map<String, Object>> getRequestType() {
|
||||
return new TypeReference<>() {};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OutputType> getSupportedOutputTypes() {
|
||||
return List.of(OutputType.PLAIN_TEXT, OutputType.JSON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(
|
||||
Map<String, Object> request, RegistrationManager m, JsonWriter jsonWriter
|
||||
) throws CommandException {
|
||||
Namespace commandNamespace = new JsonRpcNamespace(request == null ? Map.of() : request);
|
||||
handleCommand(commandNamespace, m);
|
||||
}
|
||||
}
|
|
@ -47,6 +47,16 @@ public class DbusRegistrationManagerImpl implements RegistrationManager {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteLocalAccountData() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegistered() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue