Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0045.py @ 2461:34cb8b713370
plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 03 Jan 2018 00:16:23 +0100 |
parents | 8b37a62336c3 |
children | 8f14c1865e9e |
comparison
equal
deleted
inserted
replaced
2460:feaacc462fef | 2461:34cb8b713370 |
---|---|
71 self.room = room | 71 self.room = room |
72 | 72 |
73 | 73 |
74 class XEP_0045(object): | 74 class XEP_0045(object): |
75 # TODO: handle invitations | 75 # TODO: handle invitations |
76 # FIXME: this plugin need a good cleaning, join method is messy | |
76 | 77 |
77 def __init__(self, host): | 78 def __init__(self, host): |
78 log.info(_("Plugin XEP_0045 initialization")) | 79 log.info(_("Plugin XEP_0045 initialization")) |
79 self.host = host | 80 self.host = host |
80 self._sessions = memory.Sessions() | 81 self._sessions = memory.Sessions() |
81 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) | 82 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) |
82 host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self._nick) | 83 host.bridge.addMethod("mucNick", ".plugin", in_sign='sss', out_sign='', method=self._nick) |
84 host.bridge.addMethod("mucNickGet", ".plugin", in_sign='ss', out_sign='s', method=self._getRoomNick) | |
83 host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self._leave, async=True) | 85 host.bridge.addMethod("mucLeave", ".plugin", in_sign='ss', out_sign='', method=self._leave, async=True) |
84 host.bridge.addMethod("mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject) | 86 host.bridge.addMethod("mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject) |
85 host.bridge.addMethod("mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ss)', method=self._getRoomsJoined) | 87 host.bridge.addMethod("mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ss)', method=self._getRoomsJoined) |
86 host.bridge.addMethod("mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName) | 88 host.bridge.addMethod("mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName) |
87 host.bridge.addMethod("mucConfigureRoom", ".plugin", in_sign='ss', out_sign='s', method=self._configureRoom, async=True) | 89 host.bridge.addMethod("mucConfigureRoom", ".plugin", in_sign='ss', out_sign='s', method=self._configureRoom, async=True) |
233 for room in client._muc_client.joined_rooms.values(): | 235 for room in client._muc_client.joined_rooms.values(): |
234 if room._room_ok: | 236 if room._room_ok: |
235 result.append((room.roomJID.userhost(), self._getOccupants(room), room.nick, room.subject)) | 237 result.append((room.roomJID.userhost(), self._getOccupants(room), room.nick, room.subject)) |
236 return result | 238 return result |
237 | 239 |
240 def _getRoomNick(self, room_jid_s, profile_key=C.PROF_KEY_NONE): | |
241 client = self.host.getClient(profile_key) | |
242 return self.getRoomNick(client, jid.JID(room_jid_s)) | |
243 | |
238 def getRoomNick(self, client, room_jid): | 244 def getRoomNick(self, client, room_jid): |
239 """return nick used in room by user | 245 """return nick used in room by user |
240 | 246 |
241 @param room_jid (jid.JID): JID of the room | 247 @param room_jid (jid.JID): JID of the room |
242 @profile_key: profile | 248 @profile_key: profile |
243 @return: nick or empty string in case of error | 249 @return: nick or empty string in case of error |
244 """ | 250 @raise exceptions.Notfound: use has not joined the room |
245 try: | 251 """ |
246 self.checkRoomJoined(client, room_jid) | 252 self.checkRoomJoined(client, room_jid) |
247 except exceptions.NotFound: | |
248 return '' # FIXME: should not return empty string but raise the error | |
249 return client._muc_client.joined_rooms[room_jid].nick | 253 return client._muc_client.joined_rooms[room_jid].nick |
250 | 254 |
251 # FIXME: broken, to be removed ! | 255 # FIXME: broken, to be removed ! |
252 # def getRoomEntityNick(self, client, room_jid, entity_jid, =True): | 256 # def getRoomEntityNick(self, client, room_jid, entity_jid, =True): |
253 # """Returns the nick of the given user in the room. | 257 # """Returns the nick of the given user in the room. |
411 return [True] + self._getRoomJoinedArgs(room, client.profile) | 415 return [True] + self._getRoomJoinedArgs(room, client.profile) |
412 | 416 |
413 def _join(self, room_jid_s, nick, options, profile_key=C.PROF_KEY_NONE): | 417 def _join(self, room_jid_s, nick, options, profile_key=C.PROF_KEY_NONE): |
414 """join method used by bridge | 418 """join method used by bridge |
415 | 419 |
416 @return (unicode): room bare jid | 420 @return (tuple): already_joined boolean + room joined arguments (see [_getRoomJoinedArgs]) |
417 """ | 421 """ |
418 client = self.host.getClient(profile_key) | 422 client = self.host.getClient(profile_key) |
419 if room_jid_s: | 423 if room_jid_s: |
420 muc_service = client.muc_service | 424 muc_service = client.muc_service |
421 try: | 425 try: |