Add account total unread/mentions indicator

This commit is contained in:
miruka 2020-05-01 04:46:08 -04:00
parent 9ebd8644c8
commit 9f7d30f248
6 changed files with 26 additions and 7 deletions

View File

@ -1,9 +1,9 @@
# TODO
- add unread counts on accounts
- add account number binds
- rename goto*account → scrollto*account
- fix python error
- fix back/front buttons in small window
- fix message delegate too tall
- fix left rooms opacity

View File

@ -249,15 +249,19 @@ class Backend:
only cleaning up any unread indicators.
"""
for client in self.clients.values():
for user_id, client in self.clients.items():
client.open_room = room_id
if not client.first_sync_done.is_set():
continue
room = self.models[client.user_id, "rooms"].get(room_id)
room = self.models[user_id, "rooms"].get(room_id)
if room:
account = self.models["accounts"][user_id]
account.total_unread -= room.unreads
account.total_mentions -= room.mentions
room.mentions = 0
room.unreads = 0

View File

@ -1374,10 +1374,14 @@ class MatrixClient(nio.AsyncClient):
AlertRequested()
if self.open_room != room.room_id:
room = self.models[self.user_id, "rooms"][room.room_id]
room.unreads += 1
account = self.models["accounts"][self.user_id]
room = self.models[self.user_id, "rooms"][room.room_id]
account.total_unread += 1
room.unreads += 1
content = fields.get("content", "")
if HTML.user_id_link_in_html(content, self.user_id):
room.mentions += 1
account.total_mentions += 1
room.mentions += 1

View File

@ -38,6 +38,8 @@ class Account(ModelItem):
max_upload_size: int = 0
profile_updated: datetime = ZeroDate
first_sync_done: bool = False
total_unread: int = 0
total_mentions: int = 0
def __lt__(self, other: "Account") -> bool:
"""Sort by user ID."""

View File

@ -79,6 +79,16 @@ HColumnLayout {
radius: theme.accountsBar.accountList.account.avatarRadius
}
MessageIndicator {
anchors.right: parent.right
anchors.bottom: parent.bottom
indicatorTheme:
theme.accountView.roomList.room.unreadIndicator
unreads: model.total_unread
mentions: model.total_mentions
}
}
onLeftClicked: roomList.goToAccount(model.id)

View File

@ -30,6 +30,5 @@ HLabel {
property int mentions: 0
Behavior on scale { HNumberAnimation {} }
}