Be more robust when parsing some enums - Guest Access
This commit is contained in:
parent
a7539d0f95
commit
5364d7fd03
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.api.session.room.model
|
|||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Class representing the EventType.STATE_ROOM_GUEST_ACCESS state event content
|
||||
|
@ -26,8 +27,17 @@ import com.squareup.moshi.JsonClass
|
|||
@JsonClass(generateAdapter = true)
|
||||
data class RoomGuestAccessContent(
|
||||
// Required. Whether guests can join the room. One of: ["can_join", "forbidden"]
|
||||
@Json(name = "guest_access") val guestAccess: GuestAccess? = null
|
||||
)
|
||||
@Json(name = "guest_access") private val _guestAccess: String? = null
|
||||
) {
|
||||
val guestAccess: GuestAccess? = when (_guestAccess) {
|
||||
"can_join" -> GuestAccess.CanJoin
|
||||
"forbidden" -> GuestAccess.Forbidden
|
||||
else -> {
|
||||
Timber.w("Invalid value for GuestAccess: `$_guestAccess`")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = false)
|
||||
enum class GuestAccess(val value: String) {
|
||||
|
|
|
@ -138,7 +138,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
|
|||
if (guestAccess != null) {
|
||||
sendStateEvent(
|
||||
eventType = EventType.STATE_ROOM_GUEST_ACCESS,
|
||||
body = RoomGuestAccessContent(guestAccess).toContent(),
|
||||
body = mapOf("guest_access" to guestAccess),
|
||||
stateKey = null
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue