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