Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
f55a0127
by wurstsalat at 2021-12-11T20:30:07+01:00
4 changed files:
Changes:
| ... | ... | @@ -317,6 +317,11 @@ def get_contact(self, jid, prop): |
| 317 | 317 |
# TODO: Expire entries
|
| 318 | 318 |
return value
|
| 319 | 319 |
|
| 320 |
+ @timeit
|
|
| 321 |
+ def get_unread(self):
|
|
| 322 |
+ sql = 'SELECT * FROM unread'
|
|
| 323 |
+ return self._con.execute(sql).fetchall()
|
|
| 324 |
+ |
|
| 320 | 325 |
@timeit
|
| 321 | 326 |
def get_unread_count(self, account, jid):
|
| 322 | 327 |
sql = '''SELECT count, message_id, timestamp FROM unread
|
| ... | ... | @@ -325,10 +330,14 @@ def get_unread_count(self, account, jid): |
| 325 | 330 |
|
| 326 | 331 |
@timeit
|
| 327 | 332 |
def set_unread_count(self, account, jid, count, message_id, timestamp):
|
| 328 |
- sql = '''INSERT INTO unread (account, jid, count, message_id, timestamp)
|
|
| 329 |
- VALUES (?, ?, ?, ?, ?)'''
|
|
| 330 |
- self._con.execute(sql, (account, jid, count, message_id, timestamp))
|
|
| 331 |
- self._delayed_commit()
|
|
| 333 |
+ if self.get_unread_count(account, jid) is not None:
|
|
| 334 |
+ self.update_unread_count(account, jid, count)
|
|
| 335 |
+ else:
|
|
| 336 |
+ sql = '''INSERT INTO unread
|
|
| 337 |
+ (account, jid, count, message_id, timestamp)
|
|
| 338 |
+ VALUES (?, ?, ?, ?, ?)'''
|
|
| 339 |
+ self._con.execute(sql, (account, jid, count, message_id, timestamp))
|
|
| 340 |
+ self._delayed_commit()
|
|
| 332 | 341 |
|
| 333 | 342 |
@timeit
|
| 334 | 343 |
def update_unread_count(self, account, jid, count):
|
| ... | ... | @@ -113,6 +113,15 @@ def get_chat_unread_count(self, |
| 113 | 113 |
return chat.unread_count
|
| 114 | 114 |
return None
|
| 115 | 115 |
|
| 116 |
+ def set_chat_unread_count(self,
|
|
| 117 |
+ account: str,
|
|
| 118 |
+ jid: JID,
|
|
| 119 |
+ count: int
|
|
| 120 |
+ ) -> None:
|
|
| 121 |
+ chat = self._chats.get((account, jid))
|
|
| 122 |
+ if chat is not None:
|
|
| 123 |
+ chat.unread_count = count
|
|
| 124 |
+ |
|
| 116 | 125 |
def mark_as_read(self, account: str, jid: JID) -> None:
|
| 117 | 126 |
chat = self._chats.get((account, jid))
|
| 118 | 127 |
if chat is not None:
|
| ... | ... | @@ -744,6 +753,12 @@ def add_unread(self, text: str) -> None: |
| 744 | 753 |
self._unread_count += 1
|
| 745 | 754 |
self._update_unread()
|
| 746 | 755 |
self.get_parent().emit_unread_changed()
|
| 756 |
+ app.storage.cache.set_unread_count(
|
|
| 757 |
+ self.account,
|
|
| 758 |
+ self.jid,
|
|
| 759 |
+ self.get_real_unread_count(),
|
|
| 760 |
+ self.message_id,
|
|
| 761 |
+ self.timestamp)
|
|
| 747 | 762 |
|
| 748 | 763 |
if self.contact.is_groupchat:
|
| 749 | 764 |
needs_highlight = message_needs_highlight(
|
| ... | ... | @@ -758,6 +773,7 @@ def reset_unread(self) -> None: |
| 758 | 773 |
self._unread_count = 0
|
| 759 | 774 |
self._update_unread()
|
| 760 | 775 |
self.get_parent().emit_unread_changed()
|
| 776 |
+ app.storage.cache.reset_unread_count(self.account, self.jid)
|
|
| 761 | 777 |
|
| 762 | 778 |
# Add class again in case we were mentioned previously
|
| 763 | 779 |
if self.contact.is_groupchat and not self.contact.can_notify():
|
| ... | ... | @@ -260,6 +260,14 @@ def get_chat_unread_count(self, |
| 260 | 260 |
return count
|
| 261 | 261 |
return None
|
| 262 | 262 |
|
| 263 |
+ def set_chat_unread_count(self,
|
|
| 264 |
+ account: str,
|
|
| 265 |
+ jid: JID,
|
|
| 266 |
+ count: int
|
|
| 267 |
+ ) -> None:
|
|
| 268 |
+ for chat_list in self._chat_lists.values():
|
|
| 269 |
+ chat_list.set_chat_unread_count(account, jid, count)
|
|
| 270 |
+ |
|
| 263 | 271 |
def mark_as_read(self, account: str, jid: JID) -> None:
|
| 264 | 272 |
for chat_list in self._chat_lists.values():
|
| 265 | 273 |
chat_list.mark_as_read(account, jid)
|
| ... | ... | @@ -123,6 +123,7 @@ def __init__(self): |
| 123 | 123 |
|
| 124 | 124 |
self._check_for_account()
|
| 125 | 125 |
self._load_chats()
|
| 126 |
+ self._load_unread_counts()
|
|
| 126 | 127 |
self._add_actions()
|
| 127 | 128 |
self._add_actions2()
|
| 128 | 129 |
|
| ... | ... | @@ -332,6 +333,16 @@ def _set_startup_finished(self): |
| 332 | 333 |
self._startup_finished = True
|
| 333 | 334 |
self._chat_page.set_startup_finished()
|
| 334 | 335 |
|
| 336 |
+ def _load_unread_counts(self) -> None:
|
|
| 337 |
+ chats = app.storage.cache.get_unread()
|
|
| 338 |
+ chat_list_stack = self._chat_page.get_chat_list_stack()
|
|
| 339 |
+ |
|
| 340 |
+ for chat in chats:
|
|
| 341 |
+ chat_list_stack.set_chat_unread_count(
|
|
| 342 |
+ chat.account,
|
|
| 343 |
+ chat.jid,
|
|
| 344 |
+ chat.count)
|
|
| 345 |
+ |
|
| 335 | 346 |
def show_account_page(self, account: str) -> None:
|
| 336 | 347 |
self._app_side_bar.unselect_all()
|
| 337 | 348 |
self._workspace_side_bar.unselect_all()
|