Improve RoomHistoryVisibility enum mapping
This commit is contained in:
parent
a124b514b8
commit
a1152ff72c
@ -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")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
|
||||||
"joined" -> RoomHistoryVisibility.JOINED
|
|
||||||
else -> {
|
|
||||||
Timber.w("Invalid value for RoomHistoryVisibility: `$historyVisibilityStr`")
|
Timber.w("Invalid value for RoomHistoryVisibility: `$historyVisibilityStr`")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user