From ae176324cbd0623f073a02f7a545c845ef011dfe Mon Sep 17 00:00:00 2001 From: Aminda Suomalainen Date: Wed, 18 May 2022 20:13:23 +0300 Subject: [PATCH 1/4] Implement MSC 3818 Resolves: #11896 Signed-off-by: Aminda Suomalainen --- changelog.d/12786.feature | 1 + synapse/handlers/room.py | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelog.d/12786.feature diff --git a/changelog.d/12786.feature b/changelog.d/12786.feature new file mode 100644 index 000000000000..a67c71b0cabd --- /dev/null +++ b/changelog.d/12786.feature @@ -0,0 +1 @@ +Implement [MSC 3818: Copy room type on upgrade](https://github.com/matrix-org/matrix-spec-proposals/pull/3818). diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 53569e521219..7fab4a9617c6 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -469,13 +469,17 @@ async def clone_existing_room( (EventTypes.PowerLevels, ""), ] - # If the old room was a space, copy over the room type and the rooms in - # the space. + # Copy the room type as per MSC3818 https://github.com/matrix-org/matrix-spec-proposals/pull/3818. + if old_room_create_event.content.get(EventContentFields.ROOM_TYPE) is not None: + creation_content[ + EventContentFields.ROOM_TYPE + ] = old_room_create_event.content.get(EventContentFields.ROOM_TYPE) + + # If the old room was a space, copy over the rooms in the space. if ( old_room_create_event.content.get(EventContentFields.ROOM_TYPE) == RoomTypes.SPACE ): - creation_content[EventContentFields.ROOM_TYPE] = RoomTypes.SPACE types_to_copy.append((EventTypes.SpaceChild, None)) old_room_state_ids = await self.store.get_filtered_current_state_ids( From 24b56d728f95a58dca4ad8cf8e0bf8c7342bf1ce Mon Sep 17 00:00:00 2001 From: Aminda Suomalainen Date: Thu, 19 May 2022 13:26:30 +0300 Subject: [PATCH 2/4] feedback from review Signed-off-by: Aminda Suomalainen --- synapse/handlers/room.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 7fab4a9617c6..b2403545d9fb 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -469,18 +469,16 @@ async def clone_existing_room( (EventTypes.PowerLevels, ""), ] - # Copy the room type as per MSC3818 https://github.com/matrix-org/matrix-spec-proposals/pull/3818. - if old_room_create_event.content.get(EventContentFields.ROOM_TYPE) is not None: + # Copy the room type as per MSC3818. + room_type = old_room_create_event.content.get(EventContentFields.ROOM_TYPE) + if room_type is not None: creation_content[ EventContentFields.ROOM_TYPE ] = old_room_create_event.content.get(EventContentFields.ROOM_TYPE) - # If the old room was a space, copy over the rooms in the space. - if ( - old_room_create_event.content.get(EventContentFields.ROOM_TYPE) - == RoomTypes.SPACE - ): - types_to_copy.append((EventTypes.SpaceChild, None)) + # If the old room was a space, copy over the rooms in the space. + if room_type == RoomTypes.SPACE: + types_to_copy.append((EventTypes.SpaceChild, None)) old_room_state_ids = await self.store.get_filtered_current_state_ids( old_room_id, StateFilter.from_types(types_to_copy) From 743fdbeed2becd2748365e50eb5c2a3b225848ec Mon Sep 17 00:00:00 2001 From: Aminda Suomalainen Date: Thu, 19 May 2022 13:31:17 +0300 Subject: [PATCH 3/4] Update changelog.d/12786.feature Signed-off-by: Aminda Suomalainen Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> --- changelog.d/12786.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/12786.feature b/changelog.d/12786.feature index a67c71b0cabd..c90ddd411ee2 100644 --- a/changelog.d/12786.feature +++ b/changelog.d/12786.feature @@ -1 +1 @@ -Implement [MSC 3818: Copy room type on upgrade](https://github.com/matrix-org/matrix-spec-proposals/pull/3818). +Implement [MSC3818: Copy room type on upgrade](https://github.com/matrix-org/matrix-spec-proposals/pull/3818). From 0835b6d7e54a190db4f8040878e71c81a9fb8e67 Mon Sep 17 00:00:00 2001 From: Aminda Suomalainen Date: Thu, 19 May 2022 13:52:34 +0300 Subject: [PATCH 4/4] oops Signed-off-by: Aminda Suomalainen --- synapse/handlers/room.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index b2403545d9fb..b7d64a2f5a29 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -472,9 +472,7 @@ async def clone_existing_room( # Copy the room type as per MSC3818. room_type = old_room_create_event.content.get(EventContentFields.ROOM_TYPE) if room_type is not None: - creation_content[ - EventContentFields.ROOM_TYPE - ] = old_room_create_event.content.get(EventContentFields.ROOM_TYPE) + creation_content[EventContentFields.ROOM_TYPE] = room_type # If the old room was a space, copy over the rooms in the space. if room_type == RoomTypes.SPACE: