MAM: look at total count for completness. parse fin correctly
This commit is contained in:
parent
f81e5e471e
commit
7725cb8311
|
@ -955,9 +955,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prepend(Message message) {
|
public void prepend(int offset, Message message) {
|
||||||
synchronized (this.messages) {
|
synchronized (this.messages) {
|
||||||
this.messages.add(0,message);
|
this.messages.add(Math.min(offset,this.messages.size()),message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -631,7 +631,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query != null && query.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {
|
if (query != null && query.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {
|
||||||
conversation.prepend(message);
|
conversation.prepend(query.getActualInThisQuery(),message);
|
||||||
} else {
|
} else {
|
||||||
conversation.add(message);
|
conversation.add(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (packet.getType() == IqPacket.TYPE.RESULT && fin != null ) {
|
} else if (packet.getType() == IqPacket.TYPE.RESULT && fin != null ) {
|
||||||
processFin(fin);
|
processFin(query, fin);
|
||||||
} else if (packet.getType() == IqPacket.TYPE.RESULT && query.isLegacy()) {
|
} else if (packet.getType() == IqPacket.TYPE.RESULT && query.isLegacy()) {
|
||||||
//do nothing
|
//do nothing
|
||||||
} else {
|
} else {
|
||||||
|
@ -254,18 +254,15 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
public void processFinLegacy(Element fin, Jid from) {
|
public void processFinLegacy(Element fin, Jid from) {
|
||||||
Query query = findQuery(fin.getAttribute("queryid"));
|
Query query = findQuery(fin.getAttribute("queryid"));
|
||||||
if (query != null && query.validFrom(from)) {
|
if (query != null && query.validFrom(from)) {
|
||||||
processFin(fin);
|
processFin(query, fin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processFin(Element fin) {
|
private void processFin(Query query, Element fin) {
|
||||||
Query query = findQuery(fin.getAttribute("queryid"));
|
|
||||||
if (query == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
boolean complete = fin.getAttributeAsBoolean("complete");
|
boolean complete = fin.getAttributeAsBoolean("complete");
|
||||||
Element set = fin.findChild("set","http://jabber.org/protocol/rsm");
|
Element set = fin.findChild("set","http://jabber.org/protocol/rsm");
|
||||||
Element last = set == null ? null : set.findChild("last");
|
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 first = set == null ? null : set.findChild("first");
|
||||||
Element relevant = query.getPagingOrder() == PagingOrder.NORMAL ? last : first;
|
Element relevant = query.getPagingOrder() == PagingOrder.NORMAL ? last : first;
|
||||||
boolean abort = (!query.isCatchup() && query.getTotalCount() >= Config.PAGE_SIZE) || query.getTotalCount() >= Config.MAM_MAX_MESSAGES;
|
boolean abort = (!query.isCatchup() && query.getTotalCount() >= Config.PAGE_SIZE) || query.getTotalCount() >= Config.MAM_MAX_MESSAGES;
|
||||||
|
@ -273,9 +270,18 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
query.getConversation().setFirstMamReference(first == null ? null : first.getContent());
|
query.getConversation().setFirstMamReference(first == null ? null : first.getContent());
|
||||||
}
|
}
|
||||||
if (complete || relevant == null || abort) {
|
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);
|
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) {
|
if (query.isCatchup() && query.getActualMessageCount() > 0) {
|
||||||
mXmppConnectionService.getNotificationService().finishBacklog(true,query.getAccount());
|
mXmppConnectionService.getNotificationService().finishBacklog(true,query.getAccount());
|
||||||
}
|
}
|
||||||
|
@ -330,6 +336,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
public class Query {
|
public class Query {
|
||||||
private int totalCount = 0;
|
private int totalCount = 0;
|
||||||
private int actualCount = 0;
|
private int actualCount = 0;
|
||||||
|
private int actualInThisQuery = 0;
|
||||||
private long start;
|
private long start;
|
||||||
private long end;
|
private long end;
|
||||||
private String queryId;
|
private String queryId;
|
||||||
|
@ -453,6 +460,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void incrementActualMessageCount() {
|
public void incrementActualMessageCount() {
|
||||||
|
this.actualInThisQuery++;
|
||||||
this.actualCount++;
|
this.actualCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,6 +472,10 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
return this.actualCount;
|
return this.actualCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getActualInThisQuery() {
|
||||||
|
return this.actualInThisQuery;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean validFrom(Jid from) {
|
public boolean validFrom(Jid from) {
|
||||||
if (muc()) {
|
if (muc()) {
|
||||||
return getWith().equals(from);
|
return getWith().equals(from);
|
||||||
|
|
Loading…
Reference in a new issue