-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Include bundled aggregations for the latest event in a thread #12273
Changes from 30 commits
797dd9e
5065c10
f0ab01f
d78ca4c
5a1c218
560a4ac
3f8bd1f
60ac6b4
af4c814
a63d62a
cf96c0a
d247e72
2a64c41
14ff585
a8c02b4
5e18d24
c89d227
8fe3029
823a6b1
db0ccce
87dc36a
d87dcba
8c65ace
1ccde00
6951c83
566b66c
c48b220
586943c
36ec434
c499757
d8d2879
34ee419
53fda7f
bd886bb
4f7132c
98d73e9
6bcb2dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix a bug introduced in Synapse v1.48.0 where latest thread reply provided failed to include the proper bundled aggregations. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,8 +44,6 @@ | |
| class _ThreadAggregation: | ||
| # The latest event in the thread. | ||
| latest_event: EventBase | ||
| # The latest edit to the latest event in the thread. | ||
| latest_edit: Optional[EventBase] | ||
| # The total number of events in the thread. | ||
| count: int | ||
| # True if the current user has sent an event to the thread. | ||
|
|
@@ -295,7 +293,7 @@ async def get_threads_for_events( | |
|
|
||
| for event_id, summary in summaries.items(): | ||
| if summary: | ||
| thread_count, latest_thread_event, edit = summary | ||
| thread_count, latest_thread_event = summary | ||
|
|
||
| # Subtract off the count of any ignored users. | ||
| for ignored_user in ignored_users: | ||
|
|
@@ -340,7 +338,6 @@ async def get_threads_for_events( | |
|
|
||
| results[event_id] = _ThreadAggregation( | ||
| latest_event=latest_thread_event, | ||
| latest_edit=edit, | ||
| count=thread_count, | ||
| # If there's a thread summary it must also exist in the | ||
| # participated dictionary. | ||
|
|
@@ -359,8 +356,13 @@ async def get_bundled_aggregations( | |
| user_id: The user requesting the bundled aggregations. | ||
|
|
||
| Returns: | ||
| A map of event ID to the bundled aggregation for the event. Not all | ||
| events may have bundled aggregations in the results. | ||
| A map of event ID to the bundled aggregations for the event. | ||
|
|
||
| Not all requested events may exist in the results (if they don't have | ||
| bundled aggregations). | ||
|
|
||
| The results may include additional events which are related to the | ||
| requested events. | ||
| """ | ||
| # De-duplicate events by ID to handle the same event requested multiple times. | ||
| # | ||
|
|
@@ -369,21 +371,51 @@ async def get_bundled_aggregations( | |
| event.event_id: event for event in events if not event.is_state() | ||
| } | ||
|
|
||
| # A map of event ID to the relation in that event, if there is one. | ||
| relations_by_id = {} | ||
clokep marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for event_id, event in events_by_id.items(): | ||
| relates_to = event.content.get("m.relates_to") | ||
| if isinstance(relates_to, (dict, frozendict)): | ||
| relation_type = relates_to.get("rel_type") | ||
| if relation_type is not None: | ||
| relations_by_id[event_id] = relation_type | ||
|
|
||
| # event ID -> bundled aggregation in non-serialized form. | ||
| results: Dict[str, BundledAggregations] = {} | ||
|
|
||
| # Fetch any ignored users of the requesting user. | ||
| ignored_users = await self._main_store.ignored_users(user_id) | ||
|
|
||
| # Threads are special as the latest event of a thread might cause additional | ||
| # events to be fetched. Thus, we check those first! | ||
|
|
||
| # Fetch thread summaries (but only for the directly requested events). | ||
| threads = await self.get_threads_for_events( | ||
| # It is not valid to start a thread on an event which already has a relation. | ||
clokep marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [eid for eid in events_by_id.keys() if eid not in relations_by_id], | ||
|
||
| user_id, | ||
| ignored_users, | ||
| ) | ||
| for event_id, thread in threads.items(): | ||
| results.setdefault(event_id, BundledAggregations()).thread = thread | ||
|
|
||
| # If the latest event in a thread is not already being fetched, | ||
| # add it. This ensures that the bundled aggregations for the | ||
| # latest thread event is correct. | ||
| latest_thread_event = thread.latest_event | ||
| if latest_thread_event and latest_thread_event.event_id not in events_by_id: | ||
| events_by_id[latest_thread_event.event_id] = latest_thread_event | ||
| # The latest event in the thread must have a thread relation. | ||
|
||
| relations_by_id[latest_thread_event.event_id] = RelationTypes.THREAD | ||
|
|
||
| # Fetch other relations per event. | ||
| for event in events_by_id.values(): | ||
| # Do not bundle aggregations for an event which represents an edit or an | ||
| # annotation. It does not make sense for them to have related events. | ||
| relates_to = event.content.get("m.relates_to") | ||
| if isinstance(relates_to, (dict, frozendict)): | ||
| relation_type = relates_to.get("rel_type") | ||
| if relation_type in (RelationTypes.ANNOTATION, RelationTypes.REPLACE): | ||
| continue | ||
| # Edits and annotations may not have related annotations or references. | ||
clokep marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if relations_by_id.get(event.event_id) in ( | ||
| RelationTypes.ANNOTATION, | ||
| RelationTypes.REPLACE, | ||
| ): | ||
| continue | ||
|
|
||
| annotations = await self.get_annotations_for_event( | ||
clokep marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| event.event_id, event.room_id, ignored_users=ignored_users | ||
|
|
@@ -425,10 +457,4 @@ async def get_bundled_aggregations( | |
| for event_id, edit in edits.items(): | ||
| results.setdefault(event_id, BundledAggregations()).replace = edit | ||
|
|
||
| threads = await self.get_threads_for_events( | ||
| events_by_id.keys(), user_id, ignored_users | ||
| ) | ||
| for event_id, thread in threads.items(): | ||
| results.setdefault(event_id, BundledAggregations()).thread = thread | ||
|
|
||
| return results | ||
Uh oh!
There was an error while loading. Please reload this page.