]> nmode's Git Repositories - signal-cli/commitdiff
Add --ignore-stories flag to prevent receiving story messages
authorAsamK <asamk@gmx.de>
Wed, 19 Oct 2022 17:09:23 +0000 (19:09 +0200)
committerAsamK <asamk@gmx.de>
Wed, 19 Oct 2022 17:11:37 +0000 (19:11 +0200)
lib/src/main/java/org/asamk/signal/manager/SignalDependencies.java
lib/src/main/java/org/asamk/signal/manager/api/ReceiveConfig.java
lib/src/main/java/org/asamk/signal/manager/helper/AccountHelper.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 6450f1f8f883f167b8da9fae97929105968eec2c..3b3b375a7d6ddd99d2f4872d14310b31d042e3fe 100644 (file)
@@ -40,6 +40,8 @@ public class SignalDependencies {
     private final ExecutorService executor;
     private final SignalSessionLock sessionLock;
 
+    private boolean allowStories = true;
+
     private SignalServiceAccountManager accountManager;
     private GroupsV2Api groupsV2Api;
     private GroupsV2Operations groupsV2Operations;
@@ -72,6 +74,14 @@ public class SignalDependencies {
     public void resetAfterAddressChange() {
         this.messageSender = null;
         this.cipher = null;
+        getSignalWebSocket().forceNewWebSockets();
+    }
+
+    /**
+     * This method needs to be called before the first websocket is created
+     */
+    public void setAllowStories(final boolean allowStories) {
+        this.allowStories = allowStories;
     }
 
     public ServiceEnvironmentConfig getServiceEnvironmentConfig() {
@@ -135,7 +145,7 @@ public class SignalDependencies {
                             Optional.of(credentialsProvider),
                             userAgent,
                             healthMonitor,
-                            true);
+                            allowStories);
                 }
 
                 @Override
@@ -145,7 +155,7 @@ public class SignalDependencies {
                             Optional.empty(),
                             userAgent,
                             healthMonitor,
-                            true);
+                            allowStories);
                 }
             };
             signalWebSocket = new SignalWebSocket(webSocketFactory);
index bf5f1d99da43ea33f8bd3b435825884e2c226701..e9108d120f6efdf3b287d062e1c342af63c651c2 100644 (file)
@@ -1,3 +1,3 @@
 package org.asamk.signal.manager.api;
 
-public record ReceiveConfig(boolean ignoreAttachments, boolean sendReadReceipts) {}
+public record ReceiveConfig(boolean ignoreAttachments, boolean ignoreStories, boolean sendReadReceipts) {}
index 7ae9aa450d0e35897e58e550e91a098b1e72fcfc..36cd76a363956ca1041491aba15f4ca5a7cc6720 100644 (file)
@@ -110,7 +110,6 @@ public class AccountHelper {
         // TODO check and update remote storage
         context.getUnidentifiedAccessHelper().rotateSenderCertificates();
         dependencies.resetAfterAddressChange();
-        dependencies.getSignalWebSocket().forceNewWebSockets();
         context.getAccountFileUpdater().updateAccountIdentifiers(account.getNumber(), account.getAci());
     }
 
index 09ca1a4043552039e3de93890bd769a8fdeb2933..5dca96eacdae3b3e7ce96f7308721a9e00d00a96 100644 (file)
@@ -9,6 +9,7 @@ import org.asamk.signal.manager.storage.SignalAccount;
 import org.asamk.signal.manager.storage.messageCache.CachedMessage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.whispersystems.signalservice.api.SignalWebSocket;
 import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
 import org.whispersystems.signalservice.api.websocket.WebSocketConnectionState;
 import org.whispersystems.signalservice.api.websocket.WebSocketUnavailableException;
@@ -35,7 +36,7 @@ public class ReceiveHelper {
     private final SignalDependencies dependencies;
     private final Context context;
 
-    private ReceiveConfig receiveConfig = new ReceiveConfig(false, false);
+    private ReceiveConfig receiveConfig = new ReceiveConfig(false, false, false);
     private boolean needsToRetryFailedMessages = false;
     private boolean hasCaughtUpWithOldMessages = false;
     private boolean isWaitingForMessage = false;
@@ -51,6 +52,7 @@ public class ReceiveHelper {
 
     public void setReceiveConfig(final ReceiveConfig receiveConfig) {
         this.receiveConfig = receiveConfig;
+        dependencies.setAllowStories(!receiveConfig.ignoreStories());
     }
 
     public void setNeedsToRetryFailedMessages(final boolean needsToRetryFailedMessages) {
@@ -104,25 +106,24 @@ public class ReceiveHelper {
         signalWebSocket.connect();
 
         try {
-            receiveMessagesInternal(timeout, returnOnTimeout, handler, queuedActions);
+            receiveMessagesInternal(signalWebSocket, timeout, returnOnTimeout, handler, queuedActions);
         } finally {
             hasCaughtUpWithOldMessages = false;
             handleQueuedActions(queuedActions.keySet());
             queuedActions.clear();
-            dependencies.getSignalWebSocket().disconnect();
+            signalWebSocket.disconnect();
             webSocketStateDisposable.dispose();
             shouldStop = false;
         }
     }
 
     private void receiveMessagesInternal(
+            final SignalWebSocket signalWebSocket,
             Duration timeout,
             boolean returnOnTimeout,
             Manager.ReceiveMessageHandler handler,
             final Map<HandleAction, HandleAction> queuedActions
     ) throws IOException {
-        final var signalWebSocket = dependencies.getSignalWebSocket();
-
         var backOffCounter = 0;
         isWaitingForMessage = false;
 
index f1e9e79ad5b203e266341e2845493f1da16084c3..9b6ec2dba89a1d7b777f57c7e403bab632dfac44 100644 (file)
@@ -359,9 +359,14 @@ In json mode this is outputted as one json object per line.
 *-t* TIMEOUT, *--timeout* TIMEOUT::
 Number of seconds to wait for new messages (negative values disable timeout).
 Default is 5 seconds.
+
 *--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)
 
@@ -639,6 +644,9 @@ 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)
 
index cec7cd03e622117dc62b3333874dee0c65d22cfe..01d0326f5a79bd99ebb7f224415c87a813ed766b 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("--ignore-stories")
+                .help("Don’t receive story messages from the server.")
+                .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());
@@ -97,9 +100,10 @@ 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 ignoreStories = Boolean.TRUE.equals(ns.getBoolean("ignore-stories"));
+        final var sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
 
-        m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, sendReadReceipts));
+        m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts));
         addDefaultReceiveHandler(m, noReceiveStdOut ? null : outputWriter, receiveMode != ReceiveMode.ON_START);
 
         final Channel inheritedChannel;
@@ -160,9 +164,10 @@ 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 ignoreStories = Boolean.TRUE.equals(ns.getBoolean("ignore-stories"));
+        final var sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
 
-        final var receiveConfig = new ReceiveConfig(ignoreAttachments, sendReadReceipts);
+        final var receiveConfig = new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts);
         c.getManagers().forEach(m -> {
             m.setReceiveConfig(receiveConfig);
             addDefaultReceiveHandler(m, noReceiveStdOut ? null : outputWriter, receiveMode != ReceiveMode.ON_START);
index ef33a6e8857f47e0d16a99ba016971708cc4b2c2..34961bd3bbd32112952f753f5e67ad38b2ba4b65 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("--ignore-stories")
+                .help("Don’t receive story messages from the server.")
+                .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());
@@ -48,9 +51,10 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
     public void handleCommand(
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
-        final boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
-        final boolean sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
-        m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, sendReadReceipts));
+        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 jsonOutputWriter = (JsonWriter) outputWriter;
         final Supplier<String> lineSupplier = IOUtils.getLineSupplier(new InputStreamReader(System.in,
index 68292557e381c27679452215f96acf28e75a57e0..4d5bdff0792553552ffb6ab510333849ec0d4695 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("--ignore-stories")
+                .help("Don’t receive story messages from the server.")
+                .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());
@@ -54,10 +57,11 @@ public class ReceiveCommand implements LocalCommand {
     public void handleCommand(
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
-        double timeout = ns.getDouble("timeout");
-        boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
-        boolean sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
-        m.setReceiveConfig(new ReceiveConfig(ignoreAttachments, sendReadReceipts));
+        final var timeout = ns.getDouble("timeout");
+        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));
         try {
             final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
                     (JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);