changeset 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 feaacc462fef
children 2cad04f38bac
files src/plugins/plugin_xep_0045.py
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0045.py	Wed Jan 03 00:13:48 2018 +0100
+++ b/src/plugins/plugin_xep_0045.py	Wed Jan 03 00:16:23 2018 +0100
@@ -73,6 +73,7 @@
 
 class XEP_0045(object):
     # TODO: handle invitations
+    # FIXME: this plugin need a good cleaning, join method is messy
 
     def __init__(self, host):
         log.info(_("Plugin XEP_0045 initialization"))
@@ -80,6 +81,7 @@
         self._sessions = memory.Sessions()
         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)
         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("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)
@@ -235,17 +237,19 @@
                 result.append((room.roomJID.userhost(), self._getOccupants(room), room.nick, room.subject))
         return result
 
+    def _getRoomNick(self, room_jid_s, profile_key=C.PROF_KEY_NONE):
+        client = self.host.getClient(profile_key)
+        return self.getRoomNick(client, jid.JID(room_jid_s))
+
     def getRoomNick(self, client, room_jid):
         """return nick used in room by user
 
         @param room_jid (jid.JID): JID of the room
         @profile_key: profile
         @return: nick or empty string in case of error
+        @raise exceptions.Notfound: use has not joined the room
         """
-        try:
-            self.checkRoomJoined(client, room_jid)
-        except exceptions.NotFound:
-            return ''  # FIXME: should not return empty string but raise the error
+        self.checkRoomJoined(client, room_jid)
         return client._muc_client.joined_rooms[room_jid].nick
 
     # FIXME: broken, to be removed !
@@ -413,7 +417,7 @@
     def _join(self, room_jid_s, nick, options, profile_key=C.PROF_KEY_NONE):
         """join method used by bridge
 
-        @return (unicode): room bare jid
+        @return (tuple): already_joined boolean + room joined arguments (see [_getRoomJoinedArgs])
         """
         client = self.host.getClient(profile_key)
         if room_jid_s: