Cross-client unread counters & send read receipts

This commit is contained in:
miruka 2020-06-01 09:25:09 -04:00
parent d2300bf663
commit f686b96511
5 changed files with 31 additions and 31 deletions

View File

@ -262,28 +262,20 @@ class Backend:
return await client.download(server_name, media_id)
async def room_read(self, room_id: str) -> None:
"""Mark all messages in a room as read for all accounts part of it
Currently, this doesn't handle sending a read receipt to the server,
only cleaning up any unread indicators.
async def update_room_read_marker(
self, room_id: str, event_id: str,
) -> None:
"""Update room's read marker to an event for all accounts part of it.
"""
for user_id, client in self.clients.items():
client.open_room = room_id
async def update(client: MatrixClient) -> None:
room = self.models[client.user_id, "rooms"].get(room_id)
if not client.first_sync_done.is_set():
continue
if room and room.unreads + room.highlights:
await client.update_receipt_marker(room_id, event_id)
await client.update_account_unread_counts()
room = self.models[user_id, "rooms"].get(room_id)
if room:
account = self.models["accounts"][user_id]
account.total_unread -= room.unreads
account.total_highlights -= room.highlights
room.highlights = 0
room.unreads = 0
await asyncio.gather(*[update(c) for c in self.clients.values()])
# General functions

View File

@ -170,9 +170,8 @@ class MatrixClient(nio.AsyncClient):
),
)
self.backend: "Backend" = backend
self.models: ModelStore = self.backend.models
self.open_room: Optional[str] = None
self.backend: "Backend" = backend
self.models: ModelStore = self.backend.models
self.profile_task: Optional[asyncio.Future] = None
self.server_config_task: Optional[asyncio.Future] = None
@ -1213,6 +1212,8 @@ class MatrixClient(nio.AsyncClient):
ZeroDate
# Functions to register/modify data into models
async def update_account_unread_counts(self) -> None:
"""Recalculate total unread notifications/highlights for our account"""
@ -1227,8 +1228,6 @@ class MatrixClient(nio.AsyncClient):
account.total_highlights = highlights
# Functions to register data into models
async def event_is_past(self, ev: Union[nio.Event, Event]) -> bool:
"""Return whether an event was created before this client started."""

View File

@ -70,13 +70,11 @@ class NioCallbacks:
# Response callbacks
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():
if room_id not in room_model:
# 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])
await self.client.register_nio_room(self.client.rooms[room_id])
if room_id not in self.client.past_tokens:
self.client.past_tokens[room_id] = info.timeline.prev_batch

View File

@ -50,9 +50,6 @@ HLoader {
if (history.length > historyLength) history.pop()
pageLoader.setSource(componentUrl, properties)
if (componentUrl === "Pages/Chat/Chat.qml" && properties.roomId)
py.callCoro("room_read", [properties.roomId])
}
function showPage(name, properties={}) {

View File

@ -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 {
text: qsTr("No messages to show yet")