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)