[network/kaidan] src: Blocking: Avoid duplicate entries for already-blocked JIDs

Melvin Keskin <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 80b1c36880aec64f299508ac6819d8554e216a4b by Melvin Keskin, on behalf of Linus Jahn.
Committed on 06/08/2026 at 12:44.
Pushed by melvo into branch 'master'.

Blocking: Avoid duplicate entries for already-blocked JIDs

onJidsBlocked() appended every JID from an incoming block push to the model
and database unconditionally. The controller's own cached blocklist was kept
unique via makeUnique(). But the models were notified with the raw JIDs. Thus,
BlockingModel inserted a new row even for a JID that was already blocked.

As a result, blocking a JID that was already in the blocklist (e.g., a
duplicate block push from the server) made it appear twice in the list of
blocked JIDs.

This filters out JIDs that are already blocked before touching the database
and notifying the models, while keeping the blocklist sorted.

M  +15   -3    src/Blocking.cpp

https://invent.kde.org/network/kaidan/-/commit/80b1c36880aec64f299508ac6819d8554e216a4b

diff --git a/src/Blocking.cpp b/src/Blocking.cpp
index ac9b04ab7..641b30a4c 100644
--- a/src/Blocking.cpp
+++ b/src/Blocking.cpp
@@ -283,14 +283,26 @@ void BlockingController::onJidsBlocked(const QList<QString> &jids)
     Q_ASSERT(m_blocklist);
     Q_ASSERT(m_blocklist->source == Blocklist::Xmpp);
 
-    m_db->addBlockedJids(m_accountSettings->jid(), jids);
+    // Only handle JIDs that are not already blocked.
+    // Otherwise, the same JID would be added (and displayed) multiple times if the server sends a
+    // block push for a JID that is already in the blocklist (e.g., when it is blocked again).
+    auto newJids = filter(QList<QString>{jids}, [this](const QString &jid) {
+        return !m_blocklist->jids.contains(jid);
+    });
+    makeUnique(newJids);
+
+    if (newJids.isEmpty()) {
+        return;
+    }
+
+    m_db->addBlockedJids(m_accountSettings->jid(), newJids);
 
-    m_blocklist->jids.append(jids);
+    m_blocklist->jids.append(newJids);
     makeUnique(m_blocklist->jids);
 
     // handler
     for (auto *model : m_registeredModels) {
-        model->handleBlocked(jids);
+        model->handleBlocked(newJids);
     }
     Q_EMIT blocklistChanged();
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.