From ac9f7c7210a978623ef61a7d194fef061abdc918 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 16 Mar 2021 10:22:52 +0100 Subject: [PATCH] kill pending queries when archiving conversation (cherry picked from commit 8764d11ccedf247adf825318545b9ccf39115824) --- .../services/MessageArchiveService.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index 309cbdaf9..a429062da 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -18,11 +18,11 @@ import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.ReceiptRequest; import eu.siacs.conversations.generator.AbstractGenerator; import eu.siacs.conversations.xml.Element; +import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.OnAdvancedStreamFeaturesLoaded; import eu.siacs.conversations.xmpp.mam.MamReference; import eu.siacs.conversations.xmpp.stanzas.IqPacket; import eu.siacs.conversations.xmpp.stanzas.MessagePacket; -import eu.siacs.conversations.xmpp.Jid; public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { @@ -211,7 +211,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } void executePendingQueries(final Account account) { - List pending = new ArrayList<>(); + final List pending = new ArrayList<>(); synchronized (this.pendingQueries) { for (Iterator iterator = this.pendingQueries.iterator(); iterator.hasNext(); ) { Query query = iterator.next(); @@ -391,8 +391,17 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } } - void kill(Conversation conversation) { + void kill(final Conversation conversation) { final ArrayList toBeKilled = new ArrayList<>(); + synchronized (this.pendingQueries) { + for (final Iterator iterator = this.pendingQueries.iterator(); iterator.hasNext(); ) { + final Query query = iterator.next(); + if (query.getConversation() == conversation) { + iterator.remove(); + Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": killed pending MAM query for archived conversation"); + } + } + } synchronized (this.queries) { for (final Query q : queries) { if (q.conversation == conversation) { @@ -400,7 +409,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } } } - for (Query q : toBeKilled) { + for (final Query q : toBeKilled) { kill(q); } }