Commit 3626505e authored by Philipp Hörist's avatar Philipp Hörist

MUC: Resolve nickname conflicts automatically

parent 99cf0c7b
......@@ -22,6 +22,7 @@ from functools import partial
import nbxmpp
from nbxmpp.const import InviteType
from nbxmpp.const import PresenceType
from nbxmpp.const import Error
from nbxmpp.structs import StanzaHandler
from nbxmpp.util import is_error_result
......@@ -68,6 +69,7 @@ class MUC(BaseModule):
priority=49),
StanzaHandler(name='presence',
callback=self._on_muc_presence,
typ='error',
ns=nbxmpp.NS_MUC,
priority=49),
StanzaHandler(name='message',
......@@ -194,9 +196,15 @@ class MUC(BaseModule):
muc_x.setTag('history', tags)
def _on_muc_presence(self, _con, _stanza, properties):
if properties.type == PresenceType.ERROR:
self._raise_muc_event('muc-presence-error', properties)
muc = self._get_muc_data(properties.jid.getBare())
if (properties.error.type == Error.CONFLICT and
muc.state == MUCJoinedState.JOINING):
muc.nick += '_'
self._log.info('Nickname conflict: %s change to %s',
muc.jid, muc.nick)
self._join(muc.jid)
return
self._raise_muc_event('muc-presence-error', properties)
def _on_muc_user_presence(self, _con, stanza, properties):
if properties.type == PresenceType.ERROR:
......
......@@ -2078,11 +2078,6 @@ class GroupchatControl(ChatControlBase):
_('You are not in the members '
'list in groupchat %s.') % self.room_jid)
elif error_type == Error.CONFLICT:
win = None if self.parent_win is None else self.parent_win.window
app.interface.handle_ask_new_nick(
self.account, self.room_jid, win)
else:
self.add_info_message(
'Error %s: %s' % (error_type.value, error_message))
......
......@@ -771,8 +771,8 @@ class ChangeNickDialog(InputDialogCheck):
self.on_ok(nick, self.is_checked())
def on_ok(self, nick, is_checked):
app.connections[self.account].join_gc(nick, self.room_jid, None,
change_nick=self.change_nick)
app.connections[self.account].get_module('MUC').change_nick(
self.room_jid, nick)
if app.gc_connected[self.account][self.room_jid]:
# We are changing nick, we will change self.nick when we receive
# presence that inform that it works
......
......@@ -103,7 +103,6 @@ from gajim.gtk.dialogs import YesNoDialog
from gajim.gtk.dialogs import PassphraseDialog
from gajim.gtk.dialogs import PlainConnectionDialog
from gajim.gtk.dialogs import SSLErrorDialog
from gajim.gtk.dialogs import ChangeNickDialog
from gajim.gtk.dialogs import InvitationReceivedDialog
from gajim.gtk.profile import ProfileWindow
from gajim.gtk.join_groupchat import JoinGroupchatWindow
......@@ -160,19 +159,6 @@ class Interface:
def raise_dialog(name, *args, **kwargs):
get_dialog(name, *args, **kwargs)
def handle_ask_new_nick(self, account, room_jid, parent_win):
title = _('Unable to join group chat')
prompt = _('Your desired nickname in group chat\n'
'<b>%s</b>\n'
'is in use or registered by another occupant.\n'
'Please specify another nickname below:') % room_jid
if 'change_nick_dialog' in self.instances:
self.instances['change_nick_dialog'].add_room(
account, room_jid, prompt)
else:
self.instances['change_nick_dialog'] = ChangeNickDialog(
account, room_jid, title, prompt, transient_for=parent_win)
@staticmethod
def handle_event_http_auth(obj):
#('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment