Add option to send read receipts for all received data messages

Fixes #850
This commit is contained in:
AsamK 2022-05-26 18:00:23 +02:00
parent fd92a96e1a
commit 27dbc671e0
7 changed files with 30 additions and 6 deletions

View file

@ -1,3 +1,3 @@
package org.asamk.signal.manager.api;
public record ReceiveConfig(boolean ignoreAttachments) {}
public record ReceiveConfig(boolean ignoreAttachments, boolean sendReadReceipts) {}

View file

@ -260,6 +260,11 @@ public final class IncomingMessageHandler {
actions.add(new SendProfileKeyAction(sender));
}
}
if (receiveConfig.sendReadReceipts()) {
actions.add(new SendReceiptAction(sender,
SignalServiceReceiptMessage.Type.READ,
message.getTimestamp()));
}
actions.addAll(handleSignalServiceDataMessage(message,
false,

View file

@ -35,7 +35,7 @@ public class ReceiveHelper {
private final SignalDependencies dependencies;
private final Context context;
private ReceiveConfig receiveConfig = new ReceiveConfig(false);
private ReceiveConfig receiveConfig = new ReceiveConfig(false, false);
private boolean needsToRetryFailedMessages = false;
private boolean hasCaughtUpWithOldMessages = false;
private boolean isWaitingForMessage = false;

View file

@ -357,6 +357,9 @@ Default is 5 seconds.
*--ignore-attachments*::
Dont download attachments of received messages.
*--send-read-receipts*::
Send read receipts for all incoming data messages (in addition to the default delivery receipts)
=== joinGroup
Join a group via an invitation link.
@ -628,6 +631,9 @@ See signal-cli-jsonrpc (5) for info on the JSON-RPC interface.
*--ignore-attachments*::
Dont download attachments of received messages.
*--send-read-receipts*::
Send read receipts for all incoming data messages (in addition to the default delivery receipts)
*--no-receive-stdout*::
Dont print received messages to stdout.

View file

@ -79,6 +79,9 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
subparser.addArgument("--ignore-attachments")
.help("Dont download attachments of received messages.")
.action(Arguments.storeTrue());
subparser.addArgument("--send-read-receipts")
.help("Send read receipts for all incoming data messages (in addition to the default delivery receipts)")
.action(Arguments.storeTrue());
}
@Override
@ -94,8 +97,9 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
final var noReceiveStdOut = Boolean.TRUE.equals(ns.getBoolean("no-receive-stdout"));
final var receiveMode = ns.<ReceiveMode>get("receive-mode");
final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
final boolean sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments));
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, sendReadReceipts));
addDefaultReceiveHandler(m, noReceiveStdOut ? null : outputWriter, receiveMode != ReceiveMode.ON_START);
final Channel inheritedChannel;
@ -156,8 +160,9 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
final var noReceiveStdOut = Boolean.TRUE.equals(ns.getBoolean("no-receive-stdout"));
final var receiveMode = ns.<ReceiveMode>get("receive-mode");
final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
final boolean sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
final var receiveConfig = new ReceiveConfig(ignoreAttachments);
final var receiveConfig = new ReceiveConfig(ignoreAttachments, sendReadReceipts);
c.getManagers().forEach(m -> {
m.setReceiveConfig(receiveConfig);
addDefaultReceiveHandler(m, noReceiveStdOut ? null : outputWriter, receiveMode != ReceiveMode.ON_START);

View file

@ -34,6 +34,9 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
subparser.addArgument("--ignore-attachments")
.help("Dont download attachments of received messages.")
.action(Arguments.storeTrue());
subparser.addArgument("--send-read-receipts")
.help("Send read receipts for all incoming data messages (in addition to the default delivery receipts)")
.action(Arguments.storeTrue());
}
@Override
@ -46,7 +49,8 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
final Namespace ns, final Manager m, final OutputWriter outputWriter
) throws CommandException {
final boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments));
final boolean sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, sendReadReceipts));
final var jsonOutputWriter = (JsonWriter) outputWriter;
final Supplier<String> lineSupplier = IOUtils.getLineSupplier(new InputStreamReader(System.in,

View file

@ -40,6 +40,9 @@ public class ReceiveCommand implements LocalCommand {
subparser.addArgument("--ignore-attachments")
.help("Dont download attachments of received messages.")
.action(Arguments.storeTrue());
subparser.addArgument("--send-read-receipts")
.help("Send read receipts for all incoming data messages (in addition to the default delivery receipts)")
.action(Arguments.storeTrue());
}
@Override
@ -53,7 +56,8 @@ public class ReceiveCommand implements LocalCommand {
) throws CommandException {
double timeout = ns.getDouble("timeout");
boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments));
boolean sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, sendReadReceipts));
try {
final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
(JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);