mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 02:50:39 +00:00
Improve robustness in receiving messages
This commit is contained in:
parent
e5aa10a730
commit
a7744e837c
2 changed files with 48 additions and 36 deletions
|
@ -137,13 +137,17 @@ public final class IncomingMessageHandler {
|
||||||
final Manager.ReceiveMessageHandler handler
|
final Manager.ReceiveMessageHandler handler
|
||||||
) {
|
) {
|
||||||
final var actions = new ArrayList<HandleAction>();
|
final var actions = new ArrayList<HandleAction>();
|
||||||
if (envelope.hasSourceServiceId()) {
|
|
||||||
// Store uuid if we don't have it already
|
|
||||||
// uuid in envelope is sent by server
|
|
||||||
account.getRecipientTrustedResolver().resolveRecipientTrusted(envelope.getSourceAddress());
|
|
||||||
}
|
|
||||||
SignalServiceContent content = null;
|
SignalServiceContent content = null;
|
||||||
Exception exception = null;
|
Exception exception = null;
|
||||||
|
try {
|
||||||
|
if (envelope.hasSourceServiceId()) {
|
||||||
|
// Store uuid if we don't have it already
|
||||||
|
// uuid in envelope is sent by server
|
||||||
|
account.getRecipientTrustedResolver().resolveRecipientTrusted(envelope.getSourceAddress());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
exception = e;
|
||||||
|
}
|
||||||
if (!envelope.isReceipt()) {
|
if (!envelope.isReceipt()) {
|
||||||
try {
|
try {
|
||||||
final var cipherResult = dependencies.getCipher()
|
final var cipherResult = dependencies.getCipher()
|
||||||
|
|
|
@ -205,41 +205,49 @@ public class ReceiveHelper {
|
||||||
backOffCounter = 0;
|
backOffCounter = 0;
|
||||||
if (returnOnTimeout) return;
|
if (returnOnTimeout) return;
|
||||||
continue;
|
continue;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Unknown error when receiving messages", e);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final var result = context.getIncomingMessageHandler().handleEnvelope(envelope, receiveConfig, handler);
|
try {
|
||||||
for (final var h : result.first()) {
|
final var result = context.getIncomingMessageHandler().handleEnvelope(envelope, receiveConfig, handler);
|
||||||
final var existingAction = queuedActions.get(h);
|
for (final var h : result.first()) {
|
||||||
if (existingAction == null) {
|
final var existingAction = queuedActions.get(h);
|
||||||
queuedActions.put(h, h);
|
if (existingAction == null) {
|
||||||
} else {
|
queuedActions.put(h, h);
|
||||||
existingAction.mergeOther(h);
|
} else {
|
||||||
}
|
existingAction.mergeOther(h);
|
||||||
}
|
|
||||||
final var exception = result.second();
|
|
||||||
|
|
||||||
if (hasCaughtUpWithOldMessages) {
|
|
||||||
handleQueuedActions(queuedActions.keySet());
|
|
||||||
queuedActions.clear();
|
|
||||||
}
|
|
||||||
if (cachedMessage[0] != null) {
|
|
||||||
if (exception instanceof UntrustedIdentityException) {
|
|
||||||
logger.debug("Keeping message with untrusted identity in message cache");
|
|
||||||
final var address = ((UntrustedIdentityException) exception).getSender();
|
|
||||||
if (!envelope.hasSourceServiceId() && address.uuid().isPresent()) {
|
|
||||||
final var recipientId = account.getRecipientResolver()
|
|
||||||
.resolveRecipient(ACI.from(address.uuid().get()));
|
|
||||||
try {
|
|
||||||
cachedMessage[0] = account.getMessageCache().replaceSender(cachedMessage[0], recipientId);
|
|
||||||
} catch (IOException ioException) {
|
|
||||||
logger.warn("Failed to move cached message to recipient folder: {}",
|
|
||||||
ioException.getMessage(),
|
|
||||||
ioException);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cachedMessage[0].delete();
|
|
||||||
}
|
}
|
||||||
|
final var exception = result.second();
|
||||||
|
|
||||||
|
if (hasCaughtUpWithOldMessages) {
|
||||||
|
handleQueuedActions(queuedActions.keySet());
|
||||||
|
queuedActions.clear();
|
||||||
|
}
|
||||||
|
if (cachedMessage[0] != null) {
|
||||||
|
if (exception instanceof UntrustedIdentityException) {
|
||||||
|
logger.debug("Keeping message with untrusted identity in message cache");
|
||||||
|
final var address = ((UntrustedIdentityException) exception).getSender();
|
||||||
|
if (!envelope.hasSourceServiceId() && address.uuid().isPresent()) {
|
||||||
|
final var recipientId = account.getRecipientResolver()
|
||||||
|
.resolveRecipient(ACI.from(address.uuid().get()));
|
||||||
|
try {
|
||||||
|
cachedMessage[0] = account.getMessageCache()
|
||||||
|
.replaceSender(cachedMessage[0], recipientId);
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
logger.warn("Failed to move cached message to recipient folder: {}",
|
||||||
|
ioException.getMessage(),
|
||||||
|
ioException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cachedMessage[0].delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Unknown error when handling messages", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue