plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.

This commit is contained in:
Goffi 2019-03-09 16:24:17 +01:00
commit 89aa5e4079

View file

@ -91,6 +91,7 @@ class XEP_0045(object):
host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self._nick)
host.bridge.addMethod("mucNickGet", ".plugin", in_sign='ss', out_sign='s', method=self._getRoomNick)
host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self._leave, async=True)
host.bridge.addMethod("mucOccupantsGet", ".plugin", in_sign='ss', out_sign='a{sa{ss}}', method=self._getRoomOccupants)
host.bridge.addMethod("mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject)
host.bridge.addMethod("mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ss)', method=self._getRoomsJoined)
host.bridge.addMethod("mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName)
@ -164,6 +165,17 @@ class XEP_0045(object):
return False
return True
def getRoom(self, client, room_jid):
"""Retrieve Room instance from its jid
@param room_jid(jid.JID): jid of the room
@raise exceptions.NotFound: the room has not been joined
"""
try:
return client._muc_client.joined_rooms[room_jid]
except KeyError:
raise exceptions.NotFound(_(u"This room has not been joined"))
def checkRoomJoined(self, client, room_jid):
"""Check that given room has been joined in current session
@ -261,6 +273,15 @@ class XEP_0045(object):
"""Get occupants of a room in a form suitable for bridge"""
return {u.nick: {k:unicode(getattr(u,k) or '') for k in OCCUPANT_KEYS} for u in room.roster.values()}
def _getRoomOccupants(self, room_jid_s, profile_key):
client = self.host.getClient(profile_key)
room_jid = jid.JID(room_jid_s)
return self.getRoomOccupants(client, room_jid)
def getRoomOccupants(self, client, room_jid):
room = self.getRoom(client, room_jid)
return self._getOccupants(room)
def _getRoomsJoined(self, profile_key=C.PROF_KEY_NONE):
client = self.host.getClient(profile_key)
return self.getRoomsJoined(client)