fix message archive issues

This commit is contained in:
kosyak 2023-09-15 16:14:32 +02:00
parent 6770f7de61
commit 5d30742a13
3 changed files with 33 additions and 14 deletions

View file

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

View file

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

View file

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