Add listAccounts command

This commit is contained in:
AsamK 2021-11-10 20:12:40 +01:00
parent 9c67aabebb
commit 62dd2ee49e
4 changed files with 50 additions and 1 deletions

View file

@ -449,6 +449,13 @@
"allDeclaredMethods":true,
"allDeclaredConstructors":true}
,
{
"name":"org.asamk.signal.commands.ListAccountsCommand$JsonAccount",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"number","parameterTypes":[] }]}
,
{
"name":"org.asamk.signal.commands.ListContactsCommand$JsonContact",
"allDeclaredFields":true,

View file

@ -17,6 +17,7 @@ public class Commands {
addCommand(new JoinGroupCommand());
addCommand(new JsonRpcDispatcherCommand());
addCommand(new LinkCommand());
addCommand(new ListAccountsCommand());
addCommand(new ListContactsCommand());
addCommand(new ListDevicesCommand());
addCommand(new ListGroupsCommand());

View file

@ -0,0 +1,41 @@
package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.JsonWriter;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriter;
import org.asamk.signal.commands.exceptions.CommandException;
import java.util.stream.Collectors;
public class ListAccountsCommand implements JsonRpcMultiLocalCommand {
@Override
public String getName() {
return "listAccounts";
}
@Override
public void attachToSubparser(final Subparser subparser) {
subparser.help("Show a list of registered accounts.");
}
@Override
public void handleCommand(
final Namespace ns, final SignalCreator c, final OutputWriter outputWriter
) throws CommandException {
final var accountNumbers = c.getAccountNumbers();
if (outputWriter instanceof JsonWriter jsonWriter) {
final var jsonAccounts = accountNumbers.stream().map(JsonAccount::new).collect(Collectors.toList());
jsonWriter.write(jsonAccounts);
} else if (outputWriter instanceof PlainTextWriter plainTextWriter) {
for (final var number : accountNumbers) {
plainTextWriter.println("Number: {}", number);
}
}
}
private record JsonAccount(String number) {}
}

View file

@ -119,7 +119,7 @@ public class SignalJsonRpcDispatcherHandler {
final ObjectMapper objectMapper, final String method, ContainerNode<?> params
) throws JsonRpcException {
var command = getCommand(method);
// TODO implement listAccounts, register, verify, link
// TODO implement register, verify, link
if (c != null && command instanceof JsonRpcMultiCommand<?> jsonRpcCommand) {
return runCommand(objectMapper, params, new MultiCommandRunnerImpl<>(c, jsonRpcCommand));
}