From 5df71c6161ac403e311db78b269f97b8cb5576f2 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 8 Aug 2022 16:09:54 +0200 Subject: [PATCH] Update CreateRoomParams from the potential FeaturePreset before persisting --- .../session/room/create/CreateLocalRoomTask.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateLocalRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateLocalRoomTask.kt index 78c8ebe099..52a30d937e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateLocalRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/create/CreateLocalRoomTask.kt @@ -91,7 +91,7 @@ internal class DefaultCreateLocalRoomTask @Inject constructor( val roomId = RoomLocalEcho.createLocalEchoId() monarchy.awaitTransaction { realm -> createLocalRoomEntity(realm, roomId, createRoomBody) - createLocalRoomSummaryEntity(realm, roomId, createRoomBody, params) + createLocalRoomSummaryEntity(realm, roomId, params, createRoomBody) } // Wait for room to be created in DB @@ -120,7 +120,8 @@ internal class DefaultCreateLocalRoomTask @Inject constructor( } } - private fun createLocalRoomSummaryEntity(realm: Realm, roomId: String, createRoomBody: CreateRoomBody, createRoomParams: CreateRoomParams) { + private fun createLocalRoomSummaryEntity(realm: Realm, roomId: String, createRoomParams: CreateRoomParams, createRoomBody: CreateRoomBody) { + // Create the room summary entity val roomSummaryEntity = realm.createObject(roomId).apply { val otherUserId = createRoomBody.getDirectUserId() if (otherUserId != null) { @@ -128,10 +129,20 @@ internal class DefaultCreateLocalRoomTask @Inject constructor( directUserId = otherUserId } } + + // Update the createRoomParams from the potential feature preset before saving + createRoomParams.featurePreset?.let { featurePreset -> + featurePreset.updateRoomParams(createRoomParams) + createRoomParams.initialStates.addAll(featurePreset.setupInitialStates().orEmpty()) + } + + // Create a LocalRoomSummaryEntity decorated by the related RoomSummaryEntity and the updated CreateRoomParams realm.createObject(roomId).also { it.roomSummaryEntity = roomSummaryEntity it.createRoomParams = createRoomParams } + + // Update the RoomSummaryEntity by simulating a fake sync response roomSummaryUpdater.update( realm = realm, roomId = roomId,