comparison sat/plugins/plugin_xep_0045.py @ 2844:fa1cc09df195

plugin XEP-0045: added getRoomOccupants/mucOccupantsGet method to retrieve occupants of a joined room.
author Goffi <goffi@goffi.org>
date Sat, 09 Mar 2019 16:24:17 +0100
parents 9a3b99acad91
children f44a95f566d2
comparison
equal deleted inserted replaced
2843:a425c1ca51d0 2844:fa1cc09df195
89 self._sessions = memory.Sessions() 89 self._sessions = memory.Sessions()
90 host.bridge.addMethod("mucJoin", ".plugin", in_sign='ssa{ss}s', out_sign='(bsa{sa{ss}}sss)', method=self._join, async=True) # return same arguments as mucRoomJoined + a boolean set to True is the room was already joined (first argument) 90 host.bridge.addMethod("mucJoin", ".plugin", in_sign='ssa{ss}s', out_sign='(bsa{sa{ss}}sss)', method=self._join, async=True) # return same arguments as mucRoomJoined + a boolean set to True is the room was already joined (first argument)
91 host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self._nick) 91 host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self._nick)
92 host.bridge.addMethod("mucNickGet", ".plugin", in_sign='ss', out_sign='s', method=self._getRoomNick) 92 host.bridge.addMethod("mucNickGet", ".plugin", in_sign='ss', out_sign='s', method=self._getRoomNick)
93 host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self._leave, async=True) 93 host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self._leave, async=True)
94 host.bridge.addMethod("mucOccupantsGet", ".plugin", in_sign='ss', out_sign='a{sa{ss}}', method=self._getRoomOccupants)
94 host.bridge.addMethod("mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject) 95 host.bridge.addMethod("mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject)
95 host.bridge.addMethod("mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ss)', method=self._getRoomsJoined) 96 host.bridge.addMethod("mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ss)', method=self._getRoomsJoined)
96 host.bridge.addMethod("mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName) 97 host.bridge.addMethod("mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName)
97 host.bridge.addMethod("mucConfigureRoom", ".plugin", in_sign='ss', out_sign='s', method=self._configureRoom, async=True) 98 host.bridge.addMethod("mucConfigureRoom", ".plugin", in_sign='ss', out_sign='s', method=self._configureRoom, async=True)
98 host.bridge.addMethod("mucGetDefaultService", ".plugin", in_sign='', out_sign='s', method=self.getDefaultMUC) 99 host.bridge.addMethod("mucGetDefaultService", ".plugin", in_sign='', out_sign='s', method=self.getDefaultMUC)
162 log.warning(u"Received groupchat message for a room which has not been " 163 log.warning(u"Received groupchat message for a room which has not been "
163 u"joined, ignoring it: {}".format(message_elt.toXml())) 164 u"joined, ignoring it: {}".format(message_elt.toXml()))
164 return False 165 return False
165 return True 166 return True
166 167
168 def getRoom(self, client, room_jid):
169 """Retrieve Room instance from its jid
170
171 @param room_jid(jid.JID): jid of the room
172 @raise exceptions.NotFound: the room has not been joined
173 """
174 try:
175 return client._muc_client.joined_rooms[room_jid]
176 except KeyError:
177 raise exceptions.NotFound(_(u"This room has not been joined"))
178
167 def checkRoomJoined(self, client, room_jid): 179 def checkRoomJoined(self, client, room_jid):
168 """Check that given room has been joined in current session 180 """Check that given room has been joined in current session
169 181
170 @param room_jid (JID): room JID 182 @param room_jid (JID): room JID
171 """ 183 """
258 270
259 @staticmethod 271 @staticmethod
260 def _getOccupants(room): 272 def _getOccupants(room):
261 """Get occupants of a room in a form suitable for bridge""" 273 """Get occupants of a room in a form suitable for bridge"""
262 return {u.nick: {k:unicode(getattr(u,k) or '') for k in OCCUPANT_KEYS} for u in room.roster.values()} 274 return {u.nick: {k:unicode(getattr(u,k) or '') for k in OCCUPANT_KEYS} for u in room.roster.values()}
275
276 def _getRoomOccupants(self, room_jid_s, profile_key):
277 client = self.host.getClient(profile_key)
278 room_jid = jid.JID(room_jid_s)
279 return self.getRoomOccupants(client, room_jid)
280
281 def getRoomOccupants(self, client, room_jid):
282 room = self.getRoom(client, room_jid)
283 return self._getOccupants(room)
263 284
264 def _getRoomsJoined(self, profile_key=C.PROF_KEY_NONE): 285 def _getRoomsJoined(self, profile_key=C.PROF_KEY_NONE):
265 client = self.host.getClient(profile_key) 286 client = self.host.getClient(profile_key)
266 return self.getRoomsJoined(client) 287 return self.getRoomsJoined(client)
267 288