2020#
2121
2222import logging
23+ from http import HTTPStatus
2324from typing import TYPE_CHECKING , Tuple
2425
2526from synapse .api .constants import MAIN_TIMELINE , ReceiptTypes
@@ -50,6 +51,7 @@ def __init__(self, hs: "HomeServer"):
5051 self .read_marker_handler = hs .get_read_marker_handler ()
5152 self .presence_handler = hs .get_presence_handler ()
5253 self ._main_store = hs .get_datastores ().main
54+ self ._msc4446_enabled = hs .config .experimental .msc4446_enabled
5355
5456 self ._known_receipt_types = {
5557 ReceiptTypes .READ ,
@@ -74,6 +76,25 @@ async def on_POST(
7476
7577 body = parse_json_object_from_request (request , allow_empty_body = False )
7678
79+ if self ._msc4446_enabled :
80+ allow_backward = body .get ("com.beeper.allow_backward" , False )
81+ if not isinstance (allow_backward , bool ):
82+ raise SynapseError (
83+ HTTPStatus .BAD_REQUEST ,
84+ "com.beeper.allow_backward must be a boolean." ,
85+ Codes .INVALID_PARAM ,
86+ )
87+
88+ if allow_backward and receipt_type != ReceiptTypes .FULLY_READ :
89+ raise SynapseError (
90+ HTTPStatus .BAD_REQUEST ,
91+ "com.beeper.allow_backward is only allowed to be true for "
92+ f"{ ReceiptTypes .FULLY_READ } ." ,
93+ Codes .INVALID_PARAM ,
94+ )
95+ else :
96+ allow_backward = False
97+
7798 # Pull the thread ID, if one exists.
7899 thread_id = None
79100 if "thread_id" in body :
@@ -109,6 +130,7 @@ async def on_POST(
109130 room_id ,
110131 user_id = requester .user .to_string (),
111132 event_id = event_id ,
133+ allow_backward = allow_backward ,
112134 extra_content = body ,
113135 )
114136 else :
0 commit comments