Skip to content

Commit 1d2ddbc

Browse files
Fix bug where ephemeral events were not filtered by room ID (#19002)
Co-authored-by: Andrew Morgan <[email protected]>
1 parent 70c044d commit 1d2ddbc

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

changelog.d/19002.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where ephemeral events were not filtered by room ID. Contributed by @frastefanini.

synapse/handlers/sync.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ async def ephemeral_by_room(
553553
Returns:
554554
A tuple of the now StreamToken, updated to reflect the which typing
555555
events are included, and a dict mapping from room_id to a list of
556-
typing events for that room.
556+
ephemeral events for that room.
557557
"""
558558

559559
sync_config = sync_result_builder.sync_config
@@ -578,12 +578,8 @@ async def ephemeral_by_room(
578578
ephemeral_by_room: JsonDict = {}
579579

580580
for event in typing:
581-
# we want to exclude the room_id from the event, but modifying the
582-
# result returned by the event source is poor form (it might cache
583-
# the object)
584581
room_id = event["room_id"]
585-
event_copy = {k: v for (k, v) in event.items() if k != "room_id"}
586-
ephemeral_by_room.setdefault(room_id, []).append(event_copy)
582+
ephemeral_by_room.setdefault(room_id, []).append(event)
587583

588584
receipt_key = (
589585
since_token.receipt_key
@@ -603,9 +599,7 @@ async def ephemeral_by_room(
603599

604600
for event in receipts:
605601
room_id = event["room_id"]
606-
# exclude room id, as above
607-
event_copy = {k: v for (k, v) in event.items() if k != "room_id"}
608-
ephemeral_by_room.setdefault(room_id, []).append(event_copy)
602+
ephemeral_by_room.setdefault(room_id, []).append(event)
609603

610604
return now_token, ephemeral_by_room
611605

@@ -2734,9 +2728,17 @@ async def _generate_room_entry(
27342728
)
27352729
)
27362730

2737-
ephemeral = await sync_config.filter_collection.filter_room_ephemeral(
2738-
ephemeral
2739-
)
2731+
ephemeral = [
2732+
# per spec, ephemeral events (typing notifications and read receipts)
2733+
# should not have a `room_id` field when sent to clients
2734+
# refs:
2735+
# - https://spec.matrix.org/v1.16/client-server-api/#mtyping
2736+
# - https://spec.matrix.org/v1.16/client-server-api/#mreceipt
2737+
{k: v for (k, v) in event.items() if k != "room_id"}
2738+
for event in await sync_config.filter_collection.filter_room_ephemeral(
2739+
ephemeral
2740+
)
2741+
]
27402742

27412743
if not (
27422744
always_include

0 commit comments

Comments
 (0)