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

Commit a84e165

Browse files
committed
Edits and annotations should not have any bundled aggregations caclulated.
1 parent 33abb06 commit a84e165

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

synapse/handlers/relations.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -364,21 +364,29 @@ async def get_bundled_aggregations(
364364
The results may include additional events which are related to the
365365
requested events.
366366
"""
367-
# De-duplicate events by ID to handle the same event requested multiple times.
368-
#
369-
# State events do not get bundled aggregations.
370-
events_by_id = {
371-
event.event_id: event for event in events if not event.is_state()
372-
}
373-
367+
# De-duplicated events by ID to handle the same event requested multiple times.
368+
events_by_id = {}
374369
# A map of event ID to the relation in that event, if there is one.
375370
relations_by_id: Dict[str, str] = {}
376-
for event_id, event in events_by_id.items():
371+
for event in events:
372+
# State events do not get bundled aggregations.
373+
if event.is_state():
374+
continue
375+
377376
relates_to = event.content.get("m.relates_to")
377+
relation_type = None
378378
if isinstance(relates_to, collections.abc.Mapping):
379379
relation_type = relates_to.get("rel_type")
380-
if isinstance(relation_type, str):
381-
relations_by_id[event_id] = relation_type
380+
# An event which is a replacement (ie edit) or annotation (ie,
381+
# reaction) may not have any other event related to it.
382+
if relation_type in (RelationTypes.ANNOTATION, RelationTypes.REPLACE):
383+
continue
384+
385+
# The event should get bundled aggregations.
386+
events_by_id[event.event_id] = event
387+
# Track the event's relation information for later.
388+
if isinstance(relation_type, str):
389+
relations_by_id[event.event_id] = relation_type
382390

383391
# event ID -> bundled aggregation in non-serialized form.
384392
results: Dict[str, BundledAggregations] = {}
@@ -413,16 +421,6 @@ async def get_bundled_aggregations(
413421

414422
# Fetch other relations per event.
415423
for event in events_by_id.values():
416-
# An event which is a replacement (ie edit) or annotation (ie, reaction)
417-
# may not have any other event related to it.
418-
#
419-
# XXX This is buggy, see https://github.com/matrix-org/synapse/issues/12566
420-
if relations_by_id.get(event.event_id) in (
421-
RelationTypes.ANNOTATION,
422-
RelationTypes.REPLACE,
423-
):
424-
continue
425-
426424
# Fetch any annotations (ie, reactions) to bundle with this event.
427425
annotations = await self.get_annotations_for_event(
428426
event.event_id, event.room_id, ignored_users=ignored_users

0 commit comments

Comments
 (0)