Store room member read markers in model

This commit is contained in:
miruka 2020-05-31 00:38:48 -04:00
parent 160ce2643e
commit 7b5aa8ffe1
2 changed files with 19 additions and 0 deletions

View File

@ -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."""

View File

@ -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)