mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Add --ignore-stories flag to prevent receiving story messages
This commit is contained in:
parent
3f7d8c60b9
commit
9ffacfe90e
8 changed files with 51 additions and 20 deletions
|
@ -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);
|
||||
|
|
|
@ -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) {}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue