diff options
author | lovetox <philipp@hoerist.com> | 2022-05-23 20:23:08 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2022-05-23 20:23:08 +0300 |
commit | 727beb711d2919b10d427622711160daf7a7380c (patch) | |
tree | fa10fda0c688e49de28db2e6cf1f451864dd279c | |
parent | 80112fedddb833fb9559c5fc29b175e21bbcc242 (diff) |
fix: Reset conversation view when switching chat
This may help to work around the issue that sometimes the ConversationView
freezes.
-rw-r--r-- | gajim/gtk/chat_page.py | 30 | ||||
-rw-r--r-- | gajim/gtk/chat_stack.py | 8 | ||||
-rw-r--r-- | gajim/gtk/const.py | 2 | ||||
-rw-r--r-- | gajim/gtk/main.py | 6 |
4 files changed, 2 insertions, 44 deletions
diff --git a/gajim/gtk/chat_page.py b/gajim/gtk/chat_page.py index 200bcd763..6e5527077 100644 --- a/gajim/gtk/chat_page.py +++ b/gajim/gtk/chat_page.py @@ -17,7 +17,6 @@ from typing import Literal from typing import Optional from typing import Generator -import time import logging from gi.repository import Gdk @@ -38,7 +37,6 @@ from .chat_list_stack import ChatListStack from .chat_stack import ChatStack from .search_view import SearchView from .types import ControlT -from .const import UNLOAD_CHAT_TIME log = logging.getLogger('gajim.gui.chat_page') @@ -55,8 +53,6 @@ class ChatPage(Gtk.Box): def __init__(self): Gtk.Box.__init__(self) - self._chat_idle_time: dict[tuple[str, JID], Optional[float]] = {} - self._ui = get_builder('chat_paned.ui') self.add(self._ui.paned) self._ui.connect_signals(self) @@ -146,31 +142,6 @@ class ChatPage(Gtk.Box): def _on_edit_workspace_clicked(_button: Gtk.Button) -> None: app.window.activate_action('edit-workspace', GLib.Variant('s', '')) - def _reset_chat_idle_time(self, account: str, jid: JID) -> None: - # Set the idle time of the current chat to None - # and start the timer for the last one - for chat, idle_time in self._chat_idle_time.items(): - if idle_time is None: - self._chat_idle_time[chat] = time.time() - - self._chat_idle_time[(account, jid)] = None - - def unload_idle_chats(self) -> bool: - log.debug('Unload idle chats') - for chat, idle_time in list(self._chat_idle_time.items()): - if idle_time is None: - continue - - if time.time() - UNLOAD_CHAT_TIME > idle_time: - account, jid = chat - self._chat_stack.unload_chat(account, jid) - self._chat_idle_time.pop(chat) - log.debug('Chat %s:%s unloaded', account, jid) - - # Return true because we call this method with - # GLib.timeout_add_seconds() - return True - def _on_chat_selected(self, _chat_list_stack: ChatListStack, workspace_id: str, @@ -180,7 +151,6 @@ class ChatPage(Gtk.Box): self._chat_stack.show_chat(account, jid) self._search_view.set_context(account, jid) self.emit('chat-selected', workspace_id, account, jid) - self._reset_chat_idle_time(account, jid) def _on_chat_unselected(self, _chat_list_stack: ChatListStack) -> None: self._chat_stack.clear() diff --git a/gajim/gtk/chat_stack.py b/gajim/gtk/chat_stack.py index 88e4b9d4d..286e66fa4 100644 --- a/gajim/gtk/chat_stack.py +++ b/gajim/gtk/chat_stack.py @@ -118,6 +118,8 @@ class ChatStack(Gtk.Stack, EventHelper): if self._current_control is not None: self._current_control.set_control_active(False) + self._current_control.reset_view() + control.set_control_active(True) self._current_control = control @@ -130,12 +132,6 @@ class ChatStack(Gtk.Stack, EventHelper): 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: - return - control.reset_view() - def clear(self) -> None: self.set_visible_child_name('empty') self._current_control = None diff --git a/gajim/gtk/const.py b/gajim/gtk/const.py index f22d44ee0..dc0ef5f71 100644 --- a/gajim/gtk/const.py +++ b/gajim/gtk/const.py @@ -55,8 +55,6 @@ DEFAULT_WORKSPACE_COLOR = 'rgb(191,15,167)' # Drag and drop target type URI list (for dropped files) TARGET_TYPE_URI_LIST = 80 -UNLOAD_CHAT_TIME = 300 # seconds - @unique class Theme(IntEnum): diff --git a/gajim/gtk/main.py b/gajim/gtk/main.py index e30877843..51633798f 100644 --- a/gajim/gtk/main.py +++ b/gajim/gtk/main.py @@ -57,7 +57,6 @@ from .util import restore_main_window_position from .util import save_main_window_position from .util import open_window from .util import set_urgency_hint -from .const import UNLOAD_CHAT_TIME from .structs import AccountJidParam from .structs import AddChatActionParams from .structs import actionmethod @@ -145,7 +144,6 @@ class MainWindow(Gtk.ApplicationWindow, EventHelper): self._add_actions2() self._prepare_window() - self._start_timers() chat_list_stack = self._chat_page.get_chat_list_stack() app.app.systray.connect_unread_widget(chat_list_stack, @@ -155,10 +153,6 @@ class MainWindow(Gtk.ApplicationWindow, EventHelper): client.connect_signal('state-changed', self._on_client_state_changed) - def _start_timers(self) -> None: - GLib.timeout_add_seconds(UNLOAD_CHAT_TIME, - self._chat_page.unload_idle_chats) - def _prepare_window(self) -> None: if app.settings.get('main_window_skip_taskbar'): self.set_property('skip-taskbar-hint', True) |