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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue