changeset 1710:7226280e70da

plugin XEP-0054: use full jid to manage the card/avatar if the bare jid correspond to a MUC room
author Goffi <goffi@goffi.org>
date Tue, 01 Dec 2015 17:17:09 +0100
parents c47ba491a85a
children e5b569d0c2e7
files src/plugins/plugin_xep_0054.py
diffstat 1 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0054.py	Tue Dec 01 13:55:48 2015 +0100
+++ b/src/plugins/plugin_xep_0054.py	Tue Dec 01 17:17:09 2015 +0100
@@ -67,6 +67,7 @@
     "type": "XEP",
     "protocols": ["XEP-0054", "XEP-0153"],
     "dependencies": [],
+    "recommendations": ["XEP-0045"],
     "main": "XEP_0054",
     "handler": "yes",
     "description": _("""Implementation of vcard-temp""")
@@ -108,6 +109,17 @@
 
         return True
 
+    def isInRoom(self, entity_jid, profile):
+        """Tell if an full jid is a member of a room
+
+        @param entity_jid(jid.JID): full jid of the entity
+        @return (bool): True if the bare jid of the entity is a room jid
+        """
+        try:
+            return self.host.plugins['XEP-0045'].isRoom(entity_jid.userhostJID(), profile_key=profile)
+        except KeyError:
+            return False
+
     def _fillCachedValues(self, profile):
         #FIXME: this is really suboptimal, need to be reworked
         #       the current naive approach keeps a map between all jids of all profiles
@@ -140,7 +152,12 @@
         @param value(unicode): new value of the item
         @param profile(unicode): profile which received the update
         """
-        assert not jid_.resource # VCard are retrieved with bare jid
+        if jid_.resource:
+            if not self.isInRoom(jid_, profile):
+                # VCard are retrieved with bare jid
+                # but MUC room is a special case
+                jid_ = jid.userhostJID()
+
         self.host.memory.updateEntityData(jid_, name, value, profile_key=profile)
         if name in CACHED_DATA:
             jid_s = jid_.userhost()
@@ -154,7 +171,11 @@
         @param name: name of the value ('nick' or 'avatar')
         @param profile: %(doc_profile)s
         @return: wanted value or None"""
-        assert not entity_jid.resource # VCard are retrieved with bare jid
+        if entity_jid.resource:
+            if not self.isInRoom(entity_jid, profile):
+                # VCard are retrieved with bare jid
+                # but MUC room is a special case
+                entity_jid = jid.userhostJID()
         try:
             data = self.host.memory.getEntityData(entity_jid, [name], profile)
         except exceptions.UnknownEntityError:
@@ -363,8 +384,9 @@
         Check for avatar information, and get VCard if needed
         @param presend(domish.Element): <presence/> stanza
         """
-        # FIXME: doesn't manage MUC correctly
-        from_jid = jid.JID(presence['from']).userhostJID()
+        from_jid = jid.JID(presence['from'])
+        if from_jid.resource and not self.plugin_parent.isInRoom(from_jid, self.parent.profile):
+            from_jid = from_jid.userhostJID()
         #FIXME: wokkel's data_form should be used here
         try:
             x_elt = presence.elements(NS_VCARD_UPDATE, 'x').next()