Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 8a812783 by wurstsalat at 2021-12-11T13:23:29+01:00 Improve logic for adding messages
- - - - -
3 changed files:
- gajim/gtk/chat_page.py - gajim/gtk/controls/base.py - gajim/gtk/main.py
Changes:
===================================== gajim/gtk/chat_page.py ===================================== @@ -92,7 +92,7 @@ def __init__(self): self._ui.paned.set_position(app.settings.get('chat_handle_position')) self._ui.paned.connect('button-release-event', self._on_button_release)
- self._currently_loaded_control: Optional[ControlType] = None + self._last_control: Optional[ControlType] = None self._startup_finished: bool = False
self._add_actions() @@ -168,7 +168,7 @@ def unload_idle_chats(self) -> bool: return True
def _on_chat_selected(self, - chat_list_stack: ChatListStack, + _chat_list_stack: ChatListStack, workspace_id: str, account: str, jid: JID) -> None: @@ -181,11 +181,12 @@ def _on_chat_selected(self, control = self.get_control(account, jid) if control is None: return - if self._currently_loaded_control != control: - if self._currently_loaded_control is not None: - self._currently_loaded_control.set_control_active(False) + + if control != self._last_control: + if self._last_control is not None: + self._last_control.set_control_active(False) control.set_control_active(True) - self._currently_loaded_control = control + self._last_control = control
def _on_chat_unselected(self, _chat_list_stack): self._chat_stack.clear() @@ -302,7 +303,7 @@ def remove_chat(self, account: str, jid: JID) -> None: def _on_chat_removed(self, _chat_list: ChatList, account: str, jid: JID, type_: str) -> None: self._chat_stack.remove_chat(account, jid) - self._currently_loaded_control = None + self._last_control = None if type_ == 'groupchat': client = app.get_client(account) client.get_module('MUC').leave(jid) @@ -324,8 +325,9 @@ def get_active_control(self) -> Optional[ControlType]: return None return self.get_control(chat.account, chat.jid)
- def get_currently_loaded_control(self) -> Optional[ControlType]: - return self._currently_loaded_control + def is_chat_idle(self, account: str, jid: JID) -> bool: + entry = self._chat_idle_time.get((account, jid)) + return entry is not None
def get_controls(self, account: Optional[str] ) -> Generator[ControlType, None, None]:
===================================== gajim/gtk/controls/base.py ===================================== @@ -1123,6 +1123,12 @@ def save_message(self, message: str, msg_type: str) -> None: else: self.received_history_pos = pos
+ def _allow_add_message(self) -> bool: + lower_complete = self._scrolled_view.get_lower_complete() + chat_idle = app.window.is_chat_idle(self.account, self.contact.jid) + chat_selected = bool(app.window.get_active_control() is not None) + return lower_complete and chat_idle or chat_selected + def add_info_message(self, text: str) -> None: self.conversation_view.add_info_message(text)
@@ -1130,15 +1136,11 @@ def add_file_transfer(self, transfer: HTTPFileTransfer) -> None: self.conversation_view.add_file_transfer(transfer)
def add_jingle_file_transfer(self, event): - control_selected = bool( - self == app.window.get_currently_loaded_control()) - if self._scrolled_view.get_lower_complete() and control_selected: + if self._allow_add_message(): self.conversation_view.add_jingle_file_transfer(event)
def add_call_message(self, event): - control_selected = bool( - self == app.window.get_currently_loaded_control()) - if self._scrolled_view.get_lower_complete() and control_selected: + if self._allow_add_message(): self.conversation_view.add_call_message(event=event)
def add_message(self, @@ -1157,9 +1159,7 @@ def add_message(self, if additional_data is None: additional_data = AdditionalDataDict()
- control_selected = bool( - self == app.window.get_currently_loaded_control()) - if self._scrolled_view.get_lower_complete() and control_selected: + if self._allow_add_message(): self.conversation_view.add_message( text, kind,
===================================== gajim/gtk/main.py ===================================== @@ -506,8 +506,8 @@ def get_controls(self, account: Optional[str] = None def get_active_control(self) -> Optional[ControlType]: return self._chat_page.get_active_control()
- def get_currently_loaded_control(self) -> Optional[ControlType]: - return self._chat_page.get_currently_loaded_control() + def is_chat_idle(self, account: str, jid: JID) -> bool: + return self._chat_page.is_chat_idle(account, jid)
def chat_exists(self, account: str, jid: JID) -> bool: return self._chat_page.chat_exists(account, jid)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/8a812783d7713cd510fb9dbf91ccd51c5...