Commit 7ee22d83 authored by Philipp Hörist's avatar Philipp Hörist

MUC: Add possibility to override default config

parent 6f8f3e81
Pipeline #3839 passed with stages
in 2 minutes and 41 seconds
......@@ -130,11 +130,12 @@ class MUC(BaseModule):
def get_mucs_with_state(self, states):
return [muc for muc in self._muc_data.values() if muc.state in states]
def join(self, room_jid, nick, password, rejoin=False):
def join(self, room_jid, nick, password, rejoin=False, config=None):
if not app.account_is_connected(self._account):
return
self._muc_data[room_jid] = MUCData(room_jid, nick, password, rejoin)
self._muc_data[room_jid] = MUCData(room_jid, nick,
password, rejoin, config)
self._con.get_module('Discovery').disco_muc(
room_jid, partial(self._join, room_jid))
......@@ -182,16 +183,19 @@ class MUC(BaseModule):
return
self._log.info('Configure room: %s', result.jid)
self._apply_config(result.form)
muc = self._get_muc_data(result.jid)
self._apply_config(result.form, muc.config)
self.set_config(result.jid,
result.form,
callback=self._on_config_result)
@staticmethod
def _apply_config(form, config=None):
if config is None:
config = get_default_muc_config()
for var, value in config.items():
default_config = get_default_muc_config()
if config is not None:
default_config.update(config)
for var, value in default_config.items():
try:
field = form[var]
except KeyError:
......
......@@ -24,11 +24,12 @@ CapsIdentity = namedtuple('CapsIdentity', 'category type name lang')
class MUCData:
def __init__(self, room_jid, nick, password, rejoin):
def __init__(self, room_jid, nick, password, rejoin, config=None):
self._room_jid = room_jid
self._nick = nick
self._password = password
self._rejoin = rejoin
self._config = config
self._state = MUCJoinedState.NOT_JOINED
@property
......@@ -62,3 +63,7 @@ class MUCData:
@rejoin.setter
def rejoin(self, value):
self._rejoin = value
@property
def config(self):
return self._config
......@@ -1568,7 +1568,7 @@ class Interface:
################################################################################
def join_gc_room(self, account, room_jid, nick, password, minimize=False,
is_continued=False):
is_continued=False, config=None):
"""
Join the room immediately
"""
......@@ -1628,7 +1628,7 @@ class Interface:
# Connect
app.connections[account].get_module('MUC').join(
room_jid, nick, password)
room_jid, nick, password, config=config)
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