Philipp Hörist pushed to branch master at gajim / gajim
Commits: 8474c016 by wurstsalat at 2022-09-26T21:32:26+02:00 imprv: StartChat: Pass message body from XMPP URI
Fixes #11140
- - - - -
10 changed files:
- gajim/data/other/shortcuts.json - gajim/gtk/application.py - gajim/gtk/chat_list.py - gajim/gtk/chat_page.py - gajim/gtk/chat_stack.py - gajim/gtk/const.py - gajim/gtk/main.py - gajim/gtk/start_chat.py - gajim/gtk/status_icon.py - gajim/gui_interface.py
Changes:
===================================== gajim/data/other/shortcuts.json ===================================== @@ -5,7 +5,7 @@ "app.plugins": ["<Primary>E"], "app.xml-console": ["<Primary><Shift>X"], "app.file-transfer": ["<Primary>T"], - "app.start-chat::": ["<Primary>N"], + "app.start-chat(['', ''])": ["<Primary>N"], "app.create-groupchat::": ["<Primary>G"], "win.change-nickname": ["<Primary><Shift>N"], "win.change-subject": ["<Primary><Shift>S"],
===================================== gajim/gtk/application.py ===================================== @@ -305,7 +305,8 @@ def _open_uris(self, uris: list[str]) -> None: 'groupchat-join', GLib.Variant('as', [accounts[0], jid])) else: - self.activate_action('start-chat', GLib.Variant('s', jid)) + self.activate_action( + 'start-chat', GLib.Variant('as', [jid, '']))
elif cmd == 'roster': self.activate_action('add-contact', GLib.Variant('s', jid)) @@ -338,7 +339,7 @@ def _command_line(self, options = command_line.get_options_dict()
remote_commands = [ - ('start-chat', GLib.Variant('s', '')), + ('start-chat', GLib.Variant('as', ['', ''])), ('show', None) ]
@@ -562,10 +563,11 @@ def _on_quit_action(_action: Gio.SimpleAction, @staticmethod def _on_new_chat_action(_action: Gio.SimpleAction, param: GLib.Variant) -> None: - window = open_window('StartChatDialog') - search_text = param.get_string() - if search_text: - window.set_search_text(search_text) + + jid, initial_message = param.get_strv() + open_window('StartChatDialog', + jid=jid or None, + initial_message=initial_message or None)
@staticmethod def _on_profile_action(_action: Gio.SimpleAction,
===================================== gajim/gtk/chat_list.py ===================================== @@ -337,7 +337,7 @@ def _set_placeholder(self) -> None:
@staticmethod def _on_start_chat_clicked(_button: Gtk.Button) -> None: - app.app.activate_action('start-chat', GLib.Variant('s', '')) + app.app.activate_action('start-chat', GLib.Variant('as', ['', '']))
def set_filter(self, name: str) -> None: self._current_filter = name
===================================== gajim/gtk/chat_page.py ===================================== @@ -16,6 +16,7 @@
from typing import Any from typing import Literal +from typing import Optional from typing import TYPE_CHECKING
import logging @@ -127,7 +128,7 @@ def get_chat_stack(self) -> ChatStack:
@staticmethod def _on_start_chat_clicked(_button: Gtk.Button) -> None: - app.app.activate_action('start-chat', GLib.Variant('s', '')) + app.app.activate_action('start-chat', GLib.Variant('as', ['', '']))
@staticmethod def _on_button_release(paned: Gtk.Paned, event: Gdk.EventButton) -> None: @@ -222,7 +223,8 @@ def add_chat_for_workspace(self, type_: str, pinned: bool = False, position: int = -1, - select: bool = False) -> None: + select: bool = False, + message: Optional[str] = None) -> None:
client = app.get_client(account)
@@ -247,6 +249,9 @@ def add_chat_for_workspace(self, if select: self._chat_list_stack.select_chat(account, jid) self._chat_list_stack.store_open_chats(workspace_id) + if message is not None: + message_input = self._chat_stack.get_message_input() + message_input.insert_text(message)
def load_workspace_chats(self, workspace_id: str) -> None: open_chats = app.settings.get_workspace_setting(workspace_id,
===================================== gajim/gtk/chat_stack.py ===================================== @@ -794,4 +794,4 @@ def __init__(self): self.add(button)
def _on_start_chatting(self, _button: Gtk.Button) -> None: - app.app.activate_action('start-chat', GLib.Variant('s', '')) + app.app.activate_action('start-chat', GLib.Variant('as', ['', '']))
===================================== gajim/gtk/const.py ===================================== @@ -181,7 +181,7 @@ def __str__(self): ('remove-history', 'a{sv}'), ('shortcuts', None), ('show', None), - ('start-chat', 's'), + ('start-chat', 'as'), ('xml-console', None), ]
===================================== gajim/gtk/main.py ===================================== @@ -712,18 +712,23 @@ def add_chat(self, jid: JID, type_: str, select: bool = False, - workspace: str = 'default') -> None: + workspace: str = 'default', + message: Optional[str] = None + ) -> None: + if workspace == 'current': workspace_id = self.get_active_workspace() if workspace_id is None: workspace_id = self._workspace_side_bar.get_first_workspace() else: workspace_id = self._workspace_side_bar.get_first_workspace() + self._chat_page.add_chat_for_workspace(workspace_id, account, jid, type_, - select=select) + select=select, + message=message)
def add_private_chat(self, account: str,
===================================== gajim/gtk/start_chat.py ===================================== @@ -68,7 +68,11 @@ class Search(IntEnum):
class StartChatDialog(Gtk.ApplicationWindow): - def __init__(self, jid: Optional[str] = None) -> None: + def __init__(self, + jid: Optional[str] = None, + initial_message: Optional[str] = None + ) -> None: + Gtk.ApplicationWindow.__init__(self) self.set_name('StartChatDialog') self.set_application(app.app) @@ -138,16 +142,15 @@ def __init__(self, jid: Optional[str] = None) -> None: if rows: self._load_contacts(rows)
+ self._initial_message: dict[str, Optional[str]] = {} if jid is not None: - self.set_search_text(jid) + self._initial_message[jid] = initial_message + self._ui.search_entry.set_text(jid)
self.select_first_row() self._ui.connect_signals(self) self.show_all()
- def set_search_text(self, text: str) -> None: - self._ui.search_entry.set_text(text) - def remove_row(self, account: str, jid: str) -> None: for row in cast(list[ContactRow], self._ui.listbox.get_children()): if row.account == account and row.jid == jid: @@ -362,12 +365,14 @@ def _start_new_chat(self, row: ContactRow) -> None: self._disco_muc(row.account, jid, request_vcard=row.is_new)
else: + initial_message = self._initial_message.get(str(jid)) app.window.add_chat( row.account, jid, 'contact', select=True, - workspace='current') + workspace='current', + message=initial_message) self.ready_to_destroy = True self.destroy()
===================================== gajim/gtk/status_icon.py ===================================== @@ -179,7 +179,7 @@ def _on_account_state(self,
@staticmethod def _on_new_chat(_widget: Gtk.MenuItem) -> None: - app.app.activate_action('start-chat', GLib.Variant('s', '')) + app.app.activate_action('start-chat', GLib.Variant('as', ['', '']))
@staticmethod def _on_sounds_mute(widget: Gtk.CheckMenuItem) -> None:
===================================== gajim/gui_interface.py ===================================== @@ -466,8 +466,8 @@ def start_chat_from_jid(account: str, message_input.insert_text(message) return
- # TODO: handle message arg in StartChat - app.app.activate_action('start-chat', GLib.Variant('s', str(jid))) + app.app.activate_action( + 'start-chat', GLib.Variant('as', [str(jid), message or '']))
@staticmethod def create_account(account: str,
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/8474c016624fbe9086c3cb78b1a93d9b4...