Add initialState support to CreateRoomParams (#3713)
This commit is contained in:
parent
98720ce4a5
commit
b862e5ccbf
|
@ -0,0 +1 @@
|
|||
Add initialState support to CreateRoomParams (#3713)
|
|
@ -25,7 +25,6 @@ import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility
|
|||
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesAllowEntry
|
||||
import org.matrix.android.sdk.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
|
||||
|
||||
// TODO Give a way to include other initial states
|
||||
open class CreateRoomParams {
|
||||
/**
|
||||
* A public visibility indicates that the room will be shown in the published room list.
|
||||
|
@ -103,6 +102,13 @@ open class CreateRoomParams {
|
|||
*/
|
||||
val creationContent = mutableMapOf<String, Any>()
|
||||
|
||||
/**
|
||||
* A list of state events to set in the new room. This allows the user to override the default state events
|
||||
* set in the new room. The expected format of the state events are an object with type, state_key and content keys set.
|
||||
* Takes precedence over events set by preset, but gets overridden by name and topic keys.
|
||||
*/
|
||||
val initialStates = mutableListOf<CreateRoomStateEvent>()
|
||||
|
||||
/**
|
||||
* Set to true to disable federation of this room.
|
||||
* Default: false
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2021 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.api.session.room.model.create
|
||||
|
||||
import org.matrix.android.sdk.api.session.events.model.Content
|
||||
|
||||
data class CreateRoomStateEvent(
|
||||
/**
|
||||
* Required. The type of event to send.
|
||||
*/
|
||||
val type: String,
|
||||
|
||||
/**
|
||||
* Required. The content of the event.
|
||||
*/
|
||||
val content: Content,
|
||||
|
||||
/**
|
||||
* The state_key of the state event. Defaults to an empty string.
|
||||
*/
|
||||
val stateKey: String = ""
|
||||
)
|
|
@ -81,13 +81,14 @@ internal class CreateRoomBodyBuilder @Inject constructor(
|
|||
params.historyVisibility = params.historyVisibility ?: RoomHistoryVisibility.SHARED
|
||||
params.guestAccess = params.guestAccess ?: GuestAccess.Forbidden
|
||||
}
|
||||
val initialStates = listOfNotNull(
|
||||
val initialStates = (listOfNotNull(
|
||||
buildEncryptionWithAlgorithmEvent(params),
|
||||
buildHistoryVisibilityEvent(params),
|
||||
buildAvatarEvent(params),
|
||||
buildGuestAccess(params),
|
||||
buildJoinRulesRestricted(params)
|
||||
)
|
||||
+ buildCustomInitialStates(params))
|
||||
.takeIf { it.isNotEmpty() }
|
||||
|
||||
return CreateRoomBody(
|
||||
|
@ -107,6 +108,16 @@ internal class CreateRoomBodyBuilder @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
private fun buildCustomInitialStates(params: CreateRoomParams): List<Event> {
|
||||
return params.initialStates.map {
|
||||
Event(
|
||||
type = it.type,
|
||||
stateKey = it.stateKey,
|
||||
content = it.content
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun buildAvatarEvent(params: CreateRoomParams): Event? {
|
||||
return params.avatarUri?.let { avatarUri ->
|
||||
// First upload the image, ignoring any error
|
||||
|
|
Loading…
Reference in New Issue