From 47ad6bf5b548018cbbb7ba1c0b8d5fd922ba2611 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 24 Feb 2018 15:53:31 +0100 Subject: MAM: look at total count for completness. parse fin correctly --- .../de/pixart/messenger/entities/Conversation.java | 4 +-- .../de/pixart/messenger/parser/MessageParser.java | 2 +- .../messenger/services/MessageArchiveService.java | 29 +++++++++++++++------- .../pixart/messenger/ui/ConversationFragment.java | 4 +-- 4 files changed, 24 insertions(+), 15 deletions(-) (limited to 'src/main') diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 223e26dd2..b41805987 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -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); } } diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java index f0b804306..5a95c89bd 100644 --- a/src/main/java/de/pixart/messenger/parser/MessageParser.java +++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java @@ -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); } diff --git a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java index 277ede64d..8611bf873 100644 --- a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java +++ b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java @@ -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); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index a9bb9319f..e73f30211 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -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)); -- cgit v1.2.3