Re-add local unread "counter" similar to 0.5.0
This commit is contained in:
parent
213867750d
commit
aa8dbce3a7
@ -285,9 +285,10 @@ class Backend:
|
|||||||
async def update(client: MatrixClient) -> None:
|
async def update(client: MatrixClient) -> None:
|
||||||
room = self.models[client.user_id, "rooms"].get(room_id)
|
room = self.models[client.user_id, "rooms"].get(room_id)
|
||||||
|
|
||||||
if room and room.unreads + room.highlights:
|
if room and room.unreads or room.highlights or room.local_unreads:
|
||||||
room.unreads = 0
|
room.unreads = 0
|
||||||
room.highlights = 0
|
room.highlights = 0
|
||||||
|
room.local_unreads = False
|
||||||
await client.update_account_unread_counts()
|
await client.update_account_unread_counts()
|
||||||
await client.update_receipt_marker(room_id, event_id)
|
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:
|
async def update_account_unread_counts(self) -> None:
|
||||||
"""Recalculate total unread notifications/highlights for our account"""
|
"""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():
|
for room in self.models[self.user_id, "rooms"].values():
|
||||||
unreads += room.unreads
|
unreads += room.unreads
|
||||||
highlights += room.highlights
|
highlights += room.highlights
|
||||||
|
|
||||||
|
if room.local_unreads:
|
||||||
|
local_unreads = True
|
||||||
|
|
||||||
account = self.models["accounts"][self.user_id]
|
account = self.models["accounts"][self.user_id]
|
||||||
account.total_unread = unreads
|
account.total_unread = unreads
|
||||||
account.total_highlights = highlights
|
account.total_highlights = highlights
|
||||||
|
account.local_unreads = local_unreads
|
||||||
|
|
||||||
|
|
||||||
async def event_is_past(self, ev: Union[nio.Event, Event]) -> bool:
|
async def event_is_past(self, ev: Union[nio.Event, Event]) -> bool:
|
||||||
@ -1398,10 +1404,12 @@ class MatrixClient(nio.AsyncClient):
|
|||||||
registered = None
|
registered = None
|
||||||
last_event_date = datetime.fromtimestamp(0)
|
last_event_date = datetime.fromtimestamp(0)
|
||||||
typing_members = []
|
typing_members = []
|
||||||
|
local_unreads = False
|
||||||
update_account_unread_counts = True
|
update_account_unread_counts = True
|
||||||
else:
|
else:
|
||||||
last_event_date = registered.last_event_date
|
last_event_date = registered.last_event_date
|
||||||
typing_members = registered.typing_members
|
typing_members = registered.typing_members
|
||||||
|
local_unreads = registered.local_unreads
|
||||||
update_account_unread_counts = (
|
update_account_unread_counts = (
|
||||||
registered.unreads != room.unread_notifications or
|
registered.unreads != room.unread_notifications or
|
||||||
registered.highlights != room.unread_highlights
|
registered.highlights != room.unread_highlights
|
||||||
@ -1444,8 +1452,9 @@ class MatrixClient(nio.AsyncClient):
|
|||||||
|
|
||||||
last_event_date = last_event_date,
|
last_event_date = last_event_date,
|
||||||
|
|
||||||
unreads = room.unread_notifications,
|
unreads = room.unread_notifications,
|
||||||
highlights = room.unread_highlights,
|
highlights = room.unread_highlights,
|
||||||
|
local_unreads = local_unreads,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.models[self.user_id, "rooms"][room.room_id] = room_item
|
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)
|
mentions_us = HTML.user_id_link_in_html(item.content, self.user_id)
|
||||||
AlertRequested(high_importance=mentions_us)
|
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
|
first_sync_done: bool = False
|
||||||
total_unread: int = 0
|
total_unread: int = 0
|
||||||
total_highlights: int = 0
|
total_highlights: int = 0
|
||||||
|
local_unreads: bool = False
|
||||||
|
|
||||||
def __lt__(self, other: "Account") -> bool:
|
def __lt__(self, other: "Account") -> bool:
|
||||||
"""Sort by order, then by user ID."""
|
"""Sort by order, then by user ID."""
|
||||||
@ -84,17 +85,18 @@ class Room(ModelItem):
|
|||||||
|
|
||||||
last_event_date: datetime = ZeroDate
|
last_event_date: datetime = ZeroDate
|
||||||
|
|
||||||
unreads: int = 0
|
unreads: int = 0
|
||||||
highlights: int = 0
|
highlights: int = 0
|
||||||
|
local_unreads: bool = False
|
||||||
|
|
||||||
def __lt__(self, other: "Room") -> bool:
|
def __lt__(self, other: "Room") -> bool:
|
||||||
"""Sort by membership, highlights/unread events, last event date, name.
|
"""Sort by membership, highlights/unread events, last event date, name.
|
||||||
|
|
||||||
Invited rooms are first, then joined rooms, then left rooms.
|
Invited rooms are first, then joined rooms, then left rooms.
|
||||||
Within these categories, sort by last event date (room with recent
|
Within these categories, sort by unread highlighted messages, then
|
||||||
messages are first), then by display names, then account, but
|
unread messages, then by whether the room hasn't been read locally,
|
||||||
keep rooms with highlights on top,
|
then last event date (room with recent messages are first),
|
||||||
followed by rooms with unread events.
|
then by display names or ID.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Left rooms may still have an inviter_id, so check left first.
|
# Left rooms may still have an inviter_id, so check left first.
|
||||||
@ -104,6 +106,7 @@ class Room(ModelItem):
|
|||||||
other.inviter_id,
|
other.inviter_id,
|
||||||
bool(other.highlights),
|
bool(other.highlights),
|
||||||
bool(other.unreads),
|
bool(other.unreads),
|
||||||
|
bool(other.local_unreads),
|
||||||
other.last_event_date,
|
other.last_event_date,
|
||||||
(self.display_name or self.id).lower(),
|
(self.display_name or self.id).lower(),
|
||||||
|
|
||||||
@ -113,6 +116,7 @@ class Room(ModelItem):
|
|||||||
self.inviter_id,
|
self.inviter_id,
|
||||||
bool(self.highlights),
|
bool(self.highlights),
|
||||||
bool(self.unreads),
|
bool(self.unreads),
|
||||||
|
bool(self.local_unreads),
|
||||||
self.last_event_date,
|
self.last_event_date,
|
||||||
(other.display_name or other.id).lower(),
|
(other.display_name or other.id).lower(),
|
||||||
)
|
)
|
||||||
@ -132,6 +136,7 @@ class AccountOrRoom(Account, Room):
|
|||||||
other.inviter_id,
|
other.inviter_id,
|
||||||
bool(other.highlights),
|
bool(other.highlights),
|
||||||
bool(other.unreads),
|
bool(other.unreads),
|
||||||
|
bool(other.local_unreads),
|
||||||
other.last_event_date,
|
other.last_event_date,
|
||||||
(self.display_name or self.id).lower(),
|
(self.display_name or self.id).lower(),
|
||||||
|
|
||||||
@ -143,6 +148,7 @@ class AccountOrRoom(Account, Room):
|
|||||||
self.inviter_id,
|
self.inviter_id,
|
||||||
bool(self.highlights),
|
bool(self.highlights),
|
||||||
bool(self.unreads),
|
bool(self.unreads),
|
||||||
|
bool(self.local_unreads),
|
||||||
self.last_event_date,
|
self.last_event_date,
|
||||||
(other.display_name or other.id).lower(),
|
(other.display_name or other.id).lower(),
|
||||||
)
|
)
|
||||||
|
@ -57,6 +57,7 @@ HTile {
|
|||||||
theme.mainPane.accountBar.account.unreadIndicator
|
theme.mainPane.accountBar.account.unreadIndicator
|
||||||
unreads: model.total_unread
|
unreads: model.total_unread
|
||||||
highlights: model.total_highlights
|
highlights: model.total_highlights
|
||||||
|
localUnreads: model.local_unreads
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,15 +7,18 @@ HLabel {
|
|||||||
text:
|
text:
|
||||||
unreads >= 1000000 ? Math.floor(unreads / 1000000) + "M" :
|
unreads >= 1000000 ? Math.floor(unreads / 1000000) + "M" :
|
||||||
unreads >= 1000 ? Math.floor(unreads / 1000) + "K" :
|
unreads >= 1000 ? Math.floor(unreads / 1000) + "K" :
|
||||||
unreads
|
unreads ? unreads :
|
||||||
|
localUnreads ? "!" :
|
||||||
|
""
|
||||||
|
|
||||||
font.pixelSize: theme.fontSize.small
|
font.pixelSize: theme.fontSize.small
|
||||||
|
font.bold: text === "!"
|
||||||
verticalAlignment: Qt.AlignVCenter
|
verticalAlignment: Qt.AlignVCenter
|
||||||
leftPadding: theme.spacing / 4
|
leftPadding: theme.spacing / 4
|
||||||
rightPadding: leftPadding
|
rightPadding: leftPadding
|
||||||
|
|
||||||
scale: unreads === 0 ? 0 : 1
|
scale: text ? 1 : 0
|
||||||
visible: unreads !== 0
|
visible: text !== ""
|
||||||
|
|
||||||
background: Rectangle {
|
background: Rectangle {
|
||||||
color:
|
color:
|
||||||
@ -32,6 +35,7 @@ HLabel {
|
|||||||
property QtObject indicatorTheme
|
property QtObject indicatorTheme
|
||||||
property int unreads: 0
|
property int unreads: 0
|
||||||
property int highlights: 0
|
property int highlights: 0
|
||||||
|
property bool localUnreads: false
|
||||||
|
|
||||||
|
|
||||||
Behavior on scale { HNumberAnimation {} }
|
Behavior on scale { HNumberAnimation {} }
|
||||||
|
@ -36,7 +36,10 @@ HTile {
|
|||||||
|
|
||||||
TitleLabel {
|
TitleLabel {
|
||||||
text: model.display_name || qsTr("Empty room")
|
text: model.display_name || qsTr("Empty room")
|
||||||
color: theme.mainPane.listView.room.name
|
color:
|
||||||
|
model.local_unreads ?
|
||||||
|
theme.mainPane.listView.room.unreadName :
|
||||||
|
theme.mainPane.listView.room.name
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageIndicator {
|
MessageIndicator {
|
||||||
@ -44,6 +47,7 @@ HTile {
|
|||||||
theme.mainPane.listView.room.unreadIndicator
|
theme.mainPane.listView.room.unreadIndicator
|
||||||
unreads: model.unreads
|
unreads: model.unreads
|
||||||
highlights: model.highlights
|
highlights: model.highlights
|
||||||
|
localUnreads: model.local_unreads
|
||||||
}
|
}
|
||||||
|
|
||||||
HIcon {
|
HIcon {
|
||||||
|
@ -358,7 +358,11 @@ Rectangle {
|
|||||||
|
|
||||||
running:
|
running:
|
||||||
! eventList.updateMarkerFuture &&
|
! eventList.updateMarkerFuture &&
|
||||||
(chat.roomInfo.unreads || chat.roomInfo.highlights) &&
|
(
|
||||||
|
chat.roomInfo.unreads ||
|
||||||
|
chat.roomInfo.highlights ||
|
||||||
|
chat.roomInfo.local_unreads
|
||||||
|
) &&
|
||||||
Qt.application.state === Qt.ApplicationActive &&
|
Qt.application.state === Qt.ApplicationActive &&
|
||||||
(eventList.contentY + eventList.height) > -50
|
(eventList.contentY + eventList.height) > -50
|
||||||
|
|
||||||
|
@ -324,6 +324,7 @@ mainPane:
|
|||||||
|
|
||||||
color background: "transparent"
|
color background: "transparent"
|
||||||
color name: colors.text
|
color name: colors.text
|
||||||
|
color unreadName: colors.brightText
|
||||||
color lastEventDate: colors.halfDimText
|
color lastEventDate: colors.halfDimText
|
||||||
|
|
||||||
color subtitle: colors.dimText
|
color subtitle: colors.dimText
|
||||||
|
@ -333,6 +333,7 @@ mainPane:
|
|||||||
|
|
||||||
color background: "transparent"
|
color background: "transparent"
|
||||||
color name: colors.text
|
color name: colors.text
|
||||||
|
color unreadName: colors.brightText
|
||||||
color lastEventDate: colors.halfDimText
|
color lastEventDate: colors.halfDimText
|
||||||
|
|
||||||
color subtitle: colors.dimText
|
color subtitle: colors.dimText
|
||||||
|
Loading…
x
Reference in New Issue
Block a user