Prechádzať zdrojové kódy

Store VCard JID on the groupchat message

for easier retrieval later and to work around MUC's inability to
retrieve VCards for users not in the MUC.
JC Brand 7 rokov pred
rodič
commit
63f659326b
1 zmenil súbory, kde vykonal 27 pridanie a 9 odobranie
  1. 27 9
      src/converse-chatboxes.js

+ 27 - 9
src/converse-chatboxes.js

@@ -110,17 +110,35 @@
                     }
                 },
 
-                setVCard () {
-                    if (this.get('type') === 'groupchat') {
-                        const chatbox = this.collection.chatbox,
-                              nick = Strophe.getResourceFromJid(this.get('from'));
-                        if (chatbox.get('nick') === nick) {
-                            this.vcard = _converse.xmppstatus.vcard;
-                        } else {
+                getVCardForChatroomOccupant () {
+                    const chatbox = this.collection.chatbox,
+                          nick = Strophe.getResourceFromJid(this.get('from'));
+
+                    if (chatbox.get('nick') === nick) {
+                        return _converse.xmppstatus.vcard;
+                    } else {
+                        let vcard;
+                        if (this.get('vcard_jid')) {
+                            vcard = _converse.vcards.findWhere({'jid': this.get('vcard_jid')});
+                        }
+                        if (!vcard) {
+                            let jid;
                             const occupant = chatbox.occupants.findWhere({'nick': nick});
-                            const jid = (occupant && occupant.get('jid')) ? occupant.get('jid') : this.get('from');
-                            this.vcard = _converse.vcards.findWhere({'jid': jid}) || _converse.vcards.create({'jid': jid});
+                            if (occupant && occupant.get('jid')) {
+                                jid = occupant.get('jid');
+                                this.save({'vcard_jid': jid}, {'silent': true});
+                            } else {
+                                jid = this.get('from');
+                            }
+                            vcard = _converse.vcards.findWhere({'jid': jid}) || _converse.vcards.create({'jid': jid});
                         }
+                        return vcard;
+                    }
+                },
+
+                setVCard () {
+                    if (this.get('type') === 'groupchat') {
+                        this.vcard = this.getVCardForChatroomOccupant();
                     } else {
                         const jid = this.get('from');
                         this.vcard = _converse.vcards.findWhere({'jid': jid}) || _converse.vcards.create({'jid': jid});