Daniel Brötzmann pushed to branch mainwindow at gajim / gajim
Commits: 1e47ee1b by wurstsalat at 2021-11-14T18:37:39+01:00 StartChat: Remove history when forgetting group chat
- - - - -
2 changed files:
- gajim/app_actions.py - gajim/common/storage/archive.py
Changes:
===================================== gajim/app_actions.py ===================================== @@ -28,6 +28,7 @@ from gajim.gui.about import AboutDialog from gajim.gui.discovery import ServiceDiscoveryWindow from gajim.gui.util import open_window +from gajim.gui.util import get_app_window
# General Actions
@@ -266,10 +267,16 @@ def start_chat(_action, param):
def forget_groupchat(_action, param): account, jid = param.unpack() + room_jid = JID.from_string(jid) + window = get_app_window('StartChatDialog') + window.remove_row(account, str(room_jid)) + client = app.get_client(account) - client.get_module('Bookmarks').remove(JID.from_string(jid)) - window = open_window('StartChatDialog') - window.remove_row(account, jid) + client.get_module('MUC').leave(room_jid) + client.get_module('Bookmarks').remove(room_jid) + + app.storage.archive.remove_chat_history( + account, str(room_jid), groupchat=True)
def on_groupchat_join(_action, param): account, jid = param.get_strv()
===================================== gajim/common/storage/archive.py ===================================== @@ -1192,6 +1192,27 @@ def reset_archive_infos(self, jid): log.info('Reset message archive info: %s', jid) self._delayed_commit()
+ def remove_chat_history(self, account: str, jid: str, + groupchat: bool = False) -> None: + """ + Remove chat history for a specific chat. + If it's a group chat, remove last MAM ID as well. + """ + account_id = self.get_account_id(account) + jid_id = self.get_jid_id(jid) + sql = 'DELETE FROM logs WHERE account_id = ? AND jid_id = ?' + self._con.execute(sql, (account_id, jid_id)) + + sql = 'DELETE FROM jids WHERE jid_id = ?' + self._con.execute(sql, (jid_id,)) + + if groupchat: + sql = 'DELETE FROM last_archive_message WHERE jid_id = ?' + self._con.execute(sql, (jid_id,)) + + self._delayed_commit() + log.info('Removed chat history for: %s', jid) + def _cleanup_chat_history(self): """ Remove messages from account where messages are older than max_age
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/1e47ee1b7485bce2e3970111c5d69f67f...