Browse Source

Bugfix. Make sure right occupants collection is used.

JC Brand 6 months ago
parent
commit
04f2ae7a34
1 changed files with 8 additions and 5 deletions
  1. 8 5
      src/headless/plugins/muc/message.js

+ 8 - 5
src/headless/plugins/muc/message.js

@@ -30,6 +30,10 @@ class MUCMessage extends Message {
         api.trigger('chatRoomMessageInitialized', this);
     }
 
+    get occupants () {
+        return (this.get('type') === 'chat') ? this.chatbox.collection : this.chatbox.occupants;
+    }
+
     getDisplayName () {
         return this.occupant?.getDisplayName() || this.get('nick');
     }
@@ -63,7 +67,7 @@ class MUCMessage extends Message {
     onOccupantRemoved () {
         this.stopListening(this.occupant);
         delete this.occupant;
-        this.listenTo(this.chatbox.occupants, 'add', this.onOccupantAdded);
+        this.listenTo(this.occupants, 'add', this.onOccupantAdded);
     }
 
     /**
@@ -102,10 +106,9 @@ class MUCMessage extends Message {
         } else {
             if (this.occupant) return;
 
-            const occupants = (this.get('type') === 'chat') ? this.chatbox.collection : this.chatbox.occupants;
             const nick = Strophe.getResourceFromJid(this.get('from'));
             const occupant_id = this.get('occupant_id');
-            this.occupant = nick || occupant_id ? occupants.findOccupant({ nick, occupant_id }) : null;
+            this.occupant = nick || occupant_id ? this.occupants.findOccupant({ nick, occupant_id }) : null;
 
             if (!this.occupant) {
                 const jid = this.get('from_real_jid');
@@ -114,7 +117,7 @@ class MUCMessage extends Message {
                     return;
                 }
 
-                this.occupant = this.chatbox.occupants.create({ nick, occupant_id, jid });
+                this.occupant = this.occupants.create({ nick, occupant_id, jid });
 
                 if (api.settings.get('muc_send_probes')) {
                     const jid = `${this.chatbox.get('jid')}/${nick}`;
@@ -130,7 +133,7 @@ class MUCMessage extends Message {
         this.trigger('occupant:add');
         this.listenTo(this.occupant, 'change', (changed) => this.trigger('occupant:change', changed));
         this.listenTo(this.occupant, 'destroy', this.onOccupantRemoved);
-        this.stopListening(this.chatbox.occupants, 'add', this.onOccupantAdded);
+        this.stopListening(this.occupants, 'add', this.onOccupantAdded);
 
         return this.occupant;
     }