Fix crash with RoomCreationParams

This commit is contained in:
Benoit Marty 2020-01-10 18:07:14 +01:00
parent 03b5b098c7
commit 0dbca829ea

View file

@ -28,6 +28,8 @@ import im.vector.matrix.android.api.session.room.model.PowerLevels
import im.vector.matrix.android.api.session.room.model.RoomDirectoryVisibility import im.vector.matrix.android.api.session.room.model.RoomDirectoryVisibility
import im.vector.matrix.android.api.session.room.model.RoomHistoryVisibility import im.vector.matrix.android.api.session.room.model.RoomHistoryVisibility
import im.vector.matrix.android.internal.auth.data.ThreePidMedium import im.vector.matrix.android.internal.auth.data.ThreePidMedium
import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
import timber.log.Timber
/** /**
* Parameter to create a room, with facilities functions to configure it * Parameter to create a room, with facilities functions to configure it
@ -88,7 +90,7 @@ class CreateRoomParams {
* A list of state events to set in the new room. * 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. * 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. * The expected format of the state events are an object with type, state_key and content keys set.
* Takes precedence over events set by presets, but gets overriden by name and topic keys. * Takes precedence over events set by presets, but gets overridden by name and topic keys.
*/ */
@Json(name = "initial_state") @Json(name = "initial_state")
var initialStates: MutableList<Event>? = null var initialStates: MutableList<Event>? = null
@ -120,12 +122,12 @@ class CreateRoomParams {
* *
* @param algorithm the algorithm * @param algorithm the algorithm
*/ */
fun addCryptoAlgorithm(algorithm: String) { fun enableEncryptionWithAlgorithm(algorithm: String) {
if (algorithm.isNotBlank()) { if (algorithm == MXCRYPTO_ALGORITHM_MEGOLM) {
val contentMap = HashMap<String, String>() val contentMap = mapOf("algorithm" to algorithm)
contentMap["algorithm"] = algorithm
val algoEvent = Event(type = EventType.STATE_ROOM_ENCRYPTION, val algoEvent = Event(
type = EventType.STATE_ROOM_ENCRYPTION,
stateKey = "", stateKey = "",
content = contentMap.toContent() content = contentMap.toContent()
) )
@ -135,6 +137,8 @@ class CreateRoomParams {
} else { } else {
initialStates!!.add(algoEvent) initialStates!!.add(algoEvent)
} }
} else {
Timber.e("Unsupported algorithm: $algorithm")
} }
} }
@ -145,13 +149,13 @@ class CreateRoomParams {
*/ */
fun setHistoryVisibility(historyVisibility: RoomHistoryVisibility?) { fun setHistoryVisibility(historyVisibility: RoomHistoryVisibility?) {
// Remove the existing value if any. // Remove the existing value if any.
initialStates?.removeAll { it.getClearType() == EventType.STATE_ROOM_HISTORY_VISIBILITY } initialStates?.removeAll { it.type == EventType.STATE_ROOM_HISTORY_VISIBILITY }
if (historyVisibility != null) { if (historyVisibility != null) {
val contentMap = HashMap<String, RoomHistoryVisibility>() val contentMap = mapOf("history_visibility" to historyVisibility)
contentMap["history_visibility"] = historyVisibility
val historyVisibilityEvent = Event(type = EventType.STATE_ROOM_HISTORY_VISIBILITY, val historyVisibilityEvent = Event(
type = EventType.STATE_ROOM_HISTORY_VISIBILITY,
stateKey = "", stateKey = "",
content = contentMap.toContent()) content = contentMap.toContent())