mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 01:45:05 +08:00
Use CreateRoomStateEvent in RoomFeaturePreset.setupInitialStates
This commit is contained in:
parent
d702210f26
commit
969689cdb9
@ -16,7 +16,6 @@
|
||||
|
||||
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.toContent
|
||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities
|
||||
@ -30,7 +29,7 @@ interface RoomFeaturePreset {
|
||||
|
||||
fun updateRoomParams(params: CreateRoomParams)
|
||||
|
||||
fun setupInitialStates(): List<Event>?
|
||||
fun setupInitialStates(): List<CreateRoomStateEvent>?
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
override fun setupInitialStates(): List<Event>? {
|
||||
override fun setupInitialStates(): List<CreateRoomStateEvent> {
|
||||
return listOf(
|
||||
Event(
|
||||
CreateRoomStateEvent(
|
||||
type = EventType.STATE_ROOM_JOIN_RULES,
|
||||
stateKey = "",
|
||||
content = RoomJoinRulesContent(
|
||||
|
@ -78,7 +78,7 @@ internal class CreateRoomBodyBuilder @Inject constructor(
|
||||
buildAvatarEvent(params),
|
||||
buildGuestAccess(params)
|
||||
) +
|
||||
params.featurePreset?.setupInitialStates().orEmpty() +
|
||||
buildFeaturePresetInitialStates(params) +
|
||||
buildCustomInitialStates(params)
|
||||
)
|
||||
.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> {
|
||||
return params.initialStates.map {
|
||||
Event(
|
||||
|
Loading…
Reference in New Issue
Block a user