1 package org
.asamk
.signal
.commands
;
3 import com
.fasterxml
.jackson
.core
.type
.TypeReference
;
5 import net
.sourceforge
.argparse4j
.impl
.Arguments
;
6 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
7 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
9 import org
.asamk
.signal
.OutputType
;
10 import org
.asamk
.signal
.commands
.exceptions
.CommandException
;
11 import org
.asamk
.signal
.commands
.exceptions
.IOErrorException
;
12 import org
.asamk
.signal
.commands
.exceptions
.UserErrorException
;
13 import org
.asamk
.signal
.manager
.RegistrationManager
;
14 import org
.asamk
.signal
.output
.JsonWriter
;
16 import java
.io
.IOException
;
17 import java
.util
.List
;
20 public class DeleteLocalAccountDataCommand
implements RegistrationCommand
, JsonRpcRegistrationCommand
<Map
<String
, Object
>> {
23 public String
getName() {
24 return "deleteLocalAccountData";
28 public void attachToSubparser(final Subparser subparser
) {
30 "Delete all local data for this account. Data should only be deleted if the account is unregistered. CAUTION: This cannot be undone.");
31 subparser
.addArgument("--ignore-registered")
32 .help("Delete the account data even though the account is still registered on the Signal servers.")
33 .action(Arguments
.storeTrue());
37 public void handleCommand(final Namespace ns
, final RegistrationManager m
) throws CommandException
{
39 final var ignoreRegistered
= Boolean
.TRUE
.equals(ns
.getBoolean("ignore-registered"));
40 if (m
.isRegistered() && !ignoreRegistered
) {
41 throw new UserErrorException(
42 "Not deleting account, it is still registered. Use --ignore-registered to delete it anyway.");
45 m
.deleteLocalAccountData();
46 } catch (IOException e
) {
47 throw new IOErrorException("Deletion error: " + e
.getMessage(), e
);
52 public TypeReference
<Map
<String
, Object
>> getRequestType() {
53 return new TypeReference
<>() {};
57 public List
<OutputType
> getSupportedOutputTypes() {
58 return List
.of(OutputType
.PLAIN_TEXT
, OutputType
.JSON
);
62 public void handleCommand(
63 Map
<String
, Object
> request
, RegistrationManager m
, JsonWriter jsonWriter
64 ) throws CommandException
{
65 Namespace commandNamespace
= new JsonRpcNamespace(request
== null ? Map
.of() : request
);
66 handleCommand(commandNamespace
, m
);