From 7b5aa8ffe180d4f1a221ccdbee11c592c75509a3 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 31 May 2020 00:38:48 -0400 Subject: [PATCH] Store room member read markers in model --- src/backend/models/items.py | 2 ++ src/backend/nio_callbacks.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/backend/models/items.py b/src/backend/models/items.py index 665454dd..f3d310c3 100644 --- a/src/backend/models/items.py +++ b/src/backend/models/items.py @@ -158,6 +158,8 @@ class Member(ModelItem): power_level: int = 0 invited: bool = False profile_updated: datetime = ZeroDate + last_read_event: str = "" + last_read_at: datetime = ZeroDate def __lt__(self, other: "Member") -> bool: """Sort by power level, then by display name/user ID.""" diff --git a/src/backend/nio_callbacks.py b/src/backend/nio_callbacks.py index 9507611a..3b68a0fd 100644 --- a/src/backend/nio_callbacks.py +++ b/src/backend/nio_callbacks.py @@ -537,3 +537,20 @@ class NioCallbacks: room.user_name(user_id) or user_id for user_id in ev.users if user_id not in self.client.backend.clients ) + + + async def onReceiptEvent( + self, room: nio.MatrixRoom, ev: nio.ReceiptEvent, + ) -> None: + model = self.models[self.user_id, room.room_id, "members"] + + for receipt in ev.receipts: + if receipt.receipt_type != "m.read": + continue + + member = model.get(receipt.user_id) + + if member: + member.last_read_event = receipt.event_id + timestamp = receipt.timestamp / 1000 + member.last_read_at = datetime.fromtimestamp(timestamp)