Skip to content

Commit

Permalink
Add --receive-mode parameter to jsonRpc command
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Sep 1, 2023
1 parent ee195c9 commit c8daef5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

- Added `--receive-mode` parameter for `jsonRpc` command

## [0.12.1] - 2023-08-26

### Added
Expand Down
2 changes: 1 addition & 1 deletion graalvm-config-dir/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions man/signal-cli.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,24 @@ Don’t 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*::
Don’t download attachments of received messages.

*--ignore-stories*::
Don’t 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public void attachToSubparser(final Subparser subparser) {
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
Expand All @@ -51,16 +55,27 @@ public List<OutputType> getSupportedOutputTypes() {
public void handleCommand(
final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException {
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));
final var receiveMode = ns.<ReceiveMode>get("receive-mode");
final var receiveConfig = getReceiveConfig(ns);
m.setReceiveConfig(receiveConfig);

final var jsonOutputWriter = (JsonWriter) outputWriter;
final Supplier<String> lineSupplier = IOUtils.getLineSupplier(new InputStreamReader(System.in,
IOUtils.getConsoleCharset()));
final var lineSupplier = getLineSupplier();

final var handler = new SignalJsonRpcDispatcherHandler(jsonOutputWriter, lineSupplier, false);
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"));
return new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts);
}

private static Supplier<String> getLineSupplier() {
return IOUtils.getLineSupplier(new InputStreamReader(System.in, IOUtils.getConsoleCharset()));
}
}

0 comments on commit c8daef5

Please sign in to comment.