Allow sending custom data with read receipts

This commit is contained in:
Tulir Asokan 2021-05-18 15:20:00 +03:00
parent b73debdab6
commit e58055271c
2 changed files with 7 additions and 4 deletions

View File

@ -122,7 +122,8 @@ class ReceiptsHandler(BaseHandler):
return True
async def received_client_receipt(
self, room_id: str, receipt_type: str, user_id: str, event_id: str
self, room_id: str, receipt_type: str, user_id: str, event_id: str,
extra_content: Optional[JsonDict] = None,
) -> None:
"""Called when a client tells us a local user has read up to the given
event_id in the room.
@ -132,7 +133,7 @@ class ReceiptsHandler(BaseHandler):
receipt_type=receipt_type,
user_id=user_id,
event_ids=[event_id],
data={"ts": int(self.clock.time_msec())},
data={"ts": int(self.clock.time_msec()), **(extra_content or {})},
)
is_new = await self._handle_new_receipts([receipt])

View File

@ -15,7 +15,7 @@
import logging
from synapse.api.errors import SynapseError
from synapse.http.servlet import RestServlet
from synapse.http.servlet import RestServlet, parse_json_object_from_request
from ._base import client_patterns
@ -44,8 +44,10 @@ class ReceiptRestServlet(RestServlet):
await self.presence_handler.bump_presence_active_time(requester.user)
body = parse_json_object_from_request(request, allow_empty_body=True)
await self.receipts_handler.received_client_receipt(
room_id, receipt_type, user_id=requester.user.to_string(), event_id=event_id
room_id, receipt_type, user_id=requester.user.to_string(), event_id=event_id,
extra_content=body,
)
return 200, {}