From fe8f0bd7f0acdadade5c6756846b9c29673c5035 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 25 Mar 2018 17:22:39 +0200 Subject: [PATCH] make receipt handling work with out of order receipts --- .../siacs/conversations/parser/MessageParser.java | 6 +++--- .../services/MessageArchiveService.java | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 56a685d2f..c34ad1c4a 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -692,7 +692,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece String id = received.getAttribute("id"); if (packet.fromAccount(account)) { if (query != null && id != null && packet.getTo() != null) { - query.pendingReceiptRequests.remove(new ReceiptRequest(packet.getTo(),id)); + query.removePendingReceiptRequest(new ReceiptRequest(packet.getTo(),id)); } } else { mXmppConnectionService.markMessage(account, from.asBareJid(), received.getAttribute("id"), Message.STATUS_SEND_RECEIVED); @@ -785,9 +785,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece packet.getType()); mXmppConnectionService.sendMessagePacket(account, receipt); } - } else { + } else { //just catchup?? if (request) { - query.pendingReceiptRequests.add(new ReceiptRequest(packet.getFrom(),packet.getId())); + query.addPendingReceiptRequest(new ReceiptRequest(packet.getFrom(),packet.getId())); } } } diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index da0de5964..2ae1c8b2b 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -324,6 +324,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { private void processPostponed(Query query) { query.account.getAxolotlService().processPostponed(); + query.pendingReceiptRequests.removeAll(query.receiptRequests); Log.d(Config.LOGTAG, query.getAccount().getJid().asBareJid() + ": found " + query.pendingReceiptRequests.size() + " pending receipt requests"); Iterator iterator = query.pendingReceiptRequests.iterator(); while (iterator.hasNext()) { @@ -360,7 +361,8 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } public class Query { - public HashSet pendingReceiptRequests = new HashSet<>(); + private HashSet pendingReceiptRequests = new HashSet<>(); + private HashSet receiptRequests = new HashSet<>(); private int totalCount = 0; private int actualCount = 0; private int actualInThisQuery = 0; @@ -399,11 +401,22 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { query.totalCount = totalCount; query.actualCount = actualCount; query.pendingReceiptRequests = pendingReceiptRequests; + query.receiptRequests = receiptRequests; query.callback = callback; query.catchup = catchup; return query; } + public void removePendingReceiptRequest(ReceiptRequest receiptRequest) { + if (!this.pendingReceiptRequests.remove(receiptRequest)) { + this.receiptRequests.add(receiptRequest); + } + } + + public void addPendingReceiptRequest(ReceiptRequest receiptRequest) { + this.pendingReceiptRequests.add(receiptRequest); + } + public boolean isLegacy() { if (conversation == null || conversation.getMode() == Conversation.MODE_SINGLE) { return account.getXmppConnection().getFeatures().mamLegacy();