From a1152ff72cbecf594558b7232aaf761753d0bc76 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 8 Aug 2022 17:13:28 +0200 Subject: [PATCH] Improve RoomHistoryVisibility enum mapping --- .../session/room/model/RoomHistoryVisibility.kt | 10 +++++----- .../room/model/RoomHistoryVisibilityContent.kt | 16 ++++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomHistoryVisibility.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomHistoryVisibility.kt index 2b0ea1d8fb..eef986ef96 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomHistoryVisibility.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomHistoryVisibility.kt @@ -23,30 +23,30 @@ import com.squareup.moshi.JsonClass * Ref: https://matrix.org/docs/spec/client_server/latest#room-history-visibility */ @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 * 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 * 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 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 stop being accessible when the member's state changes to something other than join. */ - @Json(name = "joined") JOINED + @Json(name = "joined") JOINED("joined") } /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomHistoryVisibilityContent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomHistoryVisibilityContent.kt index 39b4722c0c..696cd8f613 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomHistoryVisibilityContent.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomHistoryVisibilityContent.kt @@ -24,14 +24,10 @@ import timber.log.Timber data class RoomHistoryVisibilityContent( @Json(name = "history_visibility") val historyVisibilityStr: String? = null ) { - val historyVisibility: RoomHistoryVisibility? = when (historyVisibilityStr) { - "world_readable" -> RoomHistoryVisibility.WORLD_READABLE - "shared" -> RoomHistoryVisibility.SHARED - "invited" -> RoomHistoryVisibility.INVITED - "joined" -> RoomHistoryVisibility.JOINED - else -> { - Timber.w("Invalid value for RoomHistoryVisibility: `$historyVisibilityStr`") - null - } - } + val historyVisibility: RoomHistoryVisibility? = RoomHistoryVisibility.values() + .find { it.value == historyVisibilityStr } + ?: run { + Timber.w("Invalid value for RoomHistoryVisibility: `$historyVisibilityStr`") + null + } }