Add --receive-mode parameter to jsonRpc command

This commit is contained in:
AsamK 2023-09-01 12:08:56 +02:00
parent ee195c966e
commit c8daef5113
4 changed files with 45 additions and 8 deletions

View file

@ -2,6 +2,10 @@
## [Unreleased]
### Added
- Added `--receive-mode` parameter for `jsonRpc` command
## [0.12.1] - 2023-08-26
### Added

View file

@ -1098,7 +1098,7 @@
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true,
"methods":[{"name":"getError","parameterTypes":[] }, {"name":"getId","parameterTypes":[] }, {"name":"getJsonrpc","parameterTypes":[] }, {"name":"getResult","parameterTypes":[] }]
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"getError","parameterTypes":[] }, {"name":"getId","parameterTypes":[] }, {"name":"getJsonrpc","parameterTypes":[] }, {"name":"getResult","parameterTypes":[] }]
},
{
"name":"org.asamk.signal.jsonrpc.JsonRpcResponse$Error",

View file

@ -717,6 +717,24 @@ Dont print received messages to stdout.
*--receive-mode*::
Specify when to start receiving messages (on-start, on-connection, manual)
=== jsonRpc
Run in signal-cli in JSON-RPC mode.
Reads JSON-RPC requests on stdin and responds on stdout.
See **signal-cli-jsonrpc**(5) for info on the JSON-RPC interface.
*--ignore-attachments*::
Dont download attachments of received messages.
*--ignore-stories*::
Dont receive story messages from the server.
*--send-read-receipts*::
Send read receipts for all incoming data messages (in addition to the default delivery receipts)
*--receive-mode*::
Specify when to start receiving messages (on-start, manual)
=== submitRateLimitChallenge
When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA.

View file

@ -40,6 +40,10 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
subparser.addArgument("--send-read-receipts")
.help("Send read receipts for all incoming data messages (in addition to the default delivery receipts)")
.action(Arguments.storeTrue());
subparser.addArgument("--receive-mode")
.help("Specify when to start receiving messages.")
.type(Arguments.enumStringType(ReceiveMode.class))
.setDefault(ReceiveMode.ON_START);
}
@Override
@ -51,16 +55,27 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException {
final var receiveMode = ns.<ReceiveMode>get("receive-mode");
final var receiveConfig = getReceiveConfig(ns);
m.setReceiveConfig(receiveConfig);
final var jsonOutputWriter = (JsonWriter) outputWriter;
final var lineSupplier = getLineSupplier();
final var handler = new SignalJsonRpcDispatcherHandler(jsonOutputWriter,
lineSupplier,
receiveMode == ReceiveMode.MANUAL);
handler.handleConnection(m);
}
private static ReceiveConfig getReceiveConfig(final Namespace ns) {
final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
final var ignoreStories = Boolean.TRUE.equals(ns.getBoolean("ignore-stories"));
final var sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts));
return new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts);
}
final var jsonOutputWriter = (JsonWriter) outputWriter;
final Supplier<String> lineSupplier = IOUtils.getLineSupplier(new InputStreamReader(System.in,
IOUtils.getConsoleCharset()));
final var handler = new SignalJsonRpcDispatcherHandler(jsonOutputWriter, lineSupplier, false);
handler.handleConnection(m);
private static Supplier<String> getLineSupplier() {
return IOUtils.getLineSupplier(new InputStreamReader(System.in, IOUtils.getConsoleCharset()));
}
}