remember mds display state until after mam catchup

This commit is contained in:
Daniel Gultsch 2024-03-27 14:11:20 +01:00
parent dd73b01ab1
commit 6b37b6377b
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
3 changed files with 22 additions and 6 deletions

View file

@ -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);
}

View file

@ -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);
}
}
}
}

View file

@ -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());