plugin XEP-0045: added mucNickGet to retrieve our nickname in a MUC room
This commit is contained in:
parent
a9fb2e568e
commit
9e243b3a8a
1 changed files with 9 additions and 5 deletions
|
|
@ -73,6 +73,7 @@ class AlreadyJoined(exceptions.ConflictError):
|
|||
|
||||
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 @@ class XEP_0045(object):
|
|||
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 @@ class XEP_0045(object):
|
|||
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 @@ class XEP_0045(object):
|
|||
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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue