# HG changeset patch # User Goffi # Date 1350851517 -7200 # Node ID f899f6e2a9d1b9a5b5734a80c36ece74d8605e92 # Parent 9a3913fb0a6ced8b013d5a92dade5a3fbbd97180 plugin XEP-0045: in case of nickname conflict when entering a room, a new one is automaticaly assigned diff -r 9a3913fb0a6c -r f899f6e2a9d1 src/plugins/plugin_xep_0045.py --- 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"""