changeset 505:2402668b5d05

plugin xep-0045: nick change management
author Goffi <goffi@goffi.org>
date Thu, 27 Sep 2012 00:51:43 +0200
parents 65ecbb473cbb
children 2e43c74815ad
files src/plugins/plugin_xep_0045.py
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0045.py	Wed Sep 26 01:23:56 2012 +0200
+++ b/src/plugins/plugin_xep_0045.py	Thu Sep 27 00:51:43 2012 +0200
@@ -25,6 +25,9 @@
 from twisted.words.protocols.jabber import client, jid, xmlstream
 from twisted.words.protocols.jabber import error as jab_error
 from twisted.words.protocols.jabber.xmlstream import IQ
+
+from sat.core import exceptions
+
 import os.path
 import uuid
 
@@ -52,6 +55,9 @@
 "description": _("""Implementation of Multi-User Chat""")
 }
 
+class UnknownRoom(Exception):
+    pass
+
 class XEP_0045():
 
     def __init__(self, host):
@@ -59,6 +65,7 @@
         self.host = host
         self.clients={}
         host.bridge.addMethod("joinMUC", ".plugin", in_sign='ssa{ss}s', out_sign='', method=self._join)
+        host.bridge.addMethod("changeNick", ".plugin", in_sign='sss', out_sign='', method=self.changeNick)
         host.bridge.addMethod("getRoomsJoined", ".plugin", in_sign='s', out_sign='a(sass)', method=self.getRoomsJoined)
         host.bridge.addMethod("getRoomsSubjects", ".plugin", in_sign='s', out_sign='a(ss)', method=self.getRoomsSubjects)
         host.bridge.addMethod("getUniqueRoomName", ".plugin", in_sign='s', out_sign='s', method=self.getUniqueName)
@@ -171,7 +178,19 @@
             return
         d = self.join(room_jid, nick, options, profile)
         d.addErrback(lambda x: warning(_('Error while joining room'))) #TODO: error management + signal in bridge
-    
+
+    def nick(self, room_jid, nick, profile_key='@DEFAULT@'):
+        profile = self.host.memory.getProfileName(profile_key)
+        if not self.__check_profile(profile):
+            raise exceptions.UnknownProfileError("Unknown or disconnected profile")
+        if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
+            raise UnknownRoom("This room has not been joined") 
+        return self.clients[profile].nick(room_jid, nick)
+   
+    def changeNick(self, room_jid_s, nick, profile_key='@DEFAULT@'):
+        """Change nickname in a room"""
+        return self.nick(jid.JID(room_jid_s), nick, profile_key)
+
     def getHandler(self, profile):
         self.clients[profile] = SatMUCClient(self)
         return self.clients[profile]