Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: f55a0127 by wurstsalat at 2021-12-11T20:30:07+01:00 (Re)store unread counts
- - - - -
4 changed files:
- gajim/common/storage/cache.py - gajim/gtk/chat_list.py - gajim/gtk/chat_list_stack.py - gajim/gtk/main.py
Changes:
===================================== gajim/common/storage/cache.py ===================================== @@ -317,6 +317,11 @@ def get_contact(self, jid, prop): # TODO: Expire entries return value
+ @timeit + def get_unread(self): + sql = 'SELECT * FROM unread' + return self._con.execute(sql).fetchall() + @timeit def get_unread_count(self, account, jid): sql = '''SELECT count, message_id, timestamp FROM unread @@ -325,10 +330,14 @@ def get_unread_count(self, account, jid):
@timeit def set_unread_count(self, account, jid, count, message_id, timestamp): - sql = '''INSERT INTO unread (account, jid, count, message_id, timestamp) - VALUES (?, ?, ?, ?, ?)''' - self._con.execute(sql, (account, jid, count, message_id, timestamp)) - self._delayed_commit() + if self.get_unread_count(account, jid) is not None: + self.update_unread_count(account, jid, count) + else: + sql = '''INSERT INTO unread + (account, jid, count, message_id, timestamp) + VALUES (?, ?, ?, ?, ?)''' + self._con.execute(sql, (account, jid, count, message_id, timestamp)) + self._delayed_commit()
@timeit def update_unread_count(self, account, jid, count):
===================================== gajim/gtk/chat_list.py ===================================== @@ -113,6 +113,15 @@ def get_chat_unread_count(self, return chat.unread_count return None
+ def set_chat_unread_count(self, + account: str, + jid: JID, + count: int + ) -> None: + chat = self._chats.get((account, jid)) + if chat is not None: + chat.unread_count = count + def mark_as_read(self, account: str, jid: JID) -> None: chat = self._chats.get((account, jid)) if chat is not None: @@ -744,6 +753,12 @@ def add_unread(self, text: str) -> None: self._unread_count += 1 self._update_unread() self.get_parent().emit_unread_changed() + app.storage.cache.set_unread_count( + self.account, + self.jid, + self.get_real_unread_count(), + self.message_id, + self.timestamp)
if self.contact.is_groupchat: needs_highlight = message_needs_highlight( @@ -758,6 +773,7 @@ def reset_unread(self) -> None: self._unread_count = 0 self._update_unread() self.get_parent().emit_unread_changed() + app.storage.cache.reset_unread_count(self.account, self.jid)
# Add class again in case we were mentioned previously if self.contact.is_groupchat and not self.contact.can_notify():
===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -260,6 +260,14 @@ def get_chat_unread_count(self, return count return None
+ def set_chat_unread_count(self, + account: str, + jid: JID, + count: int + ) -> None: + for chat_list in self._chat_lists.values(): + chat_list.set_chat_unread_count(account, jid, count) + def mark_as_read(self, account: str, jid: JID) -> None: for chat_list in self._chat_lists.values(): chat_list.mark_as_read(account, jid)
===================================== gajim/gtk/main.py ===================================== @@ -123,6 +123,7 @@ def __init__(self):
self._check_for_account() self._load_chats() + self._load_unread_counts() self._add_actions() self._add_actions2()
@@ -332,6 +333,16 @@ def _set_startup_finished(self): self._startup_finished = True self._chat_page.set_startup_finished()
+ def _load_unread_counts(self) -> None: + chats = app.storage.cache.get_unread() + chat_list_stack = self._chat_page.get_chat_list_stack() + + for chat in chats: + chat_list_stack.set_chat_unread_count( + chat.account, + chat.jid, + chat.count) + def show_account_page(self, account: str) -> None: self._app_side_bar.unselect_all() self._workspace_side_bar.unselect_all()
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/f55a012764a1a4e0da7bc7b34441fc0c0...