Cross-client unread counters & send read receipts
This commit is contained in:
parent
d2300bf663
commit
f686b96511
|
@ -262,28 +262,20 @@ class Backend:
|
||||||
return await client.download(server_name, media_id)
|
return await client.download(server_name, media_id)
|
||||||
|
|
||||||
|
|
||||||
async def room_read(self, room_id: str) -> None:
|
async def update_room_read_marker(
|
||||||
"""Mark all messages in a room as read for all accounts part of it
|
self, room_id: str, event_id: str,
|
||||||
|
) -> None:
|
||||||
Currently, this doesn't handle sending a read receipt to the server,
|
"""Update room's read marker to an event for all accounts part of it.
|
||||||
only cleaning up any unread indicators.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for user_id, client in self.clients.items():
|
async def update(client: MatrixClient) -> None:
|
||||||
client.open_room = room_id
|
room = self.models[client.user_id, "rooms"].get(room_id)
|
||||||
|
|
||||||
if not client.first_sync_done.is_set():
|
if room and room.unreads + room.highlights:
|
||||||
continue
|
await client.update_receipt_marker(room_id, event_id)
|
||||||
|
await client.update_account_unread_counts()
|
||||||
|
|
||||||
room = self.models[user_id, "rooms"].get(room_id)
|
await asyncio.gather(*[update(c) for c in self.clients.values()])
|
||||||
|
|
||||||
if room:
|
|
||||||
account = self.models["accounts"][user_id]
|
|
||||||
account.total_unread -= room.unreads
|
|
||||||
account.total_highlights -= room.highlights
|
|
||||||
|
|
||||||
room.highlights = 0
|
|
||||||
room.unreads = 0
|
|
||||||
|
|
||||||
|
|
||||||
# General functions
|
# General functions
|
||||||
|
|
|
@ -170,9 +170,8 @@ 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: Optional[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
|
||||||
|
@ -1213,6 +1212,8 @@ class MatrixClient(nio.AsyncClient):
|
||||||
ZeroDate
|
ZeroDate
|
||||||
|
|
||||||
|
|
||||||
|
# Functions to register/modify data into models
|
||||||
|
|
||||||
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"""
|
||||||
|
|
||||||
|
@ -1227,8 +1228,6 @@ class MatrixClient(nio.AsyncClient):
|
||||||
account.total_highlights = highlights
|
account.total_highlights = highlights
|
||||||
|
|
||||||
|
|
||||||
# Functions to register data into models
|
|
||||||
|
|
||||||
async def event_is_past(self, ev: Union[nio.Event, Event]) -> bool:
|
async def event_is_past(self, ev: Union[nio.Event, Event]) -> bool:
|
||||||
"""Return whether an event was created before this client started."""
|
"""Return whether an event was created before this client started."""
|
||||||
|
|
||||||
|
|
|
@ -70,13 +70,11 @@ class NioCallbacks:
|
||||||
# Response callbacks
|
# Response callbacks
|
||||||
|
|
||||||
async def onSyncResponse(self, resp: nio.SyncResponse) -> None:
|
async def onSyncResponse(self, resp: nio.SyncResponse) -> None:
|
||||||
room_model = self.models[self.user_id, "rooms"]
|
for room_id in resp.rooms.invite:
|
||||||
|
await self.client.register_nio_room(self.client.all_rooms[room_id])
|
||||||
|
|
||||||
for room_id, info in resp.rooms.join.items():
|
for room_id, info in resp.rooms.join.items():
|
||||||
if room_id not in room_model:
|
await self.client.register_nio_room(self.client.rooms[room_id])
|
||||||
# Just in case we don't get any events for that room that
|
|
||||||
# triggers other callbacks
|
|
||||||
await self.client.register_nio_room(self.client.rooms[room_id])
|
|
||||||
|
|
||||||
if room_id not in self.client.past_tokens:
|
if room_id not in self.client.past_tokens:
|
||||||
self.client.past_tokens[room_id] = info.timeline.prev_batch
|
self.client.past_tokens[room_id] = info.timeline.prev_batch
|
||||||
|
|
|
@ -50,9 +50,6 @@ HLoader {
|
||||||
if (history.length > historyLength) history.pop()
|
if (history.length > historyLength) history.pop()
|
||||||
|
|
||||||
pageLoader.setSource(componentUrl, properties)
|
pageLoader.setSource(componentUrl, properties)
|
||||||
|
|
||||||
if (componentUrl === "Pages/Chat/Chat.qml" && properties.roomId)
|
|
||||||
py.callCoro("room_read", [properties.roomId])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showPage(name, properties={}) {
|
function showPage(name, properties={}) {
|
||||||
|
|
|
@ -352,6 +352,20 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 1000
|
||||||
|
|
||||||
|
running:
|
||||||
|
(chat.roomInfo.unreads || chat.roomInfo.highlights) &&
|
||||||
|
Qt.application.state === Qt.ApplicationActive &&
|
||||||
|
(eventList.contentY + eventList.height) > -50
|
||||||
|
|
||||||
|
onTriggered: {
|
||||||
|
const eventId = eventList.model.get(0).id
|
||||||
|
py.callCoro("update_room_read_marker", [chat.roomId, eventId])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HNoticePage {
|
HNoticePage {
|
||||||
text: qsTr("No messages to show yet")
|
text: qsTr("No messages to show yet")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user