Cleanup and safer Json model.

This commit is contained in:
Benoit Marty 2023-12-04 09:20:25 +01:00
parent 8e0c503b45
commit 778dab7bb7
3 changed files with 16 additions and 10 deletions

View File

@ -42,8 +42,10 @@ object Config {
const val ENABLE_LOCATION_SHARING = true const val ENABLE_LOCATION_SHARING = true
const val LOCATION_MAP_TILER_KEY = "fU3vlMsMn4Jb6dnEIFsx" const val LOCATION_MAP_TILER_KEY = "fU3vlMsMn4Jb6dnEIFsx"
/// Whether to read the `io.element.functional_members` state event /**
// and exclude any service members when computing a room's name and avatar. * Whether to read the `io.element.functional_members` state event
* and exclude any service members when computing a room's name and avatar.
*/
const val SUPPORT_FUNCTIONAL_MEMBERS = true const val SUPPORT_FUNCTIONAL_MEMBERS = true
/** /**

View File

@ -26,11 +26,13 @@ private const val FUNCTIONAL_MEMBERS_STATE_EVENT_TYPE = "io.element.functional_m
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class FunctionalMembersContent( data class FunctionalMembersContent(
@Json(name = "service_members") val userIds: List<String> @Json(name = "service_members") val userIds: List<String>? = null
) )
fun StateService.getFunctionalMembers(): List<String> { fun StateService.getFunctionalMembers(): List<String> {
return getStateEvent(FUNCTIONAL_MEMBERS_STATE_EVENT_TYPE, QueryStringValue.IsEmpty)?.let { return getStateEvent(FUNCTIONAL_MEMBERS_STATE_EVENT_TYPE, QueryStringValue.IsEmpty)
it.content.toModel<FunctionalMembersContent>()?.userIds ?.content
}.orEmpty() ?.toModel<FunctionalMembersContent>()
?.userIds
.orEmpty()
} }

View File

@ -32,10 +32,12 @@ class VectorRoomDisplayNameFallbackProvider @Inject constructor(
override fun excludedUserIds(roomId: String): List<String> { override fun excludedUserIds(roomId: String): List<String> {
if (!Config.SUPPORT_FUNCTIONAL_MEMBERS) return emptyList() if (!Config.SUPPORT_FUNCTIONAL_MEMBERS) return emptyList()
return activeSessionHolder.get().getSafeActiveSession() return activeSessionHolder.get()
?.getRoom(roomId)?.let { room -> .getSafeActiveSession()
room.stateService().getFunctionalMembers() ?.getRoom(roomId)
}.orEmpty() ?.stateService()
?.getFunctionalMembers()
.orEmpty()
} }
override fun getNameForRoomInvite(): String { override fun getNameForRoomInvite(): String {