def sync_response(self): timeline = Timeline([ RoomMemberEvent( { "event_id": "event_id_1", "sender": ALICE_ID, "origin_server_ts": 1516809890615 }, ALICE_ID, "join", None, {"membership": "join"}), RoomMemberEvent( { "event_id": "event_id_2", "sender": ALICE_ID, "origin_server_ts": 1516809890615 }, CAROL_ID, "invite", None, {"membership": "invite"}, ), RoomEncryptionEvent({ "event_id": "event_id_3", "sender": ALICE_ID, "origin_server_ts": 1516809890615 }) ], False, "prev_batch_token") test_room_info = RoomInfo( timeline, [], [ TypingNoticeEvent([ALICE_ID]), ReceiptEvent([ Receipt(event_id="event_id_3", receipt_type="m.read", user_id=ALICE_ID, timestamp=1516809890615) ]) ], [], RoomSummary(invited_member_count=1, joined_member_count=2), ) rooms = Rooms({}, {TEST_ROOM_ID: test_room_info}, {}) return SyncResponse("token123", rooms, DeviceOneTimeKeyCount( 49, 50), DeviceList([ALICE_ID], []), [ RoomEncryptionEvent({ "event_id": "event_id_2", "sender": ALICE_ID, "origin_server_ts": 1516809890615 }) ])
async def onReceiptEvent( self, room: nio.MatrixRoom, ev: nio.ReceiptEvent, ) -> None: member_model = self.models[self.user_id, room.room_id, "members"] event_model = self.models[self.user_id, room.room_id, "events"] unassigned_mems = self.client.unassigned_member_last_read_event unassigned_evs = self.client.unassigned_event_last_read_by recount_markers = [] for receipt in ev.receipts: if receipt.user_id in self.client.backend.clients: continue if receipt.receipt_type != "m.read": continue echo_id = self.client.event_to_echo_ids.get(receipt.event_id) read_event = event_model.get(echo_id or receipt.event_id) timestamp = receipt.timestamp if read_event: recount_markers.append(read_event) read_event.last_read_by[receipt.user_id] = timestamp read_event.notify_change("last_read_by") else: # We haven't received the read event from the server yet unassigned_evs[receipt.event_id][receipt.user_id] = timestamp if receipt.user_id not in member_model: # We haven't loaded the member yet (lazy loading), or they left unassigned_mems[room.room_id, receipt.user_id] = \ echo_id or receipt.event_id continue member = member_model[receipt.user_id] previous_read_event = event_model.get(member.last_read_event) if previous_read_event: # Remove the read marker from the previous last read event recount_markers.append(previous_read_event) previous_read_event.last_read_by.pop(receipt.user_id, None) previous_read_event.notify_change("last_read_by") member.last_read_event = echo_id or receipt.event_id for ev in recount_markers: ev.read_by_count = len(ev.last_read_by)
def sync_response(self): timeline = Timeline([ RoomMemberEvent( { "event_id": "event_id_1", "sender": ALICE_ID, "origin_server_ts": 1516809890615 }, ALICE_ID, "join", None, {"membership": "join"}), RoomMemberEvent( { "event_id": "event_id_2", "sender": ALICE_ID, "origin_server_ts": 1516809890615 }, CAROL_ID, "invite", None, {"membership": "invite"}, ), RoomEncryptionEvent({ "event_id": "event_id_3", "sender": ALICE_ID, "origin_server_ts": 1516809890615 }) ], False, "prev_batch_token") test_room_info = RoomInfo( timeline=timeline, state=[], ephemeral=[ TypingNoticeEvent([ALICE_ID]), ReceiptEvent([ Receipt(event_id="event_id_3", receipt_type="m.read", user_id=ALICE_ID, timestamp=1516809890615) ]) ], account_data=[ FullyReadEvent(event_id="event_id_2"), TagEvent(tags={"u.test": { "order": 1 }}), ], summary=RoomSummary( invited_member_count=1, joined_member_count=2, ), ) rooms = Rooms(invite={}, join={TEST_ROOM_ID: test_room_info}, leave={}) return SyncResponse(next_batch="token123", rooms=rooms, device_key_count=DeviceOneTimeKeyCount(49, 50), device_list=DeviceList([ALICE_ID], []), to_device_events=[ RoomEncryptionEvent({ "event_id": "event_id_2", "sender": ALICE_ID, "origin_server_ts": 1516809890615 }) ], presence_events=[ PresenceEvent(ALICE_ID, "online", 1337, True, "I am here.") ])