From 5d30742a1312372ab77368d713ebd950470e349a Mon Sep 17 00:00:00 2001 From: kosyak Date: Fri, 15 Sep 2023 16:14:32 +0200 Subject: [PATCH] fix message archive issues --- .../conversations/parser/MessageParser.java | 4 ++ .../services/MessageArchiveService.java | 4 ++ .../services/XmppConnectionService.java | 39 ++++++++++++------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index d081419aa..588f081b7 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -471,6 +471,10 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece nextCounterpart = counterpart; } + if (nextCounterpart != null && mXmppConnectionService.checkIsArchived(account, counterpart.asBareJid(), nextCounterpart)) { + return; + } + if ((body != null || pgpEncrypted != null || (axolotlEncrypted != null && axolotlEncrypted.hasChild("payload")) || oobUrl != null) && !isMucStatusMessage) { final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.asBareJid(), null, conversationIsProbablyMuc, nextCounterpart != null, false, nextCounterpart); final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI; diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index e74af3773..10cfdcb04 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -182,6 +182,10 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } public Query query(Conversation conversation, MamReference start, long end, boolean allowCatchup) { + if (conversation.getNextCounterpart() != null) { + return null; + } + synchronized (this.queries) { final Query query; final MamReference startActual = MamReference.max(start, mXmppConnectionService.getAutomaticMessageDeletionDate()); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 60a2c0631..bd814779b 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2170,9 +2170,7 @@ public class XmppConnectionService extends Service { if (messages.size() > 0) { conversation.addAll(0, messages); callback.onMoreMessagesLoaded(messages.size(), conversation); - } else if ( - conversation.getNextCounterpart() == null - && conversation.hasMessagesLeftOnServer() + } else if (conversation.hasMessagesLeftOnServer() && account.isOnlineAndConnected() && conversation.getLastClearHistory().getTimestamp() == 0) { final boolean mamAvailable; @@ -2290,6 +2288,17 @@ public class XmppConnectionService extends Service { } return false; } + + public boolean checkIsArchived(Account account, Jid jid, Jid counterpart) { + Conversation conversation = find(account, jid, counterpart); + if (conversation != null) { + return false; + } + conversation = databaseBackend.findConversation(account, jid, counterpart); + + return conversation != null && conversation.getStatus() == Conversation.STATUS_ARCHIVED; + } + public Conversation findOrCreateConversation(final Account account, final Jid jid, final MessageArchiveService.Query query, final boolean muc, final boolean joinAfterCreate, final boolean async, Jid counterpart) { synchronized (this.conversations) { Conversation conversation = find(account, jid, counterpart); @@ -2382,20 +2391,22 @@ public class XmppConnectionService extends Service { synchronized (this.conversations) { getMessageArchiveService().kill(conversation); if (conversation.getMode() == Conversation.MODE_MULTI) { - if (conversation.getAccount().getStatus() == Account.State.ONLINE) { - final Bookmark bookmark = conversation.getBookmark(); - if (maySynchronizeWithBookmarks && bookmark != null && synchronizeWithBookmarks()) { - if (conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) { - Account account = bookmark.getAccount(); - bookmark.setConversation(null); - deleteBookmark(account, bookmark); - } else if (bookmark.autojoin()) { - bookmark.setAutojoin(false); - createBookmark(bookmark.getAccount(), bookmark); + if (conversation.getNextCounterpart() == null) { + if (conversation.getAccount().getStatus() == Account.State.ONLINE) { + final Bookmark bookmark = conversation.getBookmark(); + if (maySynchronizeWithBookmarks && bookmark != null && synchronizeWithBookmarks()) { + if (conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) { + Account account = bookmark.getAccount(); + bookmark.setConversation(null); + deleteBookmark(account, bookmark); + } else if (bookmark.autojoin()) { + bookmark.setAutojoin(false); + createBookmark(bookmark.getAccount(), bookmark); + } } } + leaveMuc(conversation); } - leaveMuc(conversation); } else { if (conversation.getContact().getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) { stopPresenceUpdatesTo(conversation.getContact());