plugins XEP-0045: added methods to get room nicks and "MUC user left" trigger

This commit is contained in:
souliane 2013-11-19 19:31:59 +01:00
commit b037678f13

View file

@ -130,6 +130,44 @@ class XEP_0045(object):
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 @@ class SatMUCClient (muc.MUCClient):
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()