MAM: look at total count for completness. parse fin correctly

This commit is contained in:
Christian Schneppe 2018-02-24 15:53:31 +01:00
parent cd34002f7c
commit 47ad6bf5b5
4 changed files with 24 additions and 15 deletions

View file

@ -991,9 +991,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
}
}
public void prepend(Message message) {
public void prepend(int offset, Message message) {
synchronized (this.messages) {
this.messages.add(0, message);
this.messages.add(Math.min(offset, this.messages.size()), message);
}
}

View file

@ -626,7 +626,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
}
if (query != null && query.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {
conversation.prepend(message);
conversation.prepend(query.getActualInThisQuery(), message);
} else {
conversation.add(message);
}

View file

@ -184,7 +184,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
}
}
} else if (packet.getType() == IqPacket.TYPE.RESULT && fin != null) {
processFin(fin);
processFin(query, fin);
} else if (packet.getType() == IqPacket.TYPE.RESULT && query.isLegacy()) {
//do nothing
} else {
@ -254,18 +254,15 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
public void processFinLegacy(Element fin, Jid from) {
Query query = findQuery(fin.getAttribute("queryid"));
if (query != null && query.validFrom(from)) {
processFin(fin);
processFin(query, fin);
}
}
public void processFin(Element fin) {
Query query = findQuery(fin.getAttribute("queryid"));
if (query == null) {
return;
}
private void processFin(Query query, Element fin) {
boolean complete = fin.getAttributeAsBoolean("complete");
Element set = fin.findChild("set", "http://jabber.org/protocol/rsm");
Element last = set == null ? null : set.findChild("last");
String count = set == null ? null : set.findChildContent("count");
Element first = set == null ? null : set.findChild("first");
Element relevant = query.getPagingOrder() == PagingOrder.NORMAL ? last : first;
boolean abort = (!query.isCatchup() && query.getTotalCount() >= Config.PAGE_SIZE) || query.getTotalCount() >= Config.MAM_MAX_MESSAGES;
@ -273,9 +270,17 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
query.getConversation().setFirstMamReference(first == null ? null : first.getContent());
}
if (complete || relevant == null || abort) {
final boolean done = (complete || query.getActualMessageCount() == 0) && !query.isCatchup();
boolean done = !query.isCatchup();
if (count != null && !query.isCatchup()) {
try {
done = Integer.parseInt(count) <= query.getTotalCount();
} catch (NumberFormatException e) {
done = false;
}
}
done = done || (query.getActualMessageCount() == 0 && !query.isCatchup());
this.finalizeQuery(query, done);
Log.d(Config.LOGTAG, query.getAccount().getJid().toBareJid() + ": finished mam after " + query.getTotalCount() + "(" + query.getActualMessageCount() + ") messages. messages left=" + Boolean.toString(!done));
Log.d(Config.LOGTAG, query.getAccount().getJid().toBareJid() + ": finished mam after " + query.getTotalCount() + "(" + query.getActualMessageCount() + ") messages. messages left=" + Boolean.toString(!done) + " count=" + count);
if (query.isCatchup() && query.getActualMessageCount() > 0) {
mXmppConnectionService.getNotificationService().finishBacklog(true,query.getAccount());
}
@ -330,6 +335,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
public class Query {
private int totalCount = 0;
private int actualCount = 0;
private int actualInThisQuery = 0;
private long start;
private long end;
private String queryId;
@ -453,6 +459,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
}
public void incrementActualMessageCount() {
this.actualInThisQuery++;
this.actualCount++;
}
@ -464,6 +471,10 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
return this.actualCount;
}
public int getActualInThisQuery() {
return this.actualInThisQuery;
}
public boolean validFrom(Jid from) {
if (muc()) {
return getWith().equals(from);

View file

@ -1446,9 +1446,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (!ReadByMarker.contains(marker, addedMarkers)) {
addedMarkers.add(marker); //may be put outside this condition. set should do dedup anyway
MucOptions.User user = mucOptions.findUser(marker);
if (user != null && !users.contains(user)) {
shownMarkers.add(user);
}
shownMarkers.add(user);
}
}
final ReadByMarker markerForSender = ReadByMarker.from(messageList.get(i));