changeset 2463:65a6d2496504

plugin identity: return resource for MUC room occupants' nicks + added avatar and avatar_basename.
author Goffi <goffi@goffi.org>
date Wed, 03 Jan 2018 00:20:21 +0100
parents 2cad04f38bac
children 8788c217a49e
files src/plugins/plugin_misc_identity.py
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_identity.py	Wed Jan 03 00:18:31 2018 +0100
+++ b/src/plugins/plugin_misc_identity.py	Wed Jan 03 00:20:21 2018 +0100
@@ -20,10 +20,12 @@
 
 from sat.core.i18n import _
 from sat.core.constants import Const as C
+from sat.core import exceptions
 from sat.core.log import getLogger
 log = getLogger(__name__)
 from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
+import os.path
 
 
 PLUGIN_INFO = {
@@ -69,11 +71,20 @@
         roster_item = yield client.roster.getItem(jid_.userhostJID())
         if roster_item is not None and roster_item.name:
             id_data[u'nick'] = roster_item.name
+        elif jid_.resource and self._v.isRoom(client, jid_):
+            id_data[u'nick'] = jid_.resource
         else:
-            # then vcard
+            # and finally then vcard
             nick = yield self._v.getNick(client, jid_)
             id_data[u'nick'] = nick if nick else jid_.user.capitalize()
 
+        try:
+            avatar_path = id_data[u'avatar'] = yield self._v.getAvatar(client, jid_, cache_only=False)
+        except exceptions.NotFound:
+            pass
+        else:
+            id_data[u'avatar_basename'] = os.path.basename(avatar_path)
+
         defer.returnValue(id_data)
 
     def _setIdentity(self, id_data, profile):