Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
e236e904
by lovetox at 2022-01-09T08:11:12+01:00
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:
| ... | ... | @@ -1349,13 +1349,9 @@ def reset_archive_infos(self, jid: str) -> None: |
| 1349 | 1349 |
log.info('Reset message archive info: %s', jid)
|
| 1350 | 1350 |
self._delayed_commit()
|
| 1351 | 1351 |
|
| 1352 |
- def remove_chat_history(self,
|
|
| 1353 |
- account: str,
|
|
| 1354 |
- jid: str,
|
|
| 1355 |
- groupchat: bool = False
|
|
| 1356 |
- ) -> None:
|
|
| 1352 |
+ def remove_history(self, account: str, jid: JID) -> None:
|
|
| 1357 | 1353 |
"""
|
| 1358 |
- Remove chat history for a specific chat.
|
|
| 1354 |
+ Remove history for a specific chat.
|
|
| 1359 | 1355 |
If it's a group chat, remove last MAM ID as well.
|
| 1360 | 1356 |
"""
|
| 1361 | 1357 |
account_id = self.get_account_id(account)
|
| ... | ... | @@ -1363,15 +1359,19 @@ def remove_chat_history(self, |
| 1363 | 1359 |
sql = 'DELETE FROM logs WHERE account_id = ? AND jid_id = ?'
|
| 1364 | 1360 |
self._con.execute(sql, (account_id, jid_id))
|
| 1365 | 1361 |
|
| 1362 |
+ self._delayed_commit()
|
|
| 1363 |
+ log.info('Removed history for: %s', jid)
|
|
| 1364 |
+ |
|
| 1365 |
+ def forget_jid_data(self, account: str, jid: JID) -> None:
|
|
| 1366 |
+ jid_id = self.get_jid_id(jid)
|
|
| 1366 | 1367 |
sql = 'DELETE FROM jids WHERE jid_id = ?'
|
| 1367 | 1368 |
self._con.execute(sql, (jid_id,))
|
| 1368 | 1369 |
|
| 1369 |
- if groupchat:
|
|
| 1370 |
- sql = 'DELETE FROM last_archive_message WHERE jid_id = ?'
|
|
| 1371 |
- self._con.execute(sql, (jid_id,))
|
|
| 1370 |
+ sql = 'DELETE FROM last_archive_message WHERE jid_id = ?'
|
|
| 1371 |
+ self._con.execute(sql, (jid_id,))
|
|
| 1372 | 1372 |
|
| 1373 | 1373 |
self._delayed_commit()
|
| 1374 |
- log.info('Removed chat history for: %s', jid)
|
|
| 1374 |
+ log.info('Forgot data for: %s', jid)
|
|
| 1375 | 1375 |
|
| 1376 | 1376 |
def _cleanup_chat_history(self) -> None:
|
| 1377 | 1377 |
"""
|
| ... | ... | @@ -75,7 +75,9 @@ |
| 75 | 75 |
from gajim.gui.dialogs import ShortcutsWindow
|
| 76 | 76 |
from gajim.gui.about import AboutDialog
|
| 77 | 77 |
from gajim.gui.discovery import ServiceDiscoveryWindow
|
| 78 |
+from gajim.gui.structs import ForgetGroupchatActionParams
|
|
| 78 | 79 |
from gajim.gui.structs import OpenEventActionParams
|
| 80 |
+from gajim.gtk.structs import RemoveHistoryActionParams
|
|
| 79 | 81 |
|
| 80 | 82 |
|
| 81 | 83 |
ActionListT = list[tuple[str,
|
| ... | ... | @@ -380,8 +382,9 @@ def add_actions(self) -> None: |
| 380 | 382 |
('copy-text', 's', self._on_copy_text_action),
|
| 381 | 383 |
('open-link', 'as', self._on_open_link_action),
|
| 382 | 384 |
('open-mail', 's', self._on_open_mail_action),
|
| 385 |
+ ('remove-history', 'a{sv}', self._on_remove_history_action),
|
|
| 383 | 386 |
('create-groupchat', 's', self._on_create_groupchat_action),
|
| 384 |
- ('forget-groupchat', 'as', self._on_forget_groupchat_action),
|
|
| 387 |
+ ('forget-groupchat', 'a{sv}', self._on_forget_groupchat_action),
|
|
| 385 | 388 |
('groupchat-join', 'as', self._on_groupchat_join_action),
|
| 386 | 389 |
]
|
| 387 | 390 |
|
| ... | ... | @@ -775,20 +778,35 @@ def _on_open_chat_action(_action: Gio.SimpleAction, |
| 775 | 778 |
account, jid = param.get_strv()
|
| 776 | 779 |
app.interface.start_chat_from_jid(account, jid)
|
| 777 | 780 |
|
| 781 |
+ @staticmethod
|
|
| 782 |
+ def _on_remove_history_action(_action: Gio.SimpleAction,
|
|
| 783 |
+ param: GLib.Variant) -> None:
|
|
| 784 |
+ |
|
| 785 |
+ params = RemoveHistoryActionParams.from_variant(param)
|
|
| 786 |
+ |
|
| 787 |
+ if params.jid is not None:
|
|
| 788 |
+ app.storage.archive.remove_history(params.account, params.jid)
|
|
| 789 |
+ control = app.window.get_control(params.account, params.jid)
|
|
| 790 |
+ if control is not None:
|
|
| 791 |
+ control.reset_view()
|
|
| 792 |
+ else:
|
|
| 793 |
+ for control in app.window.get_controls(params.account):
|
|
| 794 |
+ control.reset_view()
|
|
| 795 |
+ |
|
| 778 | 796 |
@staticmethod
|
| 779 | 797 |
def _on_forget_groupchat_action(_action: Gio.SimpleAction,
|
| 780 | 798 |
param: GLib.Variant) -> None:
|
| 781 |
- account, jid = param.unpack()
|
|
| 782 |
- room_jid = JID.from_string(jid)
|
|
| 799 |
+ |
|
| 800 |
+ params = ForgetGroupchatActionParams.from_variant(param)
|
|
| 783 | 801 |
window = get_app_window('StartChatDialog')
|
| 784 |
- window.remove_row(account, str(room_jid))
|
|
| 802 |
+ window.remove_row(params.account, str(params.jid))
|
|
| 785 | 803 |
|
| 786 |
- client = app.get_client(account)
|
|
| 787 |
- client.get_module('MUC').leave(room_jid)
|
|
| 788 |
- client.get_module('Bookmarks').remove(room_jid)
|
|
| 804 |
+ client = app.get_client(params.account)
|
|
| 805 |
+ client.get_module('MUC').leave(params.jid)
|
|
| 806 |
+ client.get_module('Bookmarks').remove(params.jid)
|
|
| 789 | 807 |
|
| 790 |
- app.storage.archive.remove_chat_history(
|
|
| 791 |
- account, str(room_jid), groupchat=True)
|
|
| 808 |
+ app.storage.archive.remove_history(params.account, params.jid)
|
|
| 809 |
+ app.storage.archive.forget_jid_data(params.account, params.jid)
|
|
| 792 | 810 |
|
| 793 | 811 |
@staticmethod
|
| 794 | 812 |
def _on_groupchat_join_action(_action: Gio.SimpleAction,
|
| ... | ... | @@ -191,7 +191,7 @@ def __init__(self, account: str, jid: JID) -> None: |
| 191 | 191 |
|
| 192 | 192 |
self.control_menu = get_groupchat_menu(self.control_id,
|
| 193 | 193 |
self.account,
|
| 194 |
- self.room_jid)
|
|
| 194 |
+ self.contact.jid)
|
|
| 195 | 195 |
|
| 196 | 196 |
self.xml.settings_menu.set_menu_model(self.control_menu)
|
| 197 | 197 |
|
| ... | ... | @@ -41,6 +41,8 @@ |
| 41 | 41 |
from gajim.common.const import URIAction
|
| 42 | 42 |
from gajim.common.structs import URI
|
| 43 | 43 |
|
| 44 |
+from gajim.gui.structs import ForgetGroupchatActionParams
|
|
| 45 |
+from gajim.gui.structs import RemoveHistoryActionParams
|
|
| 44 | 46 |
from gajim.gui.const import ControlType
|
| 45 | 47 |
|
| 46 | 48 |
|
| ... | ... | @@ -52,7 +54,7 @@ def get_singlechat_menu(control_id: str, |
| 52 | 54 |
client = app.get_client(account)
|
| 53 | 55 |
is_self_contact = jid.bare == client.get_own_jid().bare
|
| 54 | 56 |
|
| 55 |
- singlechat_menu: List[Any] = [
|
|
| 57 |
+ singlechat_menu: list[tuple[str, Any]] = [
|
|
| 56 | 58 |
(_('Send File'), [
|
| 57 | 59 |
('win.send-file-httpupload-', _('Upload File…')),
|
| 58 | 60 |
('win.send-file-jingle-', _('Send File Directly…'))
|
| ... | ... | @@ -66,7 +68,8 @@ def get_singlechat_menu(control_id: str, |
| 66 | 68 |
('win.add-to-roster-', _('Add to Contact List…')),
|
| 67 | 69 |
('win.block-contact-', _('Block Contact…')),
|
| 68 | 70 |
('win.start-call-', _('Start Call…')),
|
| 69 |
- ('win.information-', _('Information'))
|
|
| 71 |
+ ('win.information-', _('Information')),
|
|
| 72 |
+ ('app.remove-history', _('Remove History'))
|
|
| 70 | 73 |
]
|
| 71 | 74 |
|
| 72 | 75 |
if is_self_contact:
|
| ... | ... | @@ -90,7 +93,7 @@ def build_chatstate_menu() -> Gio.Menu: |
| 90 | 93 |
menu.append(label, action)
|
| 91 | 94 |
return menu
|
| 92 | 95 |
|
| 93 |
- def build_menu(preset):
|
|
| 96 |
+ def build_menu(preset: list[tuple[str, Any]]):
|
|
| 94 | 97 |
menu = Gio.Menu()
|
| 95 | 98 |
for item in preset:
|
| 96 | 99 |
if isinstance(item[1], str):
|
| ... | ... | @@ -116,6 +119,12 @@ def build_menu(preset): |
| 116 | 119 |
menuitem.set_action_and_target_value(action_name,
|
| 117 | 120 |
variant_dict)
|
| 118 | 121 |
menu.append_item(menuitem)
|
| 122 |
+ elif action_name == 'app.remove-history':
|
|
| 123 |
+ params = RemoveHistoryActionParams(account=account, jid=jid)
|
|
| 124 |
+ menuitem = Gio.MenuItem.new(label, action_name)
|
|
| 125 |
+ menuitem.set_action_and_target_value(action_name,
|
|
| 126 |
+ params.to_variant())
|
|
| 127 |
+ menu.append_item(menuitem)
|
|
| 119 | 128 |
else:
|
| 120 | 129 |
menu.append(label, action_name + control_id)
|
| 121 | 130 |
else:
|
| ... | ... | @@ -130,7 +139,7 @@ def build_menu(preset): |
| 130 | 139 |
return build_menu(singlechat_menu)
|
| 131 | 140 |
|
| 132 | 141 |
|
| 133 |
-def get_groupchat_menu(control_id: str, account: str, jid: str) -> Gio.Menu:
|
|
| 142 |
+def get_groupchat_menu(control_id: str, account: str, jid: JID) -> Gio.Menu:
|
|
| 134 | 143 |
groupchat_menu = [
|
| 135 | 144 |
('win.information-', _('Information')),
|
| 136 | 145 |
('win.groupchat-settings-', _('Settings…')),
|
| ... | ... | @@ -140,6 +149,7 @@ def get_groupchat_menu(control_id: str, account: str, jid: str) -> Gio.Menu: |
| 140 | 149 |
('win.request-voice-', _('Request Voice')),
|
| 141 | 150 |
('win.execute-command-', _('Execute Command…')),
|
| 142 | 151 |
('win.search-history', _('Search…')),
|
| 152 |
+ ('app.remove-history', _('Remove History'))
|
|
| 143 | 153 |
]
|
| 144 | 154 |
|
| 145 | 155 |
def build_menu(preset: list[tuple[str, str]]) -> Gio.Menu:
|
| ... | ... | @@ -154,7 +164,7 @@ def build_menu(preset: list[tuple[str, str]]) -> Gio.Menu: |
| 154 | 164 |
elif action_name == 'app.browse-history':
|
| 155 | 165 |
menuitem = Gio.MenuItem.new(label, action_name)
|
| 156 | 166 |
dict_ = {'account': GLib.Variant('s', account),
|
| 157 |
- 'jid': GLib.Variant('s', jid)}
|
|
| 167 |
+ 'jid': GLib.Variant('s', str(jid))}
|
|
| 158 | 168 |
variant_dict = GLib.Variant('a{sv}', dict_)
|
| 159 | 169 |
menuitem.set_action_and_target_value(
|
| 160 | 170 |
action_name, variant_dict)
|
| ... | ... | @@ -166,6 +176,13 @@ def build_menu(preset: list[tuple[str, str]]) -> Gio.Menu: |
| 166 | 176 |
menuitem.set_action_and_target_value(
|
| 167 | 177 |
action_name, GLib.Variant('s', ''))
|
| 168 | 178 |
menu.append_item(menuitem)
|
| 179 |
+ |
|
| 180 |
+ elif action_name == 'app.remove-history':
|
|
| 181 |
+ params = RemoveHistoryActionParams(account=account, jid=jid)
|
|
| 182 |
+ menuitem = Gio.MenuItem.new(label, action_name)
|
|
| 183 |
+ menuitem.set_action_and_target_value(action_name,
|
|
| 184 |
+ params.to_variant())
|
|
| 185 |
+ menu.append_item(menuitem)
|
|
| 169 | 186 |
else:
|
| 170 | 187 |
menu.append(label, action_name + control_id)
|
| 171 | 188 |
|
| ... | ... | @@ -485,10 +502,7 @@ def get_subscription_menu(account: str, jid: str) -> Gio.Menu: |
| 485 | 502 |
return menu
|
| 486 | 503 |
|
| 487 | 504 |
|
| 488 |
-def get_start_chat_row_menu(account: str,
|
|
| 489 |
- jid: Union[JID, str]
|
|
| 490 |
- ) -> Gio.Menu:
|
|
| 491 |
- jid = str(jid)
|
|
| 505 |
+def get_start_chat_row_menu(account: str, jid: JID) -> Gio.Menu:
|
|
| 492 | 506 |
menu_items: List[Tuple[str, str]] = [
|
| 493 | 507 |
('forget-groupchat', _('Forget this Group Chat')),
|
| 494 | 508 |
]
|
| ... | ... | @@ -497,8 +511,8 @@ def get_start_chat_row_menu(account: str, |
| 497 | 511 |
action, label = item
|
| 498 | 512 |
action = f'app.{action}'
|
| 499 | 513 |
menuitem = Gio.MenuItem.new(label, action)
|
| 500 |
- variant_list = GLib.Variant('as', [account, jid])
|
|
| 501 |
- menuitem.set_action_and_target_value(action, variant_list)
|
|
| 514 |
+ params = ForgetGroupchatActionParams(account=account, jid=jid)
|
|
| 515 |
+ menuitem.set_action_and_target_value(action, params.to_variant())
|
|
| 502 | 516 |
menu.append_item(menuitem)
|
| 503 | 517 |
return menu
|
| 504 | 518 |
|
| ... | ... | @@ -29,3 +29,15 @@ class OpenEventActionParams(VariantMixin): |
| 29 | 29 |
sub_type: Optional[str]
|
| 30 | 30 |
account: str
|
| 31 | 31 |
jid: Optional[JID]
|
| 32 |
+ |
|
| 33 |
+ |
|
| 34 |
+@dataclass
|
|
| 35 |
+class RemoveHistoryActionParams(VariantMixin):
|
|
| 36 |
+ account: str
|
|
| 37 |
+ jid: Optional[JID] = None
|
|
| 38 |
+ |
|
| 39 |
+ |
|
| 40 |
+@dataclass
|
|
| 41 |
+class ForgetGroupchatActionParams(VariantMixin):
|
|
| 42 |
+ account: str
|
|
| 43 |
+ jid: JID
|