Philipp Hörist pushed to branch master at gajim / gajim
Commits: e236e904 by lovetox at 2022-01-09T08:11:12+01:00 Chats: Add remove history option
- - - - -
5 changed files:
- gajim/common/storage/archive.py - gajim/gtk/application.py - gajim/gtk/controls/groupchat.py - gajim/gtk/menus.py - gajim/gtk/structs.py
Changes:
===================================== gajim/common/storage/archive.py ===================================== @@ -1349,13 +1349,9 @@ def reset_archive_infos(self, jid: str) -> None: log.info('Reset message archive info: %s', jid) self._delayed_commit()
- def remove_chat_history(self, - account: str, - jid: str, - groupchat: bool = False - ) -> None: + def remove_history(self, account: str, jid: JID) -> None: """ - Remove chat history for a specific chat. + Remove history for a specific chat. If it's a group chat, remove last MAM ID as well. """ account_id = self.get_account_id(account) @@ -1363,15 +1359,19 @@ def remove_chat_history(self, sql = 'DELETE FROM logs WHERE account_id = ? AND jid_id = ?' self._con.execute(sql, (account_id, jid_id))
+ self._delayed_commit() + log.info('Removed history for: %s', jid) + + def forget_jid_data(self, account: str, jid: JID) -> None: + jid_id = self.get_jid_id(jid) 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,)) + 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) + log.info('Forgot data for: %s', jid)
def _cleanup_chat_history(self) -> None: """
===================================== gajim/gtk/application.py ===================================== @@ -75,7 +75,9 @@ from gajim.gui.dialogs import ShortcutsWindow from gajim.gui.about import AboutDialog from gajim.gui.discovery import ServiceDiscoveryWindow +from gajim.gui.structs import ForgetGroupchatActionParams from gajim.gui.structs import OpenEventActionParams +from gajim.gtk.structs import RemoveHistoryActionParams
ActionListT = list[tuple[str, @@ -380,8 +382,9 @@ def add_actions(self) -> None: ('copy-text', 's', self._on_copy_text_action), ('open-link', 'as', self._on_open_link_action), ('open-mail', 's', self._on_open_mail_action), + ('remove-history', 'a{sv}', self._on_remove_history_action), ('create-groupchat', 's', self._on_create_groupchat_action), - ('forget-groupchat', 'as', self._on_forget_groupchat_action), + ('forget-groupchat', 'a{sv}', self._on_forget_groupchat_action), ('groupchat-join', 'as', self._on_groupchat_join_action), ]
@@ -775,20 +778,35 @@ def _on_open_chat_action(_action: Gio.SimpleAction, account, jid = param.get_strv() app.interface.start_chat_from_jid(account, jid)
+ @staticmethod + def _on_remove_history_action(_action: Gio.SimpleAction, + param: GLib.Variant) -> None: + + params = RemoveHistoryActionParams.from_variant(param) + + if params.jid is not None: + app.storage.archive.remove_history(params.account, params.jid) + control = app.window.get_control(params.account, params.jid) + if control is not None: + control.reset_view() + else: + for control in app.window.get_controls(params.account): + control.reset_view() + @staticmethod def _on_forget_groupchat_action(_action: Gio.SimpleAction, param: GLib.Variant) -> None: - account, jid = param.unpack() - room_jid = JID.from_string(jid) + + params = ForgetGroupchatActionParams.from_variant(param) window = get_app_window('StartChatDialog') - window.remove_row(account, str(room_jid)) + window.remove_row(params.account, str(params.jid))
- client = app.get_client(account) - client.get_module('MUC').leave(room_jid) - client.get_module('Bookmarks').remove(room_jid) + client = app.get_client(params.account) + client.get_module('MUC').leave(params.jid) + client.get_module('Bookmarks').remove(params.jid)
- app.storage.archive.remove_chat_history( - account, str(room_jid), groupchat=True) + app.storage.archive.remove_history(params.account, params.jid) + app.storage.archive.forget_jid_data(params.account, params.jid)
@staticmethod def _on_groupchat_join_action(_action: Gio.SimpleAction,
===================================== gajim/gtk/controls/groupchat.py ===================================== @@ -191,7 +191,7 @@ def __init__(self, account: str, jid: JID) -> None:
self.control_menu = get_groupchat_menu(self.control_id, self.account, - self.room_jid) + self.contact.jid)
self.xml.settings_menu.set_menu_model(self.control_menu)
===================================== gajim/gtk/menus.py ===================================== @@ -41,6 +41,8 @@ from gajim.common.const import URIAction from gajim.common.structs import URI
+from gajim.gui.structs import ForgetGroupchatActionParams +from gajim.gui.structs import RemoveHistoryActionParams from gajim.gui.const import ControlType
@@ -52,7 +54,7 @@ def get_singlechat_menu(control_id: str, client = app.get_client(account) is_self_contact = jid.bare == client.get_own_jid().bare
- singlechat_menu: List[Any] = [ + singlechat_menu: list[tuple[str, Any]] = [ (_('Send File'), [ ('win.send-file-httpupload-', _('Upload File…')), ('win.send-file-jingle-', _('Send File Directly…')) @@ -66,7 +68,8 @@ def get_singlechat_menu(control_id: str, ('win.add-to-roster-', _('Add to Contact List…')), ('win.block-contact-', _('Block Contact…')), ('win.start-call-', _('Start Call…')), - ('win.information-', _('Information')) + ('win.information-', _('Information')), + ('app.remove-history', _('Remove History')) ]
if is_self_contact: @@ -90,7 +93,7 @@ def build_chatstate_menu() -> Gio.Menu: menu.append(label, action) return menu
- def build_menu(preset): + def build_menu(preset: list[tuple[str, Any]]): menu = Gio.Menu() for item in preset: if isinstance(item[1], str): @@ -116,6 +119,12 @@ def build_menu(preset): menuitem.set_action_and_target_value(action_name, variant_dict) menu.append_item(menuitem) + elif action_name == 'app.remove-history': + params = RemoveHistoryActionParams(account=account, jid=jid) + menuitem = Gio.MenuItem.new(label, action_name) + menuitem.set_action_and_target_value(action_name, + params.to_variant()) + menu.append_item(menuitem) else: menu.append(label, action_name + control_id) else: @@ -130,7 +139,7 @@ def build_menu(preset): return build_menu(singlechat_menu)
-def get_groupchat_menu(control_id: str, account: str, jid: str) -> Gio.Menu: +def get_groupchat_menu(control_id: str, account: str, jid: JID) -> Gio.Menu: groupchat_menu = [ ('win.information-', _('Information')), ('win.groupchat-settings-', _('Settings…')), @@ -140,6 +149,7 @@ def get_groupchat_menu(control_id: str, account: str, jid: str) -> Gio.Menu: ('win.request-voice-', _('Request Voice')), ('win.execute-command-', _('Execute Command…')), ('win.search-history', _('Search…')), + ('app.remove-history', _('Remove History')) ]
def build_menu(preset: list[tuple[str, str]]) -> Gio.Menu: @@ -154,7 +164,7 @@ def build_menu(preset: list[tuple[str, str]]) -> Gio.Menu: elif action_name == 'app.browse-history': menuitem = Gio.MenuItem.new(label, action_name) dict_ = {'account': GLib.Variant('s', account), - 'jid': GLib.Variant('s', jid)} + 'jid': GLib.Variant('s', str(jid))} variant_dict = GLib.Variant('a{sv}', dict_) menuitem.set_action_and_target_value( action_name, variant_dict) @@ -166,6 +176,13 @@ def build_menu(preset: list[tuple[str, str]]) -> Gio.Menu: menuitem.set_action_and_target_value( action_name, GLib.Variant('s', '')) menu.append_item(menuitem) + + elif action_name == 'app.remove-history': + params = RemoveHistoryActionParams(account=account, jid=jid) + menuitem = Gio.MenuItem.new(label, action_name) + menuitem.set_action_and_target_value(action_name, + params.to_variant()) + menu.append_item(menuitem) else: menu.append(label, action_name + control_id)
@@ -485,10 +502,7 @@ def get_subscription_menu(account: str, jid: str) -> Gio.Menu: return menu
-def get_start_chat_row_menu(account: str, - jid: Union[JID, str] - ) -> Gio.Menu: - jid = str(jid) +def get_start_chat_row_menu(account: str, jid: JID) -> Gio.Menu: menu_items: List[Tuple[str, str]] = [ ('forget-groupchat', _('Forget this Group Chat')), ] @@ -497,8 +511,8 @@ def get_start_chat_row_menu(account: str, action, label = item action = f'app.{action}' menuitem = Gio.MenuItem.new(label, action) - variant_list = GLib.Variant('as', [account, jid]) - menuitem.set_action_and_target_value(action, variant_list) + params = ForgetGroupchatActionParams(account=account, jid=jid) + menuitem.set_action_and_target_value(action, params.to_variant()) menu.append_item(menuitem) return menu
===================================== gajim/gtk/structs.py ===================================== @@ -29,3 +29,15 @@ class OpenEventActionParams(VariantMixin): sub_type: Optional[str] account: str jid: Optional[JID] + + +@dataclass +class RemoveHistoryActionParams(VariantMixin): + account: str + jid: Optional[JID] = None + + +@dataclass +class ForgetGroupchatActionParams(VariantMixin): + account: str + jid: JID
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/e236e90498c6507ec887433a8958005df...