From 01a88c24a82c2cc0817d01ecba1dd0ba991932fd Mon Sep 17 00:00:00 2001 From: JC Brand Date: Thu, 3 May 2018 14:50:27 +0200 Subject: [PATCH] Refetch avatar when occupant's photo hash has changed --- src/converse-muc.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/converse-muc.js b/src/converse-muc.js index 6a6f8a080..9350b6e57 100644 --- a/src/converse-muc.js +++ b/src/converse-muc.js @@ -783,12 +783,13 @@ }, parsePresence (pres) { - const id = Strophe.getResourceFromJid(pres.getAttribute("from")); - const data = { - 'nick': id, - 'type': pres.getAttribute("type"), - 'states': [] - }; + const from = pres.getAttribute("from"), + data = { + 'from': from, + 'nick': Strophe.getResourceFromJid(from), + 'type': pres.getAttribute("type"), + 'states': [] + }; _.each(pres.childNodes, function (child) { switch (child.nodeName) { case "status": @@ -990,6 +991,20 @@ this.set(_.extend({ 'id': _converse.connection.getUniqueId(), }, attributes)); + + this.on('change:image_hash', this.onAvatarChanged, this); + }, + + onAvatarChanged () { + this.avatar = _converse.avatars.findWhere({ + 'muc_jid': this.get('from') + }); + if (!this.avatar) { return; } + + const hash = this.get('image_hash'); + if (hash && this.avatar.get('image_hash') !== hash) { + _converse.api.vcard.update(this.avatar); + } } });