From 6b37b6377bd77dd57364122f884b7bf04dac4234 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 27 Mar 2024 14:11:20 +0100 Subject: [PATCH] remember mds display state until after mam catchup --- .../eu/siacs/conversations/entities/Conversation.java | 9 +++++++++ .../conversations/services/MessageArchiveService.java | 10 +++++++++- .../conversations/services/XmppConnectionService.java | 9 ++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 587bfc496..223a48efa 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -85,6 +85,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl private ChatState mOutgoingChatState = Config.DEFAULT_CHAT_STATE; private ChatState mIncomingChatState = Config.DEFAULT_CHAT_STATE; private String mFirstMamReference = null; + private String displayState = null; public Conversation(final String name, final Account account, final Jid contactJid, final int mode) { @@ -1121,6 +1122,14 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return getName().toString(); } + public void setDisplayState(final String stanzaId) { + this.displayState = stanzaId; + } + + public String getDisplayState() { + return this.displayState; + } + public interface OnMessageFound { void onMessageFound(final Message message); } diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index e74af3773..afa7f79ef 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -282,10 +282,18 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { if (conversation != null) { conversation.sort(); conversation.setHasMessagesLeftOnServer(!done); + final var displayState = conversation.getDisplayState(); + if (displayState != null) { + mXmppConnectionService.markReadUpToStanzaId(conversation, displayState); + } } else { - for (Conversation tmp : this.mXmppConnectionService.getConversations()) { + for (final Conversation tmp : this.mXmppConnectionService.getConversations()) { if (tmp.getAccount() == query.getAccount()) { tmp.sort(); + final var displayState = tmp.getDisplayState(); + if (displayState != null) { + mXmppConnectionService.markReadUpToStanzaId(tmp, displayState); + } } } } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index bd9363696..a581926b8 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1952,13 +1952,13 @@ public class XmppConnectionService extends Service { if (jid == null) { return; } - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": processing mds item for " + jid); final Element displayed = item.findChild("displayed", Namespace.MDS_DISPLAYED); final Element stanzaId = displayed == null ? null : displayed.findChild("stanza-id", Namespace.STANZA_IDS); final String id = stanzaId == null ? null : stanzaId.getAttribute("id"); final Conversation conversation = find(account, jid); if (id != null && conversation != null) { + conversation.setDisplayState(id); markReadUpToStanzaId(conversation, id); } } @@ -3381,7 +3381,7 @@ public class XmppConnectionService extends Service { new Thread(() -> onMediaLoaded.onMediaLoaded(fileBackend.convertToAttachments(databaseBackend.getRelativeFilePaths(account, jid, limit)))).start(); } - public void persistSelfNick(MucOptions.User self) { + public void persistSelfNick(final MucOptions.User self) { final Conversation conversation = self.getConversation(); final boolean tookProposedNickFromBookmark = conversation.getMucOptions().isTookProposedNickFromBookmark(); Jid full = self.getFullJid(); @@ -3393,11 +3393,10 @@ public class XmppConnectionService extends Service { final Bookmark bookmark = conversation.getBookmark(); final String bookmarkedNick = bookmark == null ? null : bookmark.getNick(); - if (bookmark != null && (tookProposedNickFromBookmark || TextUtils.isEmpty(bookmarkedNick)) && !full.getResource().equals(bookmarkedNick)) { + if (bookmark != null && (tookProposedNickFromBookmark || Strings.isNullOrEmpty(bookmarkedNick)) && !full.getResource().equals(bookmarkedNick)) { final Account account = conversation.getAccount(); final String defaultNick = MucOptions.defaultNick(account); - if (TextUtils.isEmpty(bookmarkedNick) && full.getResource().equals(defaultNick)) { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": do not overwrite empty bookmark nick with default nick for " + conversation.getJid().asBareJid()); + if (Strings.isNullOrEmpty(bookmarkedNick) && full.getResource().equals(defaultNick)) { return; } Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": persist nick '" + full.getResource() + "' into bookmark for " + conversation.getJid().asBareJid());