Re-add local unread "counter" similar to 0.5.0
This commit is contained in:
@@ -285,9 +285,10 @@ class Backend:
|
||||
async def update(client: MatrixClient) -> None:
|
||||
room = self.models[client.user_id, "rooms"].get(room_id)
|
||||
|
||||
if room and room.unreads + room.highlights:
|
||||
room.unreads = 0
|
||||
room.highlights = 0
|
||||
if room and room.unreads or room.highlights or room.local_unreads:
|
||||
room.unreads = 0
|
||||
room.highlights = 0
|
||||
room.local_unreads = False
|
||||
await client.update_account_unread_counts()
|
||||
await client.update_receipt_marker(room_id, event_id)
|
||||
|
||||
|
@@ -1342,15 +1342,21 @@ class MatrixClient(nio.AsyncClient):
|
||||
async def update_account_unread_counts(self) -> None:
|
||||
"""Recalculate total unread notifications/highlights for our account"""
|
||||
|
||||
unreads = highlights = 0
|
||||
local_unreads = False
|
||||
unreads = 0
|
||||
highlights = 0
|
||||
|
||||
for room in self.models[self.user_id, "rooms"].values():
|
||||
unreads += room.unreads
|
||||
highlights += room.highlights
|
||||
|
||||
if room.local_unreads:
|
||||
local_unreads = True
|
||||
|
||||
account = self.models["accounts"][self.user_id]
|
||||
account.total_unread = unreads
|
||||
account.total_highlights = highlights
|
||||
account.local_unreads = local_unreads
|
||||
|
||||
|
||||
async def event_is_past(self, ev: Union[nio.Event, Event]) -> bool:
|
||||
@@ -1398,10 +1404,12 @@ class MatrixClient(nio.AsyncClient):
|
||||
registered = None
|
||||
last_event_date = datetime.fromtimestamp(0)
|
||||
typing_members = []
|
||||
local_unreads = False
|
||||
update_account_unread_counts = True
|
||||
else:
|
||||
last_event_date = registered.last_event_date
|
||||
typing_members = registered.typing_members
|
||||
local_unreads = registered.local_unreads
|
||||
update_account_unread_counts = (
|
||||
registered.unreads != room.unread_notifications or
|
||||
registered.highlights != room.unread_highlights
|
||||
@@ -1444,8 +1452,9 @@ class MatrixClient(nio.AsyncClient):
|
||||
|
||||
last_event_date = last_event_date,
|
||||
|
||||
unreads = room.unread_notifications,
|
||||
highlights = room.unread_highlights,
|
||||
unreads = room.unread_notifications,
|
||||
highlights = room.unread_highlights,
|
||||
local_unreads = local_unreads,
|
||||
)
|
||||
|
||||
self.models[self.user_id, "rooms"][room.room_id] = room_item
|
||||
@@ -1619,3 +1628,8 @@ class MatrixClient(nio.AsyncClient):
|
||||
|
||||
mentions_us = HTML.user_id_link_in_html(item.content, self.user_id)
|
||||
AlertRequested(high_importance=mentions_us)
|
||||
|
||||
room_item = self.models[self.user_id, "rooms"][room.room_id]
|
||||
room_item.local_unreads = True
|
||||
|
||||
await self.update_account_unread_counts()
|
||||
|
@@ -41,6 +41,7 @@ class Account(ModelItem):
|
||||
first_sync_done: bool = False
|
||||
total_unread: int = 0
|
||||
total_highlights: int = 0
|
||||
local_unreads: bool = False
|
||||
|
||||
def __lt__(self, other: "Account") -> bool:
|
||||
"""Sort by order, then by user ID."""
|
||||
@@ -84,17 +85,18 @@ class Room(ModelItem):
|
||||
|
||||
last_event_date: datetime = ZeroDate
|
||||
|
||||
unreads: int = 0
|
||||
highlights: int = 0
|
||||
unreads: int = 0
|
||||
highlights: int = 0
|
||||
local_unreads: bool = False
|
||||
|
||||
def __lt__(self, other: "Room") -> bool:
|
||||
"""Sort by membership, highlights/unread events, last event date, name.
|
||||
|
||||
Invited rooms are first, then joined rooms, then left rooms.
|
||||
Within these categories, sort by last event date (room with recent
|
||||
messages are first), then by display names, then account, but
|
||||
keep rooms with highlights on top,
|
||||
followed by rooms with unread events.
|
||||
Within these categories, sort by unread highlighted messages, then
|
||||
unread messages, then by whether the room hasn't been read locally,
|
||||
then last event date (room with recent messages are first),
|
||||
then by display names or ID.
|
||||
"""
|
||||
|
||||
# Left rooms may still have an inviter_id, so check left first.
|
||||
@@ -104,6 +106,7 @@ class Room(ModelItem):
|
||||
other.inviter_id,
|
||||
bool(other.highlights),
|
||||
bool(other.unreads),
|
||||
bool(other.local_unreads),
|
||||
other.last_event_date,
|
||||
(self.display_name or self.id).lower(),
|
||||
|
||||
@@ -113,6 +116,7 @@ class Room(ModelItem):
|
||||
self.inviter_id,
|
||||
bool(self.highlights),
|
||||
bool(self.unreads),
|
||||
bool(self.local_unreads),
|
||||
self.last_event_date,
|
||||
(other.display_name or other.id).lower(),
|
||||
)
|
||||
@@ -132,6 +136,7 @@ class AccountOrRoom(Account, Room):
|
||||
other.inviter_id,
|
||||
bool(other.highlights),
|
||||
bool(other.unreads),
|
||||
bool(other.local_unreads),
|
||||
other.last_event_date,
|
||||
(self.display_name or self.id).lower(),
|
||||
|
||||
@@ -143,6 +148,7 @@ class AccountOrRoom(Account, Room):
|
||||
self.inviter_id,
|
||||
bool(self.highlights),
|
||||
bool(self.unreads),
|
||||
bool(self.local_unreads),
|
||||
self.last_event_date,
|
||||
(other.display_name or other.id).lower(),
|
||||
)
|
||||
|
Reference in New Issue
Block a user