Просмотр исходного кода

Store MUC avatars globally, not per chatroom

This allows us to cache them for longer.
JC Brand 7 лет назад
Родитель
Сommit
31982aab0b
3 измененных файлов с 12 добавлено и 19 удалено
  1. 2 1
      CHANGES.md
  2. 2 4
      src/converse-chatboxes.js
  3. 8 14
      src/converse-muc.js

+ 2 - 1
CHANGES.md

@@ -18,8 +18,9 @@
 
 
 ## UI changes
 ## UI changes
 
 
+- #956 Conversation pane should show my own identity in pane header
 - The UI is now based on Bootstrap4 and Flexbox is used extensively.
 - The UI is now based on Bootstrap4 and Flexbox is used extensively.
-- #956 Conversation pane should show my own identity in pane header 
+- User Avatars are now shown in chat messages.
 
 
 ## Configuration changes 
 ## Configuration changes 
 
 

+ 2 - 4
src/converse-chatboxes.js

@@ -88,11 +88,9 @@
 
 
                 initialize () {
                 initialize () {
                     if (this.get('type') === 'groupchat') {
                     if (this.get('type') === 'groupchat') {
-                        this.avatar = this.collection.chatbox.avatars.findWhere({'muc_jid': this.get('from')});
+                        this.avatar = _converse.avatars.findWhere({'muc_jid': this.get('from')});
                         if (_.isNil(this.avatar)) {
                         if (_.isNil(this.avatar)) {
-                            this.avatar = this.collection.chatbox.avatars.create({
-                                'muc_jid': this.get('from')
-                            });
+                            this.avatar = _converse.avatars.create({'muc_jid': this.get('from')});
                         }
                         }
                     }
                     }
 
 

+ 8 - 14
src/converse-muc.js

@@ -188,12 +188,6 @@
                     this.occupants.browserStorage = new Backbone.BrowserStorage.session(
                     this.occupants.browserStorage = new Backbone.BrowserStorage.session(
                         b64_sha1(`converse.occupants-${_converse.bare_jid}${this.get('jid')}`)
                         b64_sha1(`converse.occupants-${_converse.bare_jid}${this.get('jid')}`)
                     );
                     );
-                    this.avatars = new _converse.Avatars();
-                    this.avatars.browserStorage = new Backbone.BrowserStorage.session(
-                        b64_sha1(`converse.avatars-${_converse.bare_jid}${this.get('jid')}`)
-                    );
-                    this.avatars.fetch();
-
                     this.registerHandlers();
                     this.registerHandlers();
                     this.on('change:chat_state', this.sendChatState, this);
                     this.on('change:chat_state', this.sendChatState, this);
                 },
                 },
@@ -288,14 +282,6 @@
                      *  (String) exit_msg: Optional message to indicate your
                      *  (String) exit_msg: Optional message to indicate your
                      *      reason for leaving.
                      *      reason for leaving.
                      */
                      */
-                    if (_converse.connection.mock) {
-                        // Clear for tests, but keep otherwise.
-                        // We can only get avatars for current occupants in a
-                        // room, so we'd rather cache avatars in the hopes of
-                        // having more hits.
-                        this.avatars.browserStorage._clear();
-                        this.avatars.reset();
-                    }
                     this.occupants.browserStorage._clear();
                     this.occupants.browserStorage._clear();
                     this.occupants.reset();
                     this.occupants.reset();
                     if (_converse.connection.connected) {
                     if (_converse.connection.connected) {
@@ -1164,6 +1150,14 @@
             }
             }
 
 
             /************************ BEGIN Event Handlers ************************/
             /************************ BEGIN Event Handlers ************************/
+            _converse.api.listen.on('pluginsInitialized', () => {
+                _converse.avatars = new _converse.Avatars();
+                _converse.avatars.browserStorage = new Backbone.BrowserStorage.local(
+                    b64_sha1(`converse.avatars-${_converse.bare_jid}`)
+                );
+                _converse.avatars.fetch({'silent': true});
+            });
+
             _converse.on('addClientFeatures', () => {
             _converse.on('addClientFeatures', () => {
                 if (_converse.allow_muc) {
                 if (_converse.allow_muc) {
                     _converse.connection.disco.addFeature(Strophe.NS.MUC);
                     _converse.connection.disco.addFeature(Strophe.NS.MUC);