do not use end in catchup mam queries

This commit is contained in:
Daniel Gultsch 2018-05-11 11:16:29 +02:00
parent 170fbf0de3
commit 543d1f689b
3 changed files with 33 additions and 11 deletions

View file

@ -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");

View file

@ -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) {

View file

@ -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) {