Commit a11ce9da authored by Philipp Hörist's avatar Philipp Hörist

MUC: Move join into MUC module

parent 668048c3
......@@ -258,7 +258,9 @@ class StandardGroupChatCommands(CommandContainer):
new_nick = helpers.parse_resource(new_nick)
except Exception:
raise CommandError(_("Invalid nickname"))
self.connection.join_gc(new_nick, self.room_jid, None, change_nick=True)
# FIXME: Check state of MUC
self.connection.get_module('MUC').change_nick(
self.room_jid, new_nick)
self.new_nick = new_nick
@command('query', raw=True)
......
......@@ -1638,35 +1638,6 @@ class Connection(CommonConnection, ConnectionHandlers):
show=show,
caps=ptype != 'unavailable')
def join_gc(self, nick, room_jid, password, change_nick=False,
rejoin=False):
# FIXME: This room JID needs to be normalized; see #1364
if not app.account_is_connected(self.name):
return
show = helpers.get_xmpp_show(app.SHOW_LIST[self.connected])
if show == 'invisible':
# Never join a room when invisible
return
self.get_module('Discovery').disco_muc(
room_jid, partial(self._join_gc, nick, show, room_jid,
password, change_nick, rejoin))
def _join_gc(self, nick, show, room_jid, password, change_nick, rejoin):
if change_nick:
self.get_module('Presence').send_presence(
'%s/%s' % (room_jid, nick),
show=show,
status=self.status)
else:
self.get_module('MUC').send_muc_join_presence(
'%s/%s' % (room_jid, nick),
show=show,
status=self.status,
room_jid=room_jid,
password=password,
rejoin=rejoin)
def _nec_gc_message_outgoing(self, obj):
if obj.account != self.name:
return
......
......@@ -17,6 +17,7 @@
import time
import logging
from functools import partial
import nbxmpp
from nbxmpp.const import InviteType
......@@ -108,12 +109,20 @@ class MUC(BaseModule):
self._con.muc_jid['jabber'] = from_
raise nbxmpp.NodeProcessed
def send_muc_join_presence(self, *args, room_jid=None, password=None,
rejoin=False, **kwargs):
def join(self, room_jid, nick, password, rejoin=False):
if not app.account_is_connected(self._account):
return
show = helpers.get_xmpp_show(app.SHOW_LIST[self._con.connected])
self._con.get_module('Discovery').disco_muc(
room_jid, partial(self._join, room_jid, nick,
show, password, rejoin))
def _join(self, room_jid, nick, show, password, rejoin):
presence = self._con.get_module('Presence').get_presence(
*args, **kwargs)
'%s/%s' % (room_jid, nick),
show=show,
status=self._con.status)
muc_x = presence.setTag(nbxmpp.NS_MUC + ' x')
if room_jid is not None:
......@@ -122,10 +131,16 @@ class MUC(BaseModule):
if password is not None:
muc_x.setTagData('password', password)
self._log.debug('Send MUC join presence:\n%s', presence)
self._log.info('Join MUC: %s', room_jid)
self._con.connection.send(presence)
def change_nick(self, room_jid, new_nick):
show = helpers.get_xmpp_show(app.SHOW_LIST[self._con.connected])
self._con.get_module('Presence').send_presence(
'%s/%s' % (room_jid, new_nick),
show=show,
status=self._con.status)
def _add_history_query(self, muc_x, room_jid, rejoin):
last_date = app.logger.get_room_last_message_time(
self._account, room_jid)
......
......@@ -1474,7 +1474,8 @@ class GroupchatControl(ChatControlBase):
if obj.conn.name != self.account:
return
password = app.gc_passwords.get(self.room_jid, '')
obj.conn.join_gc(self.nick, self.room_jid, password, rejoin=True)
obj.conn.get_module('MUC').join(self.room_jid, self.nick, password,
rejoin=True)
def _nec_decrypted_message_received(self, obj):
if obj.conn.name != self.account:
......@@ -1610,8 +1611,8 @@ class GroupchatControl(ChatControlBase):
if not self.autorejoin:
return False
password = app.gc_passwords.get(self.room_jid, '')
app.connections[self.account].join_gc(self.nick, self.room_jid,
password, rejoin=True)
app.connections[self.account].get_module('MUC').join(
self.room_jid, self.nick, password, rejoin=True)
return True
def draw_roster(self):
......
......@@ -270,7 +270,8 @@ class Interface:
def handle_gc_password_required(self, account, room_jid, nick):
def on_ok(text):
app.connections[account].join_gc(nick, room_jid, text)
app.connections[account].get_module('MUC').join(
room_jid, nick, text)
app.gc_passwords[room_jid] = text
gc_control.error_dialog = None
......@@ -1644,7 +1645,8 @@ class Interface:
gc_control.parent_win.set_active_tab(gc_control)
# Connect
app.connections[account].join_gc(nick, room_jid, password)
app.connections[account].get_module('MUC').join(
room_jid, nick, password)
if password:
app.gc_passwords[room_jid] = password
......
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