make receipt handling work with out of order receipts

This commit is contained in:
Daniel Gultsch 2018-03-25 17:22:39 +02:00
parent 2e8cc12ada
commit fe8f0bd7f0
2 changed files with 17 additions and 4 deletions

View file

@ -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()));
}
}
}

View file

@ -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<ReceiptRequest> iterator = query.pendingReceiptRequests.iterator();
while (iterator.hasNext()) {
@ -360,7 +361,8 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
}
public class Query {
public HashSet<ReceiptRequest> pendingReceiptRequests = new HashSet<>();
private HashSet<ReceiptRequest> pendingReceiptRequests = new HashSet<>();
private HashSet<ReceiptRequest> 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();