From c5625bd868ca2624f8d8d35e27e4d16fedda7339 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 3 Oct 2022 14:09:14 -0400 Subject: [PATCH 1/3] Apply & bundle edits for non-message events. --- synapse/storage/databases/main/relations.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/synapse/storage/databases/main/relations.py b/synapse/storage/databases/main/relations.py index 898947af9536..aa5774a283e9 100644 --- a/synapse/storage/databases/main/relations.py +++ b/synapse/storage/databases/main/relations.py @@ -384,12 +384,11 @@ async def get_applicable_edits( the event will map to None. """ - # We only allow edits for `m.room.message` events that have the same sender - # and event type. We can't assert these things during regular event auth so - # we have to do the checks post hoc. + # We only allow edits for events that have the same sender and event type. + # We can't assert these things during regular event auth so we have to do + # the checks post hoc. - # Fetches latest edit that has the same type and sender as the - # original, and is an `m.room.message`. + # Fetches latest edit that has the same type and sender as the original. if isinstance(self.database_engine, PostgresEngine): # The `DISTINCT ON` clause will pick the *first* row it encounters, # so ordering by origin server ts + event ID desc will ensure we get @@ -405,7 +404,6 @@ async def get_applicable_edits( WHERE %s AND relation_type = ? - AND edit.type = 'm.room.message' ORDER by original.event_id DESC, edit.origin_server_ts DESC, edit.event_id DESC """ else: @@ -424,7 +422,6 @@ async def get_applicable_edits( WHERE %s AND relation_type = ? - AND edit.type = 'm.room.message' ORDER by edit.origin_server_ts, edit.event_id """ @@ -443,6 +440,8 @@ def _get_applicable_edits_txn(txn: LoggingTransaction) -> Dict[str, str]: edits = await self.get_events(edit_ids.values()) # type: ignore[attr-defined] + # TODO Should this assert m.new_content exists in the content for cleartext events? + # Map to the original event IDs to the edit events. # # There might not be an edit event due to there being no edits or From 67426452a9040915065192c397a307cd38be4319 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 3 Oct 2022 14:18:20 -0400 Subject: [PATCH 2/3] Newsfragment --- changelog.d/14034.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/14034.bugfix diff --git a/changelog.d/14034.bugfix b/changelog.d/14034.bugfix new file mode 100644 index 000000000000..e437ef3a01a1 --- /dev/null +++ b/changelog.d/14034.bugfix @@ -0,0 +1 @@ +Fix a long-standing bug where edits of non-`m.room.message` events would not be correctly bundled or have their new content applied. From c79c531dd0463c0b7ce43f1175863716f0133368 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Fri, 7 Oct 2022 10:15:47 -0400 Subject: [PATCH 3/3] Remove TODO to replace with a comment. --- synapse/storage/databases/main/relations.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/synapse/storage/databases/main/relations.py b/synapse/storage/databases/main/relations.py index 4150555376d3..116abef9de10 100644 --- a/synapse/storage/databases/main/relations.py +++ b/synapse/storage/databases/main/relations.py @@ -440,8 +440,6 @@ def _get_applicable_edits_txn(txn: LoggingTransaction) -> Dict[str, str]: edits = await self.get_events(edit_ids.values()) # type: ignore[attr-defined] - # TODO Should this assert m.new_content exists in the content for cleartext events? - # Map to the original event IDs to the edit events. # # There might not be an edit event due to there being no edits or