Commit 4acecfef authored by Philipp Hörist's avatar Philipp Hörist

MUC: Automatically set bookmarks on join/leave

- When we join a MUC add a bookmark with autojoin enabled
- When we leave a MUC modify the bookmark and disable autojoin
parent e0557fda
......@@ -308,6 +308,7 @@ class StandardGroupChatCommands(CommandContainer):
@command('part', 'close', raw=True, empty=True)
@doc(_("Leave the groupchat, optionally giving a reason, and close tab or window"))
def leave(self, reason):
self.connection.get_module('MUC').leave(self.room_jid)
self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND, reason)
@command(raw=True, empty=True)
......
......@@ -214,8 +214,8 @@ class Bookmarks(BaseModule):
password: str,
nick: str) -> None:
if self.is_bookmark(jid):
return
bookmark = self.get_bookmark_from_jid(jid)
if bookmark is None:
bookmark = BookmarkData(jid=jid,
name=name,
autojoin=autojoin,
......@@ -224,6 +224,19 @@ class Bookmarks(BaseModule):
self._bookmarks.append(bookmark)
self.store_bookmarks()
elif not bookmark.autojoin:
self.set_autojoin(jid, True)
def set_autojoin(self, jid, enabled):
bookmark = self.get_bookmark_from_jid(jid)
if bookmark is None:
return
self._log.info('Set autojoin for: %s to %s', jid, enabled)
self._bookmarks.remove(bookmark)
bookmark = bookmark._replace(autojoin=enabled)
self._bookmarks.append(bookmark)
self.store_bookmarks()
def remove(self, jid: str, publish: bool = True) -> None:
bookmark = self.get_bookmark_from_jid(jid)
if bookmark is None:
......
......@@ -167,6 +167,8 @@ class MUC(BaseModule):
self._con.get_module('Presence').send_presence(
'%s/%s' % (room_jid, muc.nick),
typ='unavailable')
# We leave a group chat, disable bookmark autojoin
self._con.get_module('Bookmarks').set_autojoin(room_jid, False)
def configure_room(self, room_jid):
self._nbxmpp('MUC').request_config(room_jid,
......@@ -513,8 +515,13 @@ class MUC(BaseModule):
nickname=properties.muc_nickname,
user_timestamp=properties.user_timestamp))
if self._get_muc_state(jid) == MUCJoinedState.JOINING:
muc_data = self._get_muc_data(jid)
if muc_data.state == MUCJoinedState.JOINING:
self._set_muc_state(jid, MUCJoinedState.JOINED)
# We successfully joined a MUC, set autojoin bookmark
self._con.get_module('Bookmarks').add_bookmark(
None, properties.muc_jid,
True, muc_data.password, muc_data.nick)
raise nbxmpp.NodeProcessed
......
......@@ -643,6 +643,7 @@ class GroupchatControl(ChatControlBase):
prompt, change_nick=True, transient_for=self.parent_win.window)
def _on_disconnect(self, action, param):
app.connections[self.account].get_module('MUC').leave(self.room_jid)
self.force_non_minimizable = True
self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND)
self.force_non_minimizable = False
......@@ -2230,9 +2231,6 @@ class GroupchatControl(ChatControlBase):
for handler in self._event_handlers:
app.ged.remove_event_handler(*handler)
if self.is_connected:
app.connections[self.account].get_module('MUC').leave(self.room_jid)
nick_list = app.contacts.get_nick_list(self.account, self.room_jid)
for nick in nick_list:
# Update pm chat window
......
......@@ -2965,6 +2965,7 @@ class RosterWindow:
"""
When disconnect menuitem is activated: disconnect from room
"""
app.connections[account].get_module('MUC').leave(jid)
if jid in app.interface.minimized_controls[account]:
ctrl = app.interface.minimized_controls[account][jid]
ctrl.shutdown()
......
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