Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: b4c09866 by wurstsalat at 2021-12-14T23:10:45+01:00 Conversation: Properly check if chat is loaded, improve view reset
- - - - -
5 changed files:
- gajim/gtk/chat_page.py - gajim/gtk/chat_stack.py - gajim/gtk/controls/base.py - gajim/gtk/conversation/scrolled.py - gajim/gtk/main.py
Changes:
===================================== gajim/gtk/chat_page.py ===================================== @@ -325,9 +325,8 @@ def get_active_control(self) -> Optional[ControlType]: return None return self.get_control(chat.account, chat.jid)
- def is_chat_idle(self, account: str, jid: JID) -> bool: - entry = self._chat_idle_time.get((account, jid)) - return entry is not None + def is_chat_loaded(self, account: str, jid: JID) -> bool: + return self._chat_stack.is_chat_loaded(account, jid)
def get_controls(self, account: Optional[str] ) -> Generator[ControlType, None, None]:
===================================== gajim/gtk/chat_stack.py ===================================== @@ -112,6 +112,12 @@ def show_chat(self, account: str, jid: JID) -> None:
GLib.idle_add(control.focus)
+ def is_chat_loaded(self, account, jid) -> bool: + control = self.get_control(account, jid) + if control is None: + return False + return control.is_chat_loaded + def unload_chat(self, account: str, jid: JID) -> None: control = self.get_control(account, jid) if control is None:
===================================== gajim/gtk/controls/base.py ===================================== @@ -225,8 +225,8 @@ def __init__(self, widget_name: str, account: str, jid: JID) -> None:
self.xml.hbox.pack_start(self.msg_scrolledwindow, True, True, 0)
- # Used for initial message row fetching in ConversationView - self._initial_fetch_finished: bool = False + # Keeps track of whether the ConversationView is populated + self._chat_loaded: bool = False
# the following vars are used to keep history of user's messages self.sent_history: List[str] = [] @@ -511,8 +511,7 @@ def _sec_labels_received(self, event):
def delegate_action(self, action: str) -> int: if action == 'clear-chat': - self.conversation_view.clear() - self._scrolled_view.reset() + self.reset_view() return Gdk.EVENT_STOP
if action == 'delete-line': @@ -1123,10 +1122,10 @@ def save_message(self, message: str, msg_type: str) -> None: self.received_history_pos = pos
def _allow_add_message(self) -> bool: + # Only add messages if the view is already populated + chat_loaded = app.window.is_chat_loaded(self.account, self.contact.jid) 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) + return chat_loaded and lower_complete
def add_info_message(self, text: str) -> None: self.conversation_view.add_info_message(text) @@ -1315,9 +1314,9 @@ def update_text_tags(self): self.conversation_view.update_text_tags()
def set_control_active(self, state: bool) -> None: - if not self._initial_fetch_finished: + if not self._chat_loaded: self.fetch_n_lines_history(self._scrolled_view, True, 20) - self._initial_fetch_finished = True + self._chat_loaded = True
if state: self.set_emoticon_popover() @@ -1332,17 +1331,21 @@ def set_control_active(self, state: bool) -> None: self._client.get_module('Chatstate').set_chatstate( self.contact, Chatstate.INACTIVE)
+ @property + def is_chat_loaded(self) -> bool: + return self._chat_loaded + def reset_view(self) -> None: - self._initial_fetch_finished = False + self._chat_loaded = False self.conversation_view.clear() + self._scrolled_view.reset()
def get_autoscroll(self) -> bool: return self._scrolled_view.get_autoscroll()
def scroll_to_end(self, force: bool = False) -> None: # Clear view and reload conversation - self.conversation_view.clear() - self._scrolled_view.reset() + self.reset_view() self.conversation_view.scroll_to_end(force)
def scroll_to_message(self, log_line_id: str, timestamp: float) -> None: @@ -1350,8 +1353,7 @@ def scroll_to_message(self, log_line_id: str, timestamp: float) -> None: if row is None: # Clear view and reload conversation around timestamp self.conversation_view.lock() - self.conversation_view.clear() - self._scrolled_view.reset() + self.reset_view() before, at_after = app.storage.archive.get_conversation_around( self.account, self.contact.jid, timestamp) self.add_messages(before)
===================================== gajim/gtk/conversation/scrolled.py ===================================== @@ -111,9 +111,12 @@ def _on_adj_upper_changed(self, if self._requesting == 'before': adj.set_value(adj.get_value() + diff)
- self._lower_complete = True - self._autoscroll = True - self.emit('autoscroll-changed', self._autoscroll) + if upper == adj.get_page_size(): + # There is no scrollbar + self.emit('request-history', True) + self._lower_complete = True + self._autoscroll = True + self.emit('autoscroll-changed', self._autoscroll)
self._requesting = None
===================================== gajim/gtk/main.py ===================================== @@ -517,8 +517,8 @@ def get_controls(self, account: Optional[str] = None def get_active_control(self) -> Optional[ControlType]: return self._chat_page.get_active_control()
- def is_chat_idle(self, account: str, jid: JID) -> bool: - return self._chat_page.is_chat_idle(account, jid) + def is_chat_loaded(self, account: str, jid: JID) -> bool: + return self._chat_page.is_chat_loaded(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/b4c09866890c947f487b97101e5fe6f16...