Philipp Hörist pushed to branch newcontrol at gajim / gajim
Commits: b9e62055 by lovetox at 2022-06-28T23:15:58+02:00 Move send_message() to chat stack
- - - - -
6 changed files:
- gajim/gtk/chat_stack.py - gajim/gtk/control_stack.py - gajim/gtk/controls/base.py - gajim/gtk/controls/chat.py - gajim/gtk/controls/groupchat.py - gajim/gtk/message_actions_box.py
Changes:
===================================== gajim/gtk/chat_stack.py ===================================== @@ -25,11 +25,12 @@ from gi.repository import Gtk from nbxmpp.protocol import JID
-from gajim.common import app +from gajim.common import app, helpers from gajim.common.const import CallType from gajim.common.modules.contacts import BareContact from gajim.common.modules.contacts import GroupchatContact from gajim.common.modules.contacts import GroupchatParticipant +from gajim.common.structs import OutgoingMessage from gajim.common.types import ChatContactT
from .chat_banner import ChatBanner @@ -170,7 +171,10 @@ def _on_action(self, account = contact.account jid = contact.jid
- if action_name == 'block-contact': + if action_name == 'send-message': + self._on_send_message() + + elif action_name == 'block-contact': app.window.block_contact(account, jid)
elif action_name == 'information': @@ -238,6 +242,62 @@ def _on_stateful_action(self, action.set_state(param) contact.settings.set('send_marker', param.get_boolean())
+ def _on_send_message(self) -> None: + self._message_action_box.msg_textview.replace_emojis() + message = self._message_action_box.msg_textview.get_text() + + control = self._control_stack.get_current_control() + + action = app.window.lookup_action('set-encryption') + encryption = action.get_state().get_string() + + if encryption: + self.sendmessage = True + app.plugin_manager.extension_point( + 'send_message' + encryption, + control) + if not self.sendmessage: + return + + contact = self._current_contact + client = app.get_client(contact.account) + + message = helpers.remove_invalid_xml_chars(message) + if message in ('', None, '\n'): + return + + # if process_commands and self.process_as_command(message): + # return + + # TODO + # label = self.get_seclabel() + + correct_id: Optional[str] = None + if control.correcting and control.last_sent_msg: + correct_id = control.last_sent_msg + else: + correct_id = None + + chatstate = client.get_module('Chatstate').get_active_chatstate( + contact) + + type_ = 'chat' + if isinstance(contact, GroupchatContact): + type_ = 'groupchat' + + message_ = OutgoingMessage(account=contact.account, + contact=contact, + message=message, + type_=type_, + chatstate=chatstate, + # label=label, + control=control, + correct_id=correct_id) + + client.send_message(message_) + + self._message_action_box.msg_textview.clear() + def _get_pref_ft_method(self, contact: ChatContactT) -> Optional[str]: ft_pref = app.settings.get_account_setting(contact.account, 'filetransfer_preference')
===================================== gajim/gtk/control_stack.py ===================================== @@ -53,6 +53,9 @@ def get_control(self, account: str, jid: JID) -> Optional[ControlT]: except KeyError: return None
+ def get_current_control(self) -> ControlT: + return self._current_control + def get_controls(self, account: Optional[str] ) -> Generator[ControlT, None, None]: if account is None:
===================================== gajim/gtk/controls/base.py ===================================== @@ -589,60 +589,6 @@ def get_seclabel(self) -> Optional[str]: def get_our_nick(self) -> str: return app.nicks[self.account]
- def _on_send_message(self, *args: Any) -> None: - self.msg_textview.replace_emojis() - message = self.msg_textview.get_text() - self.send_message(message) - - def send_message(self, - message: str, - type_: str = 'chat', - resource: Optional[str] = None, - process_commands: bool = True, - attention: bool = False - ) -> None: - """ - Send the given message to the active tab. Doesn't return None if error - """ - if not message or message == '\n': - return None - - if process_commands and self.process_as_command(message): - return - - label = self.get_seclabel() - - correct_id: Optional[str] = None - if self.correcting and self.last_sent_msg: - correct_id = self.last_sent_msg - else: - correct_id = None - - chatstate = self._client.get_module('Chatstate').get_active_chatstate( - self.contact) - - message_ = OutgoingMessage(account=self.account, - contact=self.contact, - message=message, - type_=type_, - chatstate=chatstate, - resource=resource, - user_nick=self.user_nick, - label=label, - control=self, - attention=attention, - correct_id=correct_id) - - self._client.send_message(message_) - - # Record the history of sent messages - # self.save_message(message, 'sent') - - # Be sure to send user nickname only once according to JEP-0172 - self.user_nick = None - - self.msg_textview.clear() - def _allow_add_message(self) -> bool: # Only add messages if the view is already populated return self.is_chat_loaded and self._scrolled_view.get_lower_complete()
===================================== gajim/gtk/controls/chat.py ===================================== @@ -103,6 +103,7 @@ def jid(self) -> JID: return self.contact.jid
def focus(self) -> None: + # TODO does not work anymore if not hasattr(self, 'msg_textview'): # focus() is called sometimes with GLib.idle_add() # This means there is the possibility that shutdown() was called @@ -222,32 +223,6 @@ def update_ui(self) -> None: self.update_toolbar() self.update_actions()
- def send_message(self, - message: str, - process_commands: bool = True, - attention: bool = False - ) -> None: - """ - Send a message to contact - """ - - if self.encryption: - self.sendmessage = True - app.plugin_manager.extension_point('send_message' + self.encryption, - self) - if not self.sendmessage: - return - - message = helpers.remove_invalid_xml_chars(message) - if message in ('', None, '\n'): - return - - BaseControl.send_message(self, - message, - type_='chat', - process_commands=process_commands, - attention=attention) - def add_message(self, text: str, kind: str,
===================================== gajim/gtk/controls/groupchat.py ===================================== @@ -574,7 +574,8 @@ def add_message(self, highlight = helpers.message_needs_highlight( text, self.contact.nickname, self._client.get_own_jid().bare)
- self.msg_textview.process_outgoing_message(contact, highlight) + # TODO + # self.msg_textview.process_outgoing_message(contact, highlight)
BaseControl.add_message(self, text, @@ -1023,55 +1024,6 @@ def _on_message_sent(self, event: events.MessageSent) -> None: self.msg_textview.get_style_context().remove_class( 'gajim-msg-correcting')
- def send_message(self, - message: str, - process_commands: bool = True - ) -> None: - """ - Call this function to send our message - """ - if not message: - return - - if self.encryption: - self.sendmessage = True - app.plugin_manager.extension_point( - 'send_message' + self.encryption, self) - if not self.sendmessage: - return - - if process_commands and self.process_as_command(message): - return - - message = helpers.remove_invalid_xml_chars(message) - - if not message: - return - - label = self.get_seclabel() - if message != '' or message != '\n': - # self.save_message(message, 'sent') - - if self.correcting and self.last_sent_msg: - correct_id = self.last_sent_msg - else: - correct_id = None - chatstate = self._client.get_module('Chatstate')\ - .get_active_chatstate(self.contact) - - # Send the message - message_ = OutgoingMessage(account=self.account, - contact=self.contact, - message=message, - type_='groupchat', - label=label, - chatstate=chatstate, - correct_id=correct_id) - self._client.send_message(message_) - - self.msg_textview.get_buffer().set_text('') - self.msg_textview.grab_focus() - def _on_message_error(self, event: events.MessageError) -> None: self.conversation_view.show_error(event.message_id, event.error)
@@ -1156,7 +1108,9 @@ def delegate_action(self, action: str) -> int: def focus(self) -> None: page_name = self._get_current_page() if page_name == 'groupchat': - self.msg_textview.grab_focus() + # TODO + # self.msg_textview.grab_focus() + pass elif page_name == 'password': self.xml.password_entry.grab_focus_without_selecting() elif page_name == 'nickname':
===================================== gajim/gtk/message_actions_box.py ===================================== @@ -466,14 +466,14 @@ def _on_textview_key_press_event(self, textview.insert_newline() return True
- if not app.account_is_available(self.account): + if not app.account_is_available(self._contact.account): # we are not connected ErrorDialog( _('No Connection Available'), _('Your message can not be sent until you are connected.')) return True
- self._on_send_message() + app.window.activate_action('send-message', None) return True
elif event.keyval == Gdk.KEY_z: # CTRL+z
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/b9e620553475a5232112ca07d357905c4...