This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Include bundled aggregations for the latest event in a thread #12273
Merged
Merged
Changes from 29 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
797dd9e
The latest event in a thread should include bundled aggregations.
clokep 5065c10
Move the thread edit test into BundledAggregationstTestCase.
clokep f0ab01f
Support including other bundled aggregations for the latest event.
clokep d78ca4c
Do not recurse into threads indefinitely.
clokep 5a1c218
Rejigger to avoid passing state around.
clokep 560a4ac
Newsfragment
clokep 3f8bd1f
Clarify comment.
clokep 60ac6b4
Review comments.
clokep af4c814
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep a63d62a
Lint
clokep cf96c0a
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep d247e72
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep 2a64c41
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep 14ff585
Add more checks to ensure that threads don't return bundled aggregati…
clokep a8c02b4
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep 5e18d24
Fix parameter ordering in docstring.
clokep c89d227
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep 8fe3029
Fix frozendicts on Python 3.10.
clokep 823a6b1
Clean-up and rename test_thread_loop.
clokep db0ccce
Reduce duplicated code.
clokep 87dc36a
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep d87dcba
Lint
clokep 8c65ace
Clarify docstrings.
clokep 1ccde00
Remove useless helper method.
clokep 6951c83
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep 566b66c
Avoid generating bundled thread aggregations for events with a relation.
clokep c48b220
Clarify comment.
clokep 586943c
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep 36ec434
Clarify comments.
clokep c499757
Keep data in sync.
clokep d8d2879
Merge remote-tracking branch 'origin/develop' into clokep/bundled-agg…
clokep 34ee419
Clarify comment.
clokep 53fda7f
Merge remote-tracking branch 'refs/remotes/origin/clokep/bundled-aggs…
clokep bd886bb
Add comments.
clokep 4f7132c
Clarify comment.
clokep 98d73e9
References != replies.
clokep 6bcb2dc
Better checking of relation types.
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,49 @@ 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 | ||
|
|
||
| # 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 +455,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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.