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) { } else if (mam.getWith()!=null) {
data.put("with", mam.getWith().toString()); data.put("with", mam.getWith().toString());
} }
if (mam.getStart() != 0) { final long start = mam.getStart();
data.put("start", getTimestamp(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(); data.submit();
query.addChild(data); query.addChild(data);
Element set = query.addChild("set", "http://jabber.org/protocol/rsm"); 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")) boolean checkForDuplicates = (isTypeGroupChat && packet.hasChild("delay", "urn:xmpp:delay"))
|| message.getType() == Message.TYPE_PRIVATE || message.getType() == Message.TYPE_PRIVATE
|| message.getServerMsgId() != null; || message.getServerMsgId() != null
|| (query == null && mXmppConnectionService.getMessageArchiveService().isCatchupInProgress(conversation));
if (checkForDuplicates) { if (checkForDuplicates) {
final Message duplicate = conversation.findDuplicateMessage(message); final Message duplicate = conversation.findDuplicateMessage(message);
if (duplicate != null) { if (duplicate != null) {

View file

@ -12,6 +12,7 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Conversational;
import eu.siacs.conversations.entities.ReceiptRequest; import eu.siacs.conversations.entities.ReceiptRequest;
import eu.siacs.conversations.generator.AbstractGenerator; import eu.siacs.conversations.generator.AbstractGenerator;
import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.xml.Namespace;
@ -58,9 +59,9 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
this.query(conversation, startCatchup, true); this.query(conversation, startCatchup, true);
} }
} }
query = new Query(account, new MamReference(startCatchup), endCatchup); query = new Query(account, new MamReference(startCatchup), 0);
} else { } else {
query = new Query(account, mamReference, endCatchup); query = new Query(account, mamReference, 0);
} }
synchronized (this.queries) { synchronized (this.queries) {
this.queries.add(query); this.queries.add(query);
@ -72,12 +73,12 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
if (conversation.getLastMessageTransmitted().getTimestamp() < 0 && conversation.countMessages() == 0) { if (conversation.getLastMessageTransmitted().getTimestamp() < 0 && conversation.countMessages() == 0) {
query(conversation, query(conversation,
new MamReference(0), new MamReference(0),
System.currentTimeMillis(), 0,
true); true);
} else { } else {
query(conversation, query(conversation,
conversation.getLastMessageTransmitted(), conversation.getLastMessageTransmitted(),
System.currentTimeMillis(), 0,
true); true);
} }
} }
@ -136,7 +137,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
query = new Query(conversation, startActual, end, false); query = new Query(conversation, startActual, end, false);
} }
} }
if (start.greaterThan(end)) { if (end != 0 && start.greaterThan(end)) {
return null; return null;
} }
this.queries.add(query); this.queries.add(query);
@ -224,6 +225,20 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
return false; 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) { boolean queryInProgress(Conversation conversation, XmppConnectionService.OnMoreMessagesLoaded callback) {
synchronized (this.queries) { synchronized (this.queries) {
for (Query query : queries) { for (Query query : queries) {
@ -541,8 +556,10 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
builder.append(", start="); builder.append(", start=");
builder.append(AbstractGenerator.getTimestamp(this.start)); builder.append(AbstractGenerator.getTimestamp(this.start));
} }
if (this.end != 0) {
builder.append(", end="); builder.append(", end=");
builder.append(AbstractGenerator.getTimestamp(this.end)); builder.append(AbstractGenerator.getTimestamp(this.end));
}
builder.append(", order=").append(pagingOrder.toString()); builder.append(", order=").append(pagingOrder.toString());
if (this.reference != null) { if (this.reference != null) {
if (this.pagingOrder == PagingOrder.NORMAL) { if (this.pagingOrder == PagingOrder.NORMAL) {