changeset 1392:c7082457d03f

memory, plugin XEP-0045: getMainResource returns None when asking a MUC entity + fixes /whois on a MUC (bare) entity
author souliane <souliane@mailoo.org>
date Wed, 25 Mar 2015 15:28:02 +0100
parents 1276e6a0716b
children 50d5d6325f62
files src/memory/memory.py src/plugins/plugin_xep_0045.py
diffstat 2 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/memory/memory.py	Wed Mar 25 15:21:17 2015 +0100
+++ b/src/memory/memory.py	Wed Mar 25 15:28:02 2015 +0100
@@ -514,6 +514,11 @@
         """
         if entity_jid.resource:
             raise ValueError("getMainResource must be used with a bare jid (got {})".format(entity_jid))
+        try:
+            if self.host.plugins["XEP-0045"].isRoom(entity_jid, profile_key):
+                return None  # MUC rooms have no main resource
+        except KeyError:  # plugin not found
+            pass
         resources = self.getAllResources(entity_jid, profile_key)
         priority_resources = []
         for resource in resources:
--- a/src/plugins/plugin_xep_0045.py	Wed Mar 25 15:21:17 2015 +0100
+++ b/src/plugins/plugin_xep_0045.py	Wed Mar 25 15:28:02 2015 +0100
@@ -153,6 +153,16 @@
         self.host.bridge.newAlert(mess, D_("Group chat error"), "ERROR", profile)
         raise failure
 
+    def isRoom(self, entity_bare, profile_key):
+        """Tell if a bare entity is a MUC room.
+
+        @param entity_bare (jid.JID): bare entity
+        @param profile_key (unicode): %(doc_profile_key)s
+        @return bool
+        """
+        profile = self.host.memory.getProfileName(profile_key)
+        return entity_bare in self.clients[profile].joined_rooms
+
     def getRoomsJoined(self, profile_key=C.PROF_KEY_NONE):
         """Return room where user is"""
         profile = self.host.memory.getProfileName(profile_key)
@@ -615,6 +625,8 @@
         if target_jid.userhostJID() not in self.clients[profile].joined_rooms:
             log.warning(_("This room has not been joined"))
             return
+        if not target_jid.resource:
+            return
         user = self.clients[profile].joined_rooms[target_jid.userhostJID()].getUser(target_jid.resource)
         whois_msg.append(_("Nickname: %s") % user.nick)
         if user.entity: