Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit e8a3e81

Browse files
authored
Don't fail on empty bodies when sending out read receipts (#10531)
Fixes a bug introduced in rc1 that would cause Synapse to 400 on read receipts requests with empty bodies. Broken in #10413
1 parent 903db99 commit e8a3e81

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

changelog.d/10531.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in Synapse v1.40.0rc1 that would cause Synapse to respond with an error when clients would update their read receipts.

synapse/rest/client/v2_alpha/receipts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def on_POST(self, request, room_id, receipt_type, event_id):
4343
if receipt_type != "m.read":
4444
raise SynapseError(400, "Receipt type must be 'm.read'")
4545

46-
body = parse_json_object_from_request(request)
46+
body = parse_json_object_from_request(request, allow_empty_body=True)
4747
hidden = body.get(ReadReceiptEventFields.MSC2285_HIDDEN, False)
4848

4949
if not isinstance(hidden, bool):

tests/rest/client/v2_alpha/test_sync.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,18 @@ def test_hidden_read_receipts(self):
418418
# Test that the first user can't see the other user's hidden read receipt
419419
self.assertEqual(self._get_read_receipt(), None)
420420

421+
def test_read_receipt_with_empty_body(self):
422+
# Send a message as the first user
423+
res = self.helper.send(self.room_id, body="hello", tok=self.tok)
424+
425+
# Send a read receipt for this message with an empty body
426+
channel = self.make_request(
427+
"POST",
428+
"/rooms/%s/receipt/m.read/%s" % (self.room_id, res["event_id"]),
429+
access_token=self.tok2,
430+
)
431+
self.assertEqual(channel.code, 200)
432+
421433
def _get_read_receipt(self):
422434
"""Syncs and returns the read receipt."""
423435

0 commit comments

Comments
 (0)