Added limited local read/unread tracking
This commit is contained in:
parent
b2cfc27ce2
commit
6ee20a2717
|
@ -116,6 +116,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
self.backend: "Backend" = backend
|
self.backend: "Backend" = backend
|
||||||
self.models: ModelStore = self.backend.models
|
self.models: ModelStore = self.backend.models
|
||||||
|
self.open_room: str = None
|
||||||
|
|
||||||
self.profile_task: Optional[asyncio.Future] = None
|
self.profile_task: Optional[asyncio.Future] = None
|
||||||
self.server_config_task: Optional[asyncio.Future] = None
|
self.server_config_task: Optional[asyncio.Future] = None
|
||||||
|
@ -831,6 +832,18 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
await super().room_forget(room_id)
|
await super().room_forget(room_id)
|
||||||
|
|
||||||
|
async def room_read(self, room_id: str) -> None:
|
||||||
|
"""Mark all messages in a room as read
|
||||||
|
|
||||||
|
Currently, this doesn't handle sending a read receipt to the server,
|
||||||
|
only cleaning up any unread indicators.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.open_room = room_id
|
||||||
|
if self.first_sync_done.is_set():
|
||||||
|
room = self.models[self.user_id, "rooms"][room_id]
|
||||||
|
room.mentions = 0
|
||||||
|
room.unreads = 0
|
||||||
|
|
||||||
async def room_mass_invite(
|
async def room_mass_invite(
|
||||||
self, room_id: str, *user_ids: str,
|
self, room_id: str, *user_ids: str,
|
||||||
|
@ -1153,10 +1166,12 @@ class MatrixClient(nio.AsyncClient):
|
||||||
last_event_date = registered.last_event_date
|
last_event_date = registered.last_event_date
|
||||||
typing_members = registered.typing_members
|
typing_members = registered.typing_members
|
||||||
mentions = registered.mentions
|
mentions = registered.mentions
|
||||||
|
unreads = registered.unreads
|
||||||
except KeyError:
|
except KeyError:
|
||||||
last_event_date = datetime.fromtimestamp(0)
|
last_event_date = datetime.fromtimestamp(0)
|
||||||
typing_members = []
|
typing_members = []
|
||||||
mentions = 0
|
mentions = 0
|
||||||
|
unreads = 0
|
||||||
|
|
||||||
self.models[self.user_id, "rooms"][room.room_id] = Room(
|
self.models[self.user_id, "rooms"][room.room_id] = Room(
|
||||||
id = room.room_id,
|
id = room.room_id,
|
||||||
|
@ -1191,6 +1206,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
last_event_date = last_event_date,
|
last_event_date = last_event_date,
|
||||||
mentions = mentions,
|
mentions = mentions,
|
||||||
|
unreads = unreads,
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,7 @@ class Room(ModelItem):
|
||||||
last_event_date: datetime = ZeroDate
|
last_event_date: datetime = ZeroDate
|
||||||
|
|
||||||
mentions: int = 0
|
mentions: int = 0
|
||||||
|
unreads: int = 0
|
||||||
|
|
||||||
def __lt__(self, other: "Room") -> bool:
|
def __lt__(self, other: "Room") -> bool:
|
||||||
"""Sort by join state, then descending last event date, then name.
|
"""Sort by join state, then descending last event date, then name.
|
||||||
|
|
|
@ -36,7 +36,6 @@ class NioCallbacks:
|
||||||
|
|
||||||
client: "MatrixClient" = field()
|
client: "MatrixClient" = field()
|
||||||
|
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Register our methods as callbacks."""
|
"""Register our methods as callbacks."""
|
||||||
|
|
||||||
|
@ -109,9 +108,11 @@ class NioCallbacks:
|
||||||
room, ev, content=co, mentions=mention_list,
|
room, ev, content=co, mentions=mention_list,
|
||||||
)
|
)
|
||||||
|
|
||||||
if HTML_PROCESSOR.user_id_link_in_html(co, self.client.user_id):
|
if self.client.first_sync_done.is_set() and self.client.open_room != room.room_id:
|
||||||
rooms = self.client.models[self.client.user_id, "rooms"]
|
room = self.client.models[self.client.user_id, "rooms"][room.room_id]
|
||||||
rooms[room.room_id].mentions += 1
|
room.unreads += 1
|
||||||
|
if HTML_PROCESSOR.user_id_link_in_html(co, self.client.user_id):
|
||||||
|
room.mentions += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,23 +44,23 @@ HTileDelegate {
|
||||||
color: theme.mainPane.listView.room.name
|
color: theme.mainPane.listView.room.name
|
||||||
}
|
}
|
||||||
|
|
||||||
// HLabel {
|
HLabel {
|
||||||
// text: model.mentions
|
text: model.unreads
|
||||||
// font.pixelSize: theme.fontSize.small
|
font.pixelSize: theme.fontSize.small
|
||||||
// verticalAlignment: Qt.AlignVCenter
|
verticalAlignment: Qt.AlignVCenter
|
||||||
// leftPadding: theme.spacing / 4
|
leftPadding: theme.spacing / 4
|
||||||
// rightPadding: leftPadding
|
rightPadding: leftPadding
|
||||||
|
|
||||||
// scale: model.mentions === 0 ? 0 : 1
|
scale: model.unreads === 0 ? 0 : 1
|
||||||
// visible: scale > 0
|
visible: scale > 0
|
||||||
|
|
||||||
// background: Rectangle {
|
background: Rectangle {
|
||||||
// color: theme.colors.alertBackground
|
color: model.mentions === 0 ? theme.colors.unreadBackground : theme.colors.alertBackground
|
||||||
// radius: theme.radius / 4
|
radius: theme.radius / 4
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Behavior on scale { HNumberAnimation {} }
|
Behavior on scale { HNumberAnimation {} }
|
||||||
// },
|
}
|
||||||
|
|
||||||
HIcon {
|
HIcon {
|
||||||
svgName: "invite-received"
|
svgName: "invite-received"
|
||||||
|
|
|
@ -61,6 +61,8 @@ HLoader {
|
||||||
function showRoom(userId, roomId) {
|
function showRoom(userId, roomId) {
|
||||||
_show("Pages/Chat/Chat.qml", {userId, roomId})
|
_show("Pages/Chat/Chat.qml", {userId, roomId})
|
||||||
|
|
||||||
|
py.callClientCoro(userId, "room_read", [roomId], () => {})
|
||||||
|
|
||||||
window.uiState.page = "Pages/Chat/Chat.qml"
|
window.uiState.page = "Pages/Chat/Chat.qml"
|
||||||
window.uiState.pageProperties = {userId, roomId}
|
window.uiState.pageProperties = {userId, roomId}
|
||||||
window.uiStateChanged()
|
window.uiStateChanged()
|
||||||
|
|
|
@ -59,6 +59,9 @@ colors:
|
||||||
color negativeBackground:
|
color negativeBackground:
|
||||||
hsluv(0, saturation * 1.5, intensity * 52, opacity)
|
hsluv(0, saturation * 1.5, intensity * 52, opacity)
|
||||||
|
|
||||||
|
color unreadBackground:
|
||||||
|
hsluv(188, saturation * 1.5, intensity * 52, 1)
|
||||||
|
|
||||||
color alertBackground: negativeBackground
|
color alertBackground: negativeBackground
|
||||||
|
|
||||||
color brightText: hsluv(0, 0, intensity * 100)
|
color brightText: hsluv(0, 0, intensity * 100)
|
||||||
|
|
|
@ -62,6 +62,9 @@ colors:
|
||||||
color negativeBackground:
|
color negativeBackground:
|
||||||
hsluv(0, saturation * 1.5, intensity * 52, opacity)
|
hsluv(0, saturation * 1.5, intensity * 52, opacity)
|
||||||
|
|
||||||
|
color unreadBackground:
|
||||||
|
hsluv(188, saturation * 1.5, intensity * 52, 1)
|
||||||
|
|
||||||
color alertBackground: negativeBackground
|
color alertBackground: negativeBackground
|
||||||
|
|
||||||
color brightText: hsluv(0, 0, intensity * 100)
|
color brightText: hsluv(0, 0, intensity * 100)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user