From 07129f103078153aa19150c08cb6d16b5fa12283 Mon Sep 17 00:00:00 2001
From: Xavi Ferrer <xavi@delape.net>
Date: Tue, 3 Nov 2020 18:24:11 +0100
Subject: [PATCH] prevent self messages from triggering unreadStatus or
 notifications

---
 src/plugins/converse-rai.js | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/plugins/converse-rai.js b/src/plugins/converse-rai.js
index 6b28cd2..a4adbad 100644
--- a/src/plugins/converse-rai.js
+++ b/src/plugins/converse-rai.js
@@ -152,17 +152,32 @@
 
 	// Listen for incoming RAI from the server
         _converse.connection.addHandler(function (message) {
-            message.querySelectorAll('activity').forEach(function (activity)
-            {
-                if (activity && activity.namespaceURI == "xmpp:prosody.im/protocol/rai")
-                {
-                    const jid = activity.textContent;
-                    setUnreadStatus(jid, true);
-                    emitNotification(jid);
+            const from_jid = message.attributes.from?.nodevalue
+            const room_jid = from_jid?.split("/")[0]
+            const room = '';
+            let ignore = false;
+            for (let i = 0; i < _converse.chatboxes.models.length; i++){
+                if(_converse.chatboxes.models[i].id === room_jid){
+                    room = _converse.chatboxes.models[i].id;
+                    break;
                 }
-            });
-
-            return true;
+            }
+            if (room && from_jid && room_jid){
+                if (from_jid === room_jid+'/'+room.get('nick')){
+                    ignore = true;
+                }
+            }
+            if(message && !ignore)
+                message.querySelectorAll('activity').forEach(function (activity)
+                {
+                    if (activity && activity.namespaceURI == "xmpp:prosody.im/protocol/rai")
+                    {
+                        const jid = activity.textContent;
+                        setUnreadStatus(jid, true);
+                        emitNotification(jid);
+                    }
+                });
+                return true;
         }, null, 'message');
     }
 
-- 
GitLab