mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-29 14:38:45 +03:00
Be more robust when parsing some enums - RoomJoinRules
This commit is contained in:
parent
5364d7fd03
commit
ee265f71e6
2 changed files with 16 additions and 4 deletions
|
@ -19,11 +19,23 @@ package org.matrix.android.sdk.api.session.room.model
|
||||||
|
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing the EventType.STATE_ROOM_JOIN_RULES state event content
|
* Class representing the EventType.STATE_ROOM_JOIN_RULES state event content
|
||||||
*/
|
*/
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class RoomJoinRulesContent(
|
data class RoomJoinRulesContent constructor(
|
||||||
@Json(name = "join_rule") val joinRules: RoomJoinRules? = null
|
@Json(name = "join_rule") private val _joinRules: String? = null
|
||||||
)
|
) {
|
||||||
|
val joinRules: RoomJoinRules? = when (_joinRules) {
|
||||||
|
"public" -> RoomJoinRules.PUBLIC
|
||||||
|
"invite" -> RoomJoinRules.INVITE
|
||||||
|
"knock" -> RoomJoinRules.KNOCK
|
||||||
|
"private" -> RoomJoinRules.PRIVATE
|
||||||
|
else -> {
|
||||||
|
Timber.w("Invalid value for RoomJoinRules: `$_joinRules`")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
|
||||||
if (joinRules != null) {
|
if (joinRules != null) {
|
||||||
sendStateEvent(
|
sendStateEvent(
|
||||||
eventType = EventType.STATE_ROOM_JOIN_RULES,
|
eventType = EventType.STATE_ROOM_JOIN_RULES,
|
||||||
body = RoomJoinRulesContent(joinRules).toContent(),
|
body = mapOf("join_rule" to joinRules),
|
||||||
stateKey = null
|
stateKey = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue