Browse Source

Send presence status change to all connected MUCs

Fixes #2725
JC Brand 3 years ago
parent
commit
ed63902ac1
2 changed files with 18 additions and 1 deletions
  1. 1 0
      CHANGES.md
  2. 17 1
      src/headless/plugins/status/api.js

+ 1 - 0
CHANGES.md

@@ -12,6 +12,7 @@
 - #1419: Clicking on avatar should show bigger version
 - #2647: Singleton mode doesn't work
 - #2704: Send button doesn't work in a multi-user chat
+- #2725: Send new presence status to all connected MUCs
 
 - Emit a `change` event when a configuration setting changes
 - 3 New configuration settings:

+ 17 - 1
src/headless/plugins/status/api.js

@@ -18,7 +18,9 @@ export default {
          */
         async send (type, to, status, child_nodes) {
             await api.waitUntil('statusInitialized');
-            const presence = await _converse.xmppstatus.constructPresence(type, to, status);
+
+            const model= _converse.xmppstatus
+            const presence = await model.constructPresence(type, to, status);
             if (child_nodes) {
                 if (!Array.isArray(child_nodes)) {
                     child_nodes = [child_nodes];
@@ -26,6 +28,20 @@ export default {
                 child_nodes.map(c => c?.tree() ?? c).forEach(c => presence.cnode(c).up());
             }
             api.send(presence);
+
+            if (['away', 'chat', 'dnd', 'online', 'xa', undefined].includes(type)) {
+                const mucs = await api.rooms.get();
+                mucs.forEach(async muc => {
+                    const presence = await model.constructPresence(type, muc.getRoomJIDAndNick(), status);
+                    if (child_nodes) {
+                        if (!Array.isArray(child_nodes)) {
+                            child_nodes = [child_nodes];
+                        }
+                        child_nodes.map(c => c?.tree() ?? c).forEach(c => presence.cnode(c).up());
+                    }
+                    api.send(presence);
+                });
+            }
         }
     },