Store MUC avatars globally, not per chatroom

This allows us to cache them for longer.
This commit is contained in:
JC Brand 2018-05-01 18:29:04 +02:00
parent 53f5627b72
commit 31982aab0b
3 changed files with 12 additions and 19 deletions

View File

@ -18,8 +18,9 @@
## 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.
- #956 Conversation pane should show my own identity in pane header
- User Avatars are now shown in chat messages.
## Configuration changes

View File

@ -88,11 +88,9 @@
initialize () {
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)) {
this.avatar = this.collection.chatbox.avatars.create({
'muc_jid': this.get('from')
});
this.avatar = _converse.avatars.create({'muc_jid': this.get('from')});
}
}

View File

@ -188,12 +188,6 @@
this.occupants.browserStorage = new Backbone.BrowserStorage.session(
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.on('change:chat_state', this.sendChatState, this);
},
@ -288,14 +282,6 @@
* (String) exit_msg: Optional message to indicate your
* 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.reset();
if (_converse.connection.connected) {
@ -1164,6 +1150,14 @@
}
/************************ 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', () => {
if (_converse.allow_muc) {
_converse.connection.disco.addFeature(Strophe.NS.MUC);