comparison src/plugins/plugin_xep_0045.py @ 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 3446ce33247d
children ca13633d3b6b
comparison
equal deleted inserted replaced
527:9a3913fb0a6c 528:f899f6e2a9d1
98 else: 98 else:
99 _sendBridgeSignal() 99 _sendBridgeSignal()
100 return room 100 return room
101 101
102 102
103 def __err_joining_room(self, failure, profile): 103 def __err_joining_room(self, failure, room_jid, nick, history_options, password, profile):
104 """Called when something is going wrong when joining the room""" 104 """Called when something is going wrong when joining the room"""
105 if failure.value.condition == 'conflict':
106 # we have a nickname conflict, we try again with "_" suffixed to current nickname
107 nick += '_'
108 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])
109
105 mess = _("Error when joining the room") 110 mess = _("Error when joining the room")
106 error (mess) 111 error (mess)
107 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) 112 self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile)
108 raise failure 113 raise failure
109 114
127 return '' 132 return ''
128 return self.clients[profile].joined_rooms[room_jid_s].nick 133 return self.clients[profile].joined_rooms[room_jid_s].nick
129 134
130 def isNickInRoom(self, room_jid, nick, profile): 135 def isNickInRoom(self, room_jid, nick, profile):
131 """Tell if a nick is currently present in a room""" 136 """Tell if a nick is currently present in a room"""
132 profile = self.host.memory.getProfileName(profile_key) 137 profile = self.host.memory.getProfileName(profile)
133 if not self.__check_profile(profile): 138 if not self.__check_profile(profile):
134 raise exceptions.UnknownProfileError("Unknown or disconnected profile") 139 raise exceptions.UnknownProfileError("Unknown or disconnected profile")
135 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()): 140 if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
136 raise UnknownRoom("This room has not been joined") 141 raise UnknownRoom("This room has not been joined")
137 return self.clients[profile].joined_rooms[room_jid.userhost()].inRoster(nick) 142 return self.clients[profile].joined_rooms[room_jid.userhost()].inRoster(nick)
164 info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':room_jid.userhost(), 'nick':nick}) 169 info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':room_jid.userhost(), 'nick':nick})
165 170
166 history_options = options["history"] == "True" if options.has_key("history") else None 171 history_options = options["history"] == "True" if options.has_key("history") else None
167 password = options["password"] if options.has_key("password") else None 172 password = options["password"] if options.has_key("password") else None
168 173
169 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}) 174 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])
170 175
171 def _join(self, room_jid_s, nick, options={}, profile_key='@DEFAULT@'): 176 def _join(self, room_jid_s, nick, options={}, profile_key='@DEFAULT@'):
172 """join method used by bridge: use the _join method, but doesn't return any deferred""" 177 """join method used by bridge: use the _join method, but doesn't return any deferred"""
173 profile = self.host.memory.getProfileName(profile_key) 178 profile = self.host.memory.getProfileName(profile_key)
174 if not self.__check_profile(profile): 179 if not self.__check_profile(profile):