changeset 528:f899f6e2a9d1

plugin XEP-0045: in case of nickname conflict when entering a room, a new one is automaticaly assigned
author Goffi <goffi@goffi.org>
date Sun, 21 Oct 2012 22:31:57 +0200
parents 9a3913fb0a6c
children c18e0e108925
files src/plugins/plugin_xep_0045.py
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0045.py	Sun Oct 21 19:46:08 2012 +0200
+++ b/src/plugins/plugin_xep_0045.py	Sun Oct 21 22:31:57 2012 +0200
@@ -100,8 +100,13 @@
         return room
 
 
-    def __err_joining_room(self, failure, profile):
+    def __err_joining_room(self, failure, room_jid, nick, history_options, password, profile):
         """Called when something is going wrong when joining the room"""
+        if failure.value.condition == 'conflict':
+            # we have a nickname conflict, we try again with "_" suffixed to current nickname
+            nick += '_'
+            return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackArgs=[room_jid, nick, history_options, password, profile])
+        
         mess = _("Error when joining the room")
         error (mess)
         self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile)
@@ -129,7 +134,7 @@
   
     def isNickInRoom(self, room_jid, nick, profile):
         """Tell if a nick is currently present in a room"""
-        profile = self.host.memory.getProfileName(profile_key)
+        profile = self.host.memory.getProfileName(profile)
         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()):
@@ -166,7 +171,7 @@
         history_options = options["history"] == "True" if options.has_key("history") else None
         password = options["password"] if options.has_key("password") else None
         
-        return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackKeywords={'profile':profile})
+        return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackArgs=[room_jid, nick, history_options, password, profile])
 
     def _join(self, room_jid_s, nick, options={}, profile_key='@DEFAULT@'):
         """join method used by bridge: use the _join method, but doesn't return any deferred"""