Improve RoomHistoryVisibility enum mapping

This commit is contained in:
Florian Renaud 2022-08-08 17:13:28 +02:00 committed by Florian Renaud
parent a124b514b8
commit a1152ff72c
2 changed files with 11 additions and 15 deletions

View File

@ -23,30 +23,30 @@ import com.squareup.moshi.JsonClass
* Ref: https://matrix.org/docs/spec/client_server/latest#room-history-visibility * Ref: https://matrix.org/docs/spec/client_server/latest#room-history-visibility
*/ */
@JsonClass(generateAdapter = false) @JsonClass(generateAdapter = false)
enum class RoomHistoryVisibility { enum class RoomHistoryVisibility(val value: String) {
/** /**
* All events while this is the m.room.history_visibility value may be shared by any * All events while this is the m.room.history_visibility value may be shared by any
* participating homeserver with anyone, regardless of whether they have ever joined the room. * participating homeserver with anyone, regardless of whether they have ever joined the room.
*/ */
@Json(name = "world_readable") WORLD_READABLE, @Json(name = "world_readable") WORLD_READABLE("world_readable"),
/** /**
* Previous events are always accessible to newly joined members. All events in the * Previous events are always accessible to newly joined members. All events in the
* room are accessible, even those sent when the member was not a part of the room. * room are accessible, even those sent when the member was not a part of the room.
*/ */
@Json(name = "shared") SHARED, @Json(name = "shared") SHARED("shared"),
/** /**
* Events are accessible to newly joined members from the point they were invited onwards. * Events are accessible to newly joined members from the point they were invited onwards.
* Events stop being accessible when the member's state changes to something other than invite or join. * Events stop being accessible when the member's state changes to something other than invite or join.
*/ */
@Json(name = "invited") INVITED, @Json(name = "invited") INVITED("invited"),
/** /**
* Events are accessible to newly joined members from the point they joined the room onwards. * Events are accessible to newly joined members from the point they joined the room onwards.
* Events stop being accessible when the member's state changes to something other than join. * Events stop being accessible when the member's state changes to something other than join.
*/ */
@Json(name = "joined") JOINED @Json(name = "joined") JOINED("joined")
} }
/** /**

View File

@ -24,14 +24,10 @@ import timber.log.Timber
data class RoomHistoryVisibilityContent( data class RoomHistoryVisibilityContent(
@Json(name = "history_visibility") val historyVisibilityStr: String? = null @Json(name = "history_visibility") val historyVisibilityStr: String? = null
) { ) {
val historyVisibility: RoomHistoryVisibility? = when (historyVisibilityStr) { val historyVisibility: RoomHistoryVisibility? = RoomHistoryVisibility.values()
"world_readable" -> RoomHistoryVisibility.WORLD_READABLE .find { it.value == historyVisibilityStr }
"shared" -> RoomHistoryVisibility.SHARED ?: run {
"invited" -> RoomHistoryVisibility.INVITED Timber.w("Invalid value for RoomHistoryVisibility: `$historyVisibilityStr`")
"joined" -> RoomHistoryVisibility.JOINED null
else -> { }
Timber.w("Invalid value for RoomHistoryVisibility: `$historyVisibilityStr`")
null
}
}
} }