changeset 715:f47d7c09c60b

plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger
author souliane <souliane@mailoo.org>
date Tue, 19 Nov 2013 19:31:59 +0100
parents ecc5a5b34ee1
children 30eb49e4e05d
files src/plugins/plugin_xep_0045.py
diffstat 1 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0045.py	Mon Nov 18 14:25:40 2013 +0100
+++ b/src/plugins/plugin_xep_0045.py	Tue Nov 19 19:31:59 2013 +0100
@@ -130,6 +130,44 @@
             return ''
         return self.clients[profile].joined_rooms[room_jid_s].nick
 
+    def getRoomNickOfUser(self, room, user_jid, secure=True):
+        """Returns the nick of the given user in the room.
+        @room: instance of wokkel.muc.Room
+        @user: JID or unicode (JID userhost).
+        @param secure: set to True for a secure check
+        @return: the nick or None if the user didn't join the room.
+        """
+        if not isinstance(user_jid, jid.JID):
+            user_jid = jid.JID(user_jid)
+        for user in room.roster.values():
+            if user.entity is not None:
+                if user.entity.userhostJID() == user_jid.userhostJID():
+                    return user.nick
+            elif not secure:
+                # FIXME: this is NOT ENOUGH to check an identity!!
+                # See in which conditions user.entity could be None.
+                if user.nick == user_jid.user:
+                    return user.nick
+        return None
+
+    def getRoomNicksOfUsers(self, room, users=[], secure=True):
+        """Returns the nicks of the given users in the room.
+        @room: instance of wokkel.muc.Room
+        @users: list of JID or unicode (JID userhost).
+        @param secure: set to True for a secure check
+        @return: (x, y) with x a list containing the nicks of
+        the users who are in the room, and y the missing users.
+        """
+        nicks = []
+        missing = []
+        for user in users:
+            nick = self.getRoomNickOfUser(room, user, secure)
+            if nick is None:
+                missing.append(user)
+            else:
+                nicks.append(nick)
+        return nicks, missing
+
     def isNickInRoom(self, room_jid, nick, profile):
         """Tell if a nick is currently present in a room"""
         profile = self.host.memory.getProfileName(profile)
@@ -308,6 +346,8 @@
             self.host.bridge.roomUserJoined(room.roomJID.userhost(), user.nick, user_data, self.parent.profile)
 
     def userLeftRoom(self, room, user):
+        if not self.host.trigger.point("MUC user left", room, user, self.parent.profile):
+            return
         if user.nick == room.nick:
             # we left the room
             room_jid_s = room.roomJID.userhost()