]> nmode's Git Repositories - signal-cli/commitdiff
Add option to send read receipts for all received data messages
authorAsamK <asamk@gmx.de>
Thu, 26 May 2022 16:00:23 +0000 (18:00 +0200)
committerAsamK <asamk@gmx.de>
Thu, 26 May 2022 16:00:23 +0000 (18:00 +0200)
Fixes #850

lib/src/main/java/org/asamk/signal/manager/api/ReceiveConfig.java
lib/src/main/java/org/asamk/signal/manager/helper/IncomingMessageHandler.java
lib/src/main/java/org/asamk/signal/manager/helper/ReceiveHelper.java
man/signal-cli.1.adoc
src/main/java/org/asamk/signal/commands/DaemonCommand.java
src/main/java/org/asamk/signal/commands/JsonRpcDispatcherCommand.java
src/main/java/org/asamk/signal/commands/ReceiveCommand.java

index 0210c430b4e81a14de7114b1f1c7639ec07993c5..bf5f1d99da43ea33f8bd3b435825884e2c226701 100644 (file)
@@ -1,3 +1,3 @@
 package org.asamk.signal.manager.api;
 
-public record ReceiveConfig(boolean ignoreAttachments) {}
+public record ReceiveConfig(boolean ignoreAttachments, boolean sendReadReceipts) {}
index 2ee2e14ef7391068c2fc98965933ea8208b56ed8..b6e3d8cb71a70e1c94ed1f85846b77c7259cce2f 100644 (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,
index d27fe121787ddcaa91da7391b674b3d54c46fc87..d3c1ef5629e135a6cb27597f095497368ce00d09 100644 (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;
index 1ccb067c279fa73ee22532e52e4516d9b9942841..4d32ea5f3b664dd24ff326d61f7830758be25f73 100644 (file)
@@ -357,6 +357,9 @@ Default is 5 seconds.
 *--ignore-attachments*::
 Don’t 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*::
 Don’t 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*::
 Don’t print received messages to stdout.
 
index c65d576d2de346869d50eaa6b7d81b064a88f2e4..cec7cd03e622117dc62b3333874dee0c65d22cfe 100644 (file)
@@ -79,6 +79,9 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
         subparser.addArgument("--ignore-attachments")
                 .help("Don’t 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);
index ca5b8939419eadf4cedee7527c01c85ca01e87c0..ef33a6e8857f47e0d16a99ba016971708cc4b2c2 100644 (file)
@@ -34,6 +34,9 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
         subparser.addArgument("--ignore-attachments")
                 .help("Don’t 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,
index bb7e9b732156c97d32823eecfbff496bf9debe84..68292557e381c27679452215f96acf28e75a57e0 100644 (file)
@@ -40,6 +40,9 @@ public class ReceiveCommand implements LocalCommand {
         subparser.addArgument("--ignore-attachments")
                 .help("Don’t 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);