mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Wrap ignoreAttachments option in a ReceiveConfig record
This commit is contained in:
parent
8828b60288
commit
fd92a96e1a
9 changed files with 35 additions and 24 deletions
|
@ -12,6 +12,7 @@ import org.asamk.signal.manager.api.Message;
|
|||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
|
||||
import org.asamk.signal.manager.api.Pair;
|
||||
import org.asamk.signal.manager.api.ReceiveConfig;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.SendGroupMessageResults;
|
||||
import org.asamk.signal.manager.api.SendMessageResults;
|
||||
|
@ -206,7 +207,7 @@ public interface Manager extends Closeable {
|
|||
*/
|
||||
void receiveMessages(ReceiveMessageHandler handler) throws IOException;
|
||||
|
||||
void setIgnoreAttachments(boolean ignoreAttachments);
|
||||
void setReceiveConfig(ReceiveConfig receiveConfig);
|
||||
|
||||
boolean hasCaughtUpWithOldMessages();
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.asamk.signal.manager.api.InvalidStickerException;
|
|||
import org.asamk.signal.manager.api.Message;
|
||||
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
|
||||
import org.asamk.signal.manager.api.Pair;
|
||||
import org.asamk.signal.manager.api.ReceiveConfig;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.SendGroupMessageResults;
|
||||
import org.asamk.signal.manager.api.SendMessageResult;
|
||||
|
@ -947,8 +948,8 @@ class ManagerImpl implements Manager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setIgnoreAttachments(final boolean ignoreAttachments) {
|
||||
context.getReceiveHelper().setIgnoreAttachments(ignoreAttachments);
|
||||
public void setReceiveConfig(final ReceiveConfig receiveConfig) {
|
||||
context.getReceiveHelper().setReceiveConfig(receiveConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package org.asamk.signal.manager.api;
|
||||
|
||||
public record ReceiveConfig(boolean ignoreAttachments) {}
|
|
@ -22,6 +22,7 @@ import org.asamk.signal.manager.actions.SendSyncKeysAction;
|
|||
import org.asamk.signal.manager.actions.UpdateAccountAttributesAction;
|
||||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
import org.asamk.signal.manager.api.Pair;
|
||||
import org.asamk.signal.manager.api.ReceiveConfig;
|
||||
import org.asamk.signal.manager.api.StickerPackId;
|
||||
import org.asamk.signal.manager.api.TrustLevel;
|
||||
import org.asamk.signal.manager.api.UntrustedIdentityException;
|
||||
|
@ -76,7 +77,7 @@ public final class IncomingMessageHandler {
|
|||
|
||||
public Pair<List<HandleAction>, Exception> handleRetryEnvelope(
|
||||
final SignalServiceEnvelope envelope,
|
||||
final boolean ignoreAttachments,
|
||||
final ReceiveConfig receiveConfig,
|
||||
final Manager.ReceiveMessageHandler handler
|
||||
) {
|
||||
final List<HandleAction> actions = new ArrayList<>();
|
||||
|
@ -100,13 +101,13 @@ public final class IncomingMessageHandler {
|
|||
account.getIdentityKeyStore().setRetryingDecryption(false);
|
||||
}
|
||||
}
|
||||
actions.addAll(checkAndHandleMessage(envelope, content, ignoreAttachments, handler, null));
|
||||
actions.addAll(checkAndHandleMessage(envelope, content, receiveConfig, handler, null));
|
||||
return new Pair<>(actions, null);
|
||||
}
|
||||
|
||||
public Pair<List<HandleAction>, Exception> handleEnvelope(
|
||||
final SignalServiceEnvelope envelope,
|
||||
final boolean ignoreAttachments,
|
||||
final ReceiveConfig receiveConfig,
|
||||
final Manager.ReceiveMessageHandler handler
|
||||
) {
|
||||
final var actions = new ArrayList<HandleAction>();
|
||||
|
@ -156,14 +157,14 @@ public final class IncomingMessageHandler {
|
|||
}
|
||||
}
|
||||
|
||||
actions.addAll(checkAndHandleMessage(envelope, content, ignoreAttachments, handler, exception));
|
||||
actions.addAll(checkAndHandleMessage(envelope, content, receiveConfig, handler, exception));
|
||||
return new Pair<>(actions, exception);
|
||||
}
|
||||
|
||||
private List<HandleAction> checkAndHandleMessage(
|
||||
final SignalServiceEnvelope envelope,
|
||||
final SignalServiceContent content,
|
||||
final boolean ignoreAttachments,
|
||||
final ReceiveConfig receiveConfig,
|
||||
final Manager.ReceiveMessageHandler handler,
|
||||
final Exception exception
|
||||
) {
|
||||
|
@ -190,7 +191,7 @@ public final class IncomingMessageHandler {
|
|||
} else {
|
||||
List<HandleAction> actions;
|
||||
if (content != null) {
|
||||
actions = handleMessage(envelope, content, ignoreAttachments);
|
||||
actions = handleMessage(envelope, content, receiveConfig);
|
||||
} else {
|
||||
actions = List.of();
|
||||
}
|
||||
|
@ -205,7 +206,7 @@ public final class IncomingMessageHandler {
|
|||
}
|
||||
|
||||
public List<HandleAction> handleMessage(
|
||||
SignalServiceEnvelope envelope, SignalServiceContent content, boolean ignoreAttachments
|
||||
SignalServiceEnvelope envelope, SignalServiceContent content, ReceiveConfig receiveConfig
|
||||
) {
|
||||
var actions = new ArrayList<HandleAction>();
|
||||
final var senderPair = getSender(envelope, content);
|
||||
|
@ -264,12 +265,12 @@ public final class IncomingMessageHandler {
|
|||
false,
|
||||
sender,
|
||||
account.getSelfRecipientId(),
|
||||
ignoreAttachments));
|
||||
receiveConfig.ignoreAttachments()));
|
||||
}
|
||||
|
||||
if (content.getSyncMessage().isPresent()) {
|
||||
var syncMessage = content.getSyncMessage().get();
|
||||
actions.addAll(handleSyncMessage(syncMessage, sender, ignoreAttachments));
|
||||
actions.addAll(handleSyncMessage(syncMessage, sender, receiveConfig.ignoreAttachments()));
|
||||
}
|
||||
|
||||
return actions;
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.asamk.signal.manager.helper;
|
|||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.SignalDependencies;
|
||||
import org.asamk.signal.manager.actions.HandleAction;
|
||||
import org.asamk.signal.manager.api.ReceiveConfig;
|
||||
import org.asamk.signal.manager.api.UntrustedIdentityException;
|
||||
import org.asamk.signal.manager.storage.SignalAccount;
|
||||
import org.asamk.signal.manager.storage.messageCache.CachedMessage;
|
||||
|
@ -34,7 +35,7 @@ public class ReceiveHelper {
|
|||
private final SignalDependencies dependencies;
|
||||
private final Context context;
|
||||
|
||||
private boolean ignoreAttachments = false;
|
||||
private ReceiveConfig receiveConfig = new ReceiveConfig(false);
|
||||
private boolean needsToRetryFailedMessages = false;
|
||||
private boolean hasCaughtUpWithOldMessages = false;
|
||||
private boolean isWaitingForMessage = false;
|
||||
|
@ -48,8 +49,8 @@ public class ReceiveHelper {
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
public void setIgnoreAttachments(final boolean ignoreAttachments) {
|
||||
this.ignoreAttachments = ignoreAttachments;
|
||||
public void setReceiveConfig(final ReceiveConfig receiveConfig) {
|
||||
this.receiveConfig = receiveConfig;
|
||||
}
|
||||
|
||||
public void setNeedsToRetryFailedMessages(final boolean needsToRetryFailedMessages) {
|
||||
|
@ -192,7 +193,7 @@ public class ReceiveHelper {
|
|||
continue;
|
||||
}
|
||||
|
||||
final var result = context.getIncomingMessageHandler().handleEnvelope(envelope, ignoreAttachments, handler);
|
||||
final var result = context.getIncomingMessageHandler().handleEnvelope(envelope, receiveConfig, handler);
|
||||
for (final var h : result.first()) {
|
||||
final var existingAction = queuedActions.get(h);
|
||||
if (existingAction == null) {
|
||||
|
@ -247,8 +248,7 @@ public class ReceiveHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
final var result = context.getIncomingMessageHandler()
|
||||
.handleRetryEnvelope(envelope, ignoreAttachments, handler);
|
||||
final var result = context.getIncomingMessageHandler().handleRetryEnvelope(envelope, receiveConfig, handler);
|
||||
final var actions = result.first();
|
||||
final var exception = result.second();
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.asamk.signal.json.JsonReceiveMessageHandler;
|
|||
import org.asamk.signal.jsonrpc.SignalJsonRpcDispatcherHandler;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.MultiAccountManager;
|
||||
import org.asamk.signal.manager.api.ReceiveConfig;
|
||||
import org.asamk.signal.output.JsonWriter;
|
||||
import org.asamk.signal.output.JsonWriterImpl;
|
||||
import org.asamk.signal.output.OutputWriter;
|
||||
|
@ -94,7 +95,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
|
|||
final var receiveMode = ns.<ReceiveMode>get("receive-mode");
|
||||
final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
|
||||
|
||||
m.setIgnoreAttachments(ignoreAttachments);
|
||||
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments));
|
||||
addDefaultReceiveHandler(m, noReceiveStdOut ? null : outputWriter, receiveMode != ReceiveMode.ON_START);
|
||||
|
||||
final Channel inheritedChannel;
|
||||
|
@ -156,12 +157,13 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
|
|||
final var receiveMode = ns.<ReceiveMode>get("receive-mode");
|
||||
final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
|
||||
|
||||
final var receiveConfig = new ReceiveConfig(ignoreAttachments);
|
||||
c.getManagers().forEach(m -> {
|
||||
m.setIgnoreAttachments(ignoreAttachments);
|
||||
m.setReceiveConfig(receiveConfig);
|
||||
addDefaultReceiveHandler(m, noReceiveStdOut ? null : outputWriter, receiveMode != ReceiveMode.ON_START);
|
||||
});
|
||||
c.addOnManagerAddedHandler(m -> {
|
||||
m.setIgnoreAttachments(ignoreAttachments);
|
||||
m.setReceiveConfig(receiveConfig);
|
||||
addDefaultReceiveHandler(m, noReceiveStdOut ? null : outputWriter, receiveMode != ReceiveMode.ON_START);
|
||||
});
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.asamk.signal.OutputType;
|
|||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.jsonrpc.SignalJsonRpcDispatcherHandler;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.api.ReceiveConfig;
|
||||
import org.asamk.signal.output.JsonWriter;
|
||||
import org.asamk.signal.output.OutputWriter;
|
||||
import org.asamk.signal.util.IOUtils;
|
||||
|
@ -45,7 +46,7 @@ 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.setIgnoreAttachments(ignoreAttachments);
|
||||
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments));
|
||||
|
||||
final var jsonOutputWriter = (JsonWriter) outputWriter;
|
||||
final Supplier<String> lineSupplier = IOUtils.getLineSupplier(new InputStreamReader(System.in,
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.asamk.signal.commands.exceptions.CommandException;
|
|||
import org.asamk.signal.commands.exceptions.IOErrorException;
|
||||
import org.asamk.signal.json.JsonReceiveMessageHandler;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.api.ReceiveConfig;
|
||||
import org.asamk.signal.output.JsonWriter;
|
||||
import org.asamk.signal.output.OutputWriter;
|
||||
import org.asamk.signal.output.PlainTextWriter;
|
||||
|
@ -52,7 +53,7 @@ public class ReceiveCommand implements LocalCommand {
|
|||
) throws CommandException {
|
||||
double timeout = ns.getDouble("timeout");
|
||||
boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
|
||||
m.setIgnoreAttachments(ignoreAttachments);
|
||||
m.setReceiveConfig(new ReceiveConfig(ignoreAttachments));
|
||||
try {
|
||||
final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
|
||||
(JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.asamk.signal.manager.api.Message;
|
|||
import org.asamk.signal.manager.api.MessageEnvelope;
|
||||
import org.asamk.signal.manager.api.NotPrimaryDeviceException;
|
||||
import org.asamk.signal.manager.api.Pair;
|
||||
import org.asamk.signal.manager.api.ReceiveConfig;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.SendGroupMessageResults;
|
||||
import org.asamk.signal.manager.api.SendMessageResults;
|
||||
|
@ -531,7 +532,7 @@ public class DbusManagerImpl implements Manager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setIgnoreAttachments(final boolean ignoreAttachments) {
|
||||
public void setReceiveConfig(final ReceiveConfig receiveConfig) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue