Update CreateRoomParams from the potential FeaturePreset before persisting

This commit is contained in:
Florian Renaud 2022-08-08 16:09:54 +02:00
parent c96343f1d7
commit 5df71c6161
1 changed files with 13 additions and 2 deletions

View File

@ -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<RoomSummaryEntity>(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<LocalRoomSummaryEntity>(roomId).also {
it.roomSummaryEntity = roomSummaryEntity
it.createRoomParams = createRoomParams
}
// Update the RoomSummaryEntity by simulating a fake sync response
roomSummaryUpdater.update(
realm = realm,
roomId = roomId,