mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Detect when receive has caught up with old messages
This commit is contained in:
parent
5829e3f117
commit
d14b8ac71f
1 changed files with 12 additions and 1 deletions
|
@ -1402,13 +1402,15 @@ public class Manager implements Closeable {
|
||||||
messagePipe = messageReceiver.createMessagePipe();
|
messagePipe = messageReceiver.createMessagePipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean hasCaughtUpWithOldMessages = false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
SignalServiceEnvelope envelope;
|
SignalServiceEnvelope envelope;
|
||||||
SignalServiceContent content = null;
|
SignalServiceContent content = null;
|
||||||
Exception exception = null;
|
Exception exception = null;
|
||||||
final long now = new Date().getTime();
|
final long now = new Date().getTime();
|
||||||
try {
|
try {
|
||||||
envelope = messagePipe.read(timeout, unit, envelope1 -> {
|
Optional<SignalServiceEnvelope> result = messagePipe.readOrEmpty(timeout, unit, envelope1 -> {
|
||||||
// store message on disk, before acknowledging receipt to the server
|
// store message on disk, before acknowledging receipt to the server
|
||||||
try {
|
try {
|
||||||
String source = envelope1.getSourceE164().isPresent() ? envelope1.getSourceE164().get() : "";
|
String source = envelope1.getSourceE164().isPresent() ? envelope1.getSourceE164().get() : "";
|
||||||
|
@ -1418,6 +1420,15 @@ public class Manager implements Closeable {
|
||||||
System.err.println("Failed to store encrypted message in disk cache, ignoring: " + e.getMessage());
|
System.err.println("Failed to store encrypted message in disk cache, ignoring: " + e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (result.isPresent()) {
|
||||||
|
envelope = result.get();
|
||||||
|
} else {
|
||||||
|
// Received indicator that server queue is empty
|
||||||
|
hasCaughtUpWithOldMessages = true;
|
||||||
|
|
||||||
|
// Continue to wait another timeout for new messages
|
||||||
|
continue;
|
||||||
|
}
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
if (returnOnTimeout)
|
if (returnOnTimeout)
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue