From 543d1f689be496f4d107f39c67c92a47e7869e0a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 11 May 2018 11:16:29 +0200 Subject: [PATCH] do not use end in catchup mam queries --- .../conversations/generator/IqGenerator.java | 10 ++++-- .../conversations/parser/MessageParser.java | 3 +- .../services/MessageArchiveService.java | 31 ++++++++++++++----- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index 5cd0f9b54..304e962b3 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -257,10 +257,14 @@ public class IqGenerator extends AbstractGenerator { } else if (mam.getWith()!=null) { data.put("with", mam.getWith().toString()); } - if (mam.getStart() != 0) { - data.put("start", getTimestamp(mam.getStart())); + final long start = mam.getStart(); + final long end = mam.getEnd(); + if (start != 0) { + data.put("start", getTimestamp(start)); + } + if (end != 0) { + data.put("end", getTimestamp(end)); } - data.put("end", getTimestamp(mam.getEnd())); data.submit(); query.addChild(data); Element set = query.addChild("set", "http://jabber.org/protocol/rsm"); diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 9e3ed29fb..3114f0d14 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -519,7 +519,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece boolean checkForDuplicates = (isTypeGroupChat && packet.hasChild("delay", "urn:xmpp:delay")) || message.getType() == Message.TYPE_PRIVATE - || message.getServerMsgId() != null; + || message.getServerMsgId() != null + || (query == null && mXmppConnectionService.getMessageArchiveService().isCatchupInProgress(conversation)); if (checkForDuplicates) { final Message duplicate = conversation.findDuplicateMessage(message); if (duplicate != null) { diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index 2ae1c8b2b..10f643909 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -12,6 +12,7 @@ import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.ReceiptRequest; import eu.siacs.conversations.generator.AbstractGenerator; import eu.siacs.conversations.xml.Namespace; @@ -58,9 +59,9 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { this.query(conversation, startCatchup, true); } } - query = new Query(account, new MamReference(startCatchup), endCatchup); + query = new Query(account, new MamReference(startCatchup), 0); } else { - query = new Query(account, mamReference, endCatchup); + query = new Query(account, mamReference, 0); } synchronized (this.queries) { this.queries.add(query); @@ -72,12 +73,12 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { if (conversation.getLastMessageTransmitted().getTimestamp() < 0 && conversation.countMessages() == 0) { query(conversation, new MamReference(0), - System.currentTimeMillis(), + 0, true); } else { query(conversation, conversation.getLastMessageTransmitted(), - System.currentTimeMillis(), + 0, true); } } @@ -136,7 +137,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { query = new Query(conversation, startActual, end, false); } } - if (start.greaterThan(end)) { + if (end != 0 && start.greaterThan(end)) { return null; } this.queries.add(query); @@ -224,6 +225,20 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { return false; } + public boolean isCatchupInProgress(Conversation conversation) { + synchronized (this.queries) { + for(Query query : queries) { + if (query.account == conversation.getAccount() && query.isCatchup()) { + final Jid with = query.getWith() == null ? null : query.getWith().asBareJid(); + if ((conversation.getMode() == Conversational.MODE_SINGLE && with == null) || (conversation.getJid().asBareJid().equals(with))) { + return true; + } + } + } + } + return false; + } + boolean queryInProgress(Conversation conversation, XmppConnectionService.OnMoreMessagesLoaded callback) { synchronized (this.queries) { for (Query query : queries) { @@ -541,8 +556,10 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { builder.append(", start="); builder.append(AbstractGenerator.getTimestamp(this.start)); } - builder.append(", end="); - builder.append(AbstractGenerator.getTimestamp(this.end)); + if (this.end != 0) { + builder.append(", end="); + builder.append(AbstractGenerator.getTimestamp(this.end)); + } builder.append(", order=").append(pagingOrder.toString()); if (this.reference != null) { if (this.pagingOrder == PagingOrder.NORMAL) {