Use CreateRoomStateEvent in RoomFeaturePreset.setupInitialStates

This commit is contained in:
Florian Renaud 2022-08-08 16:08:49 +02:00 committed by Florian Renaud
parent d702210f26
commit 969689cdb9
2 changed files with 14 additions and 5 deletions

View File

@ -16,7 +16,6 @@
package org.matrix.android.sdk.api.session.room.model.create package org.matrix.android.sdk.api.session.room.model.create
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toContent
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
@ -30,7 +29,7 @@ interface RoomFeaturePreset {
fun updateRoomParams(params: CreateRoomParams) fun updateRoomParams(params: CreateRoomParams)
fun setupInitialStates(): List<Event>? fun setupInitialStates(): List<CreateRoomStateEvent>?
} }
class RestrictedRoomPreset(val homeServerCapabilities: HomeServerCapabilities, val restrictedList: List<RoomJoinRulesAllowEntry>) : RoomFeaturePreset { class RestrictedRoomPreset(val homeServerCapabilities: HomeServerCapabilities, val restrictedList: List<RoomJoinRulesAllowEntry>) : RoomFeaturePreset {
@ -41,9 +40,9 @@ class RestrictedRoomPreset(val homeServerCapabilities: HomeServerCapabilities, v
params.roomVersion = homeServerCapabilities.versionOverrideForFeature(HomeServerCapabilities.ROOM_CAP_RESTRICTED) params.roomVersion = homeServerCapabilities.versionOverrideForFeature(HomeServerCapabilities.ROOM_CAP_RESTRICTED)
} }
override fun setupInitialStates(): List<Event>? { override fun setupInitialStates(): List<CreateRoomStateEvent> {
return listOf( return listOf(
Event( CreateRoomStateEvent(
type = EventType.STATE_ROOM_JOIN_RULES, type = EventType.STATE_ROOM_JOIN_RULES,
stateKey = "", stateKey = "",
content = RoomJoinRulesContent( content = RoomJoinRulesContent(

View File

@ -78,7 +78,7 @@ internal class CreateRoomBodyBuilder @Inject constructor(
buildAvatarEvent(params), buildAvatarEvent(params),
buildGuestAccess(params) buildGuestAccess(params)
) + ) +
params.featurePreset?.setupInitialStates().orEmpty() + buildFeaturePresetInitialStates(params) +
buildCustomInitialStates(params) buildCustomInitialStates(params)
) )
.takeIf { it.isNotEmpty() } .takeIf { it.isNotEmpty() }
@ -99,6 +99,16 @@ internal class CreateRoomBodyBuilder @Inject constructor(
) )
} }
private fun buildFeaturePresetInitialStates(params: CreateRoomParams): List<Event> {
return params.featurePreset?.setupInitialStates().orEmpty().map {
Event(
type = it.type,
stateKey = it.stateKey,
content = it.content
)
}
}
private fun buildCustomInitialStates(params: CreateRoomParams): List<Event> { private fun buildCustomInitialStates(params: CreateRoomParams): List<Event> {
return params.initialStates.map { return params.initialStates.map {
Event( Event(