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

Handle string read receipt data #10606

Merged
merged 8 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10606.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix errors on /sync when read receipt data is a string with MSC2285 enabled. Contributed by @SimonBrandner.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 8 additions & 1 deletion synapse/handlers/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,14 @@ def filter_out_hidden(events: List[JsonDict], user_id: str) -> List[JsonDict]:

new_users = {}
for rr_user_id, user_rr in m_read.items():
hidden = user_rr.get("hidden", None)
try:
hidden = user_rr.get("hidden")
except AttributeError:
# Due to https://github.com/matrix-org/synapse/issues/10376
# there are cases where user_rr is a string, in those cases
# we just ignore the read receipt
continue

if hidden is not True or rr_user_id == user_id:
new_users[rr_user_id] = user_rr.copy()
# If hidden has a value replace hidden with the correct prefixed key
Expand Down
23 changes: 23 additions & 0 deletions tests/handlers/test_receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,29 @@ def test_filters_out_receipt_event_with_only_hidden_receipt_and_ignores_rest(sel
],
)

def test_handles_string_data(self):
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved
"""
Tests that an invalid shape for read-receipts is handled.
Context: https://github.com/matrix-org/synapse/issues/10603
"""

self._test_filters_hidden(
[
{
"content": {
"$14356419edgd14394fHBLK:matrix.org": {
"m.read": {
"@rikj:jki.re": "string",
}
},
},
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
"type": "m.receipt",
},
],
[],
)

def _test_filters_hidden(
self, events: List[JsonDict], expected_output: List[JsonDict]
):
Expand Down