forked from MirrorHub/synapse
Allow custom content in read receipts
This commit is contained in:
parent
4eddcf6653
commit
7dbc917769
4 changed files with 18 additions and 5 deletions
|
@ -13,9 +13,10 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from synapse.util.async_helpers import Linearizer
|
from synapse.util.async_helpers import Linearizer
|
||||||
|
from synapse.types import JsonDict
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from synapse.server import HomeServer
|
from synapse.server import HomeServer
|
||||||
|
@ -31,7 +32,11 @@ class ReadMarkerHandler:
|
||||||
self.read_marker_linearizer = Linearizer(name="read_marker")
|
self.read_marker_linearizer = Linearizer(name="read_marker")
|
||||||
|
|
||||||
async def received_client_read_marker(
|
async def received_client_read_marker(
|
||||||
self, room_id: str, user_id: str, event_id: str
|
self,
|
||||||
|
room_id: str,
|
||||||
|
user_id: str,
|
||||||
|
event_id: str,
|
||||||
|
extra_content: Optional[JsonDict] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Updates the read marker for a given user in a given room if the event ID given
|
"""Updates the read marker for a given user in a given room if the event ID given
|
||||||
is ahead in the stream relative to the current read marker.
|
is ahead in the stream relative to the current read marker.
|
||||||
|
@ -54,7 +59,7 @@ class ReadMarkerHandler:
|
||||||
)
|
)
|
||||||
|
|
||||||
if should_update:
|
if should_update:
|
||||||
content = {"event_id": event_id}
|
content = {"event_id": event_id, **(extra_content or {})}
|
||||||
await self.account_data_handler.add_account_data_to_room(
|
await self.account_data_handler.add_account_data_to_room(
|
||||||
user_id, room_id, "m.fully_read", content
|
user_id, room_id, "m.fully_read", content
|
||||||
)
|
)
|
||||||
|
|
|
@ -161,6 +161,7 @@ class ReceiptsHandler:
|
||||||
user_id: str,
|
user_id: str,
|
||||||
event_id: str,
|
event_id: str,
|
||||||
thread_id: Optional[str],
|
thread_id: Optional[str],
|
||||||
|
extra_content: Optional[JsonDict] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Called when a client tells us a local user has read up to the given
|
"""Called when a client tells us a local user has read up to the given
|
||||||
event_id in the room.
|
event_id in the room.
|
||||||
|
@ -171,7 +172,7 @@ class ReceiptsHandler:
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
event_ids=[event_id],
|
event_ids=[event_id],
|
||||||
thread_id=thread_id,
|
thread_id=thread_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])
|
is_new = await self._handle_new_receipts([receipt])
|
||||||
|
|
|
@ -70,12 +70,16 @@ class ReadMarkerRestServlet(RestServlet):
|
||||||
# TODO Add validation to reject non-string event IDs.
|
# TODO Add validation to reject non-string event IDs.
|
||||||
if not event_id:
|
if not event_id:
|
||||||
continue
|
continue
|
||||||
|
extra_content = body.get(
|
||||||
|
receipt_type.replace("m.", "com.beeper.") + ".extra", None
|
||||||
|
)
|
||||||
|
|
||||||
if receipt_type == ReceiptTypes.FULLY_READ:
|
if receipt_type == ReceiptTypes.FULLY_READ:
|
||||||
await self.read_marker_handler.received_client_read_marker(
|
await self.read_marker_handler.received_client_read_marker(
|
||||||
room_id,
|
room_id,
|
||||||
user_id=requester.user.to_string(),
|
user_id=requester.user.to_string(),
|
||||||
event_id=event_id,
|
event_id=event_id,
|
||||||
|
extra_content=extra_content,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await self.receipts_handler.received_client_receipt(
|
await self.receipts_handler.received_client_receipt(
|
||||||
|
@ -85,6 +89,7 @@ class ReadMarkerRestServlet(RestServlet):
|
||||||
event_id=event_id,
|
event_id=event_id,
|
||||||
# Setting the thread ID is not possible with the /read_markers endpoint.
|
# Setting the thread ID is not possible with the /read_markers endpoint.
|
||||||
thread_id=None,
|
thread_id=None,
|
||||||
|
extra_content=extra_content,
|
||||||
)
|
)
|
||||||
|
|
||||||
return 200, {}
|
return 200, {}
|
||||||
|
|
|
@ -65,7 +65,7 @@ class ReceiptRestServlet(RestServlet):
|
||||||
f"Receipt type must be {', '.join(self._known_receipt_types)}",
|
f"Receipt type must be {', '.join(self._known_receipt_types)}",
|
||||||
)
|
)
|
||||||
|
|
||||||
body = parse_json_object_from_request(request)
|
body = parse_json_object_from_request(request, allow_empty_body=False)
|
||||||
|
|
||||||
# Pull the thread ID, if one exists.
|
# Pull the thread ID, if one exists.
|
||||||
thread_id = None
|
thread_id = None
|
||||||
|
@ -100,6 +100,7 @@ class ReceiptRestServlet(RestServlet):
|
||||||
room_id,
|
room_id,
|
||||||
user_id=requester.user.to_string(),
|
user_id=requester.user.to_string(),
|
||||||
event_id=event_id,
|
event_id=event_id,
|
||||||
|
extra_content=body,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
await self.receipts_handler.received_client_receipt(
|
await self.receipts_handler.received_client_receipt(
|
||||||
|
@ -108,6 +109,7 @@ class ReceiptRestServlet(RestServlet):
|
||||||
user_id=requester.user.to_string(),
|
user_id=requester.user.to_string(),
|
||||||
event_id=event_id,
|
event_id=event_id,
|
||||||
thread_id=thread_id,
|
thread_id=thread_id,
|
||||||
|
extra_content=body,
|
||||||
)
|
)
|
||||||
|
|
||||||
return 200, {}
|
return 200, {}
|
||||||
|
|
Loading…
Reference in a new issue