Improve GuestAccess enum mapping

This commit is contained in:
Florian Renaud 2022-08-08 17:08:21 +02:00 committed by Florian Renaud
parent 969689cdb9
commit a124b514b8

View File

@ -29,14 +29,12 @@ data class RoomGuestAccessContent(
// Required. Whether guests can join the room. One of: ["can_join", "forbidden"]
@Json(name = "guest_access") val guestAccessStr: String? = null
) {
val guestAccess: GuestAccess? = when (guestAccessStr) {
"can_join" -> GuestAccess.CanJoin
"forbidden" -> GuestAccess.Forbidden
else -> {
val guestAccess: GuestAccess? = GuestAccess.values()
.find { it.value == guestAccessStr }
?: run {
Timber.w("Invalid value for GuestAccess: `$guestAccessStr`")
null
}
}
}
@JsonClass(generateAdapter = false)