From e4128f1227832580702a53f8ce3909b1f378ef79 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 17 May 2018 20:47:00 +0200 Subject: do not use end in catchup mam queries --- .../de/pixart/messenger/generator/IqGenerator.java | 10 ++++--- .../de/pixart/messenger/parser/MessageParser.java | 3 ++- .../messenger/services/MessageArchiveService.java | 31 +++++++++++++++++----- 3 files changed, 33 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java index 5926d48d4..fbb47a2c6 100644 --- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java +++ b/src/main/java/de/pixart/messenger/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/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java index f09c82473..701dd860e 100644 --- a/src/main/java/de/pixart/messenger/parser/MessageParser.java +++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java @@ -629,7 +629,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/de/pixart/messenger/services/MessageArchiveService.java b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java index a20c7fc49..df376ab73 100644 --- a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java +++ b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java @@ -12,6 +12,7 @@ import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Conversation; +import de.pixart.messenger.entities.Conversational; import de.pixart.messenger.entities.ReceiptRequest; import de.pixart.messenger.generator.AbstractGenerator; import de.pixart.messenger.utils.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) { @@ -540,8 +555,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) { -- cgit v1.2.3