Fix bug where ephemeral events were not filtered by room ID (#19002)

Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
This commit is contained in:
Francesco Stefanini
2025-10-03 14:19:57 +02:00
committed by GitHub
parent 70c044db8e
commit 1d2ddbc76e
2 changed files with 15 additions and 12 deletions

1
changelog.d/19002.bugfix Normal file
View File

@@ -0,0 +1 @@
Fix bug where ephemeral events were not filtered by room ID. Contributed by @frastefanini.

View File

@@ -553,7 +553,7 @@ class SyncHandler:
Returns:
A tuple of the now StreamToken, updated to reflect the which typing
events are included, and a dict mapping from room_id to a list of
typing events for that room.
ephemeral events for that room.
"""
sync_config = sync_result_builder.sync_config
@@ -578,12 +578,8 @@ class SyncHandler:
ephemeral_by_room: JsonDict = {}
for event in typing:
# we want to exclude the room_id from the event, but modifying the
# result returned by the event source is poor form (it might cache
# the object)
room_id = event["room_id"]
event_copy = {k: v for (k, v) in event.items() if k != "room_id"}
ephemeral_by_room.setdefault(room_id, []).append(event_copy)
ephemeral_by_room.setdefault(room_id, []).append(event)
receipt_key = (
since_token.receipt_key
@@ -603,9 +599,7 @@ class SyncHandler:
for event in receipts:
room_id = event["room_id"]
# exclude room id, as above
event_copy = {k: v for (k, v) in event.items() if k != "room_id"}
ephemeral_by_room.setdefault(room_id, []).append(event_copy)
ephemeral_by_room.setdefault(room_id, []).append(event)
return now_token, ephemeral_by_room
@@ -2734,9 +2728,17 @@ class SyncHandler:
)
)
ephemeral = await sync_config.filter_collection.filter_room_ephemeral(
ephemeral
)
ephemeral = [
# per spec, ephemeral events (typing notifications and read receipts)
# should not have a `room_id` field when sent to clients
# refs:
# - https://spec.matrix.org/v1.16/client-server-api/#mtyping
# - https://spec.matrix.org/v1.16/client-server-api/#mreceipt
{k: v for (k, v) in event.items() if k != "room_id"}
for event in await sync_config.filter_collection.filter_room_ephemeral(
ephemeral
)
]
if not (
always_include