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; 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) { 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 Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.asBareJid(), null, conversationIsProbablyMuc, nextCounterpart != null, false, nextCounterpart);
final boolean conversationMultiMode = conversation.getMode() == Conversation.MODE_MULTI; 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) { public Query query(Conversation conversation, MamReference start, long end, boolean allowCatchup) {
if (conversation.getNextCounterpart() != null) {
return null;
}
synchronized (this.queries) { synchronized (this.queries) {
final Query query; final Query query;
final MamReference startActual = MamReference.max(start, mXmppConnectionService.getAutomaticMessageDeletionDate()); final MamReference startActual = MamReference.max(start, mXmppConnectionService.getAutomaticMessageDeletionDate());

View file

@ -2170,9 +2170,7 @@ public class XmppConnectionService extends Service {
if (messages.size() > 0) { if (messages.size() > 0) {
conversation.addAll(0, messages); conversation.addAll(0, messages);
callback.onMoreMessagesLoaded(messages.size(), conversation); callback.onMoreMessagesLoaded(messages.size(), conversation);
} else if ( } else if (conversation.hasMessagesLeftOnServer()
conversation.getNextCounterpart() == null
&& conversation.hasMessagesLeftOnServer()
&& account.isOnlineAndConnected() && account.isOnlineAndConnected()
&& conversation.getLastClearHistory().getTimestamp() == 0) { && conversation.getLastClearHistory().getTimestamp() == 0) {
final boolean mamAvailable; final boolean mamAvailable;
@ -2290,6 +2288,17 @@ public class XmppConnectionService extends Service {
} }
return false; 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) { 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) { synchronized (this.conversations) {
Conversation conversation = find(account, jid, counterpart); Conversation conversation = find(account, jid, counterpart);
@ -2382,20 +2391,22 @@ public class XmppConnectionService extends Service {
synchronized (this.conversations) { synchronized (this.conversations) {
getMessageArchiveService().kill(conversation); getMessageArchiveService().kill(conversation);
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
if (conversation.getAccount().getStatus() == Account.State.ONLINE) { if (conversation.getNextCounterpart() == null) {
final Bookmark bookmark = conversation.getBookmark(); if (conversation.getAccount().getStatus() == Account.State.ONLINE) {
if (maySynchronizeWithBookmarks && bookmark != null && synchronizeWithBookmarks()) { final Bookmark bookmark = conversation.getBookmark();
if (conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) { if (maySynchronizeWithBookmarks && bookmark != null && synchronizeWithBookmarks()) {
Account account = bookmark.getAccount(); if (conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) {
bookmark.setConversation(null); Account account = bookmark.getAccount();
deleteBookmark(account, bookmark); bookmark.setConversation(null);
} else if (bookmark.autojoin()) { deleteBookmark(account, bookmark);
bookmark.setAutojoin(false); } else if (bookmark.autojoin()) {
createBookmark(bookmark.getAccount(), bookmark); bookmark.setAutojoin(false);
createBookmark(bookmark.getAccount(), bookmark);
}
} }
} }
leaveMuc(conversation);
} }
leaveMuc(conversation);
} else { } else {
if (conversation.getContact().getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) { if (conversation.getContact().getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
stopPresenceUpdatesTo(conversation.getContact()); stopPresenceUpdatesTo(conversation.getContact());