Change (mention span) : rework and add more cases (#4476)
* change(mention span) : improve truncation logic * change(mention span) : fix theme switching * change(mention span) : start to pillify permalinks * change(mention span) : use permalink directly * change(mention span) : start improving mention type * change(mention span) : use the appropriate MentionSpanProvider methods * change(mention span) : introduce MentionSpanFormatter * change(mention span) : introduce MentionSpanUpdater * change(mention span) : Improve RoomNameCaches * change(mention span) : remove useless param on HtmlConverterProvider * change(mention span) : fix some remaining issues on the composer * change(mention span) : remove pillifiedBody * change(mention span) : fix some issues with pillification * change(mention span) : fix getMentionsSpans * change(mention span) : make sure all tests passes * change(mention span) : remove the coroutine from the caches and a MentionSpanFormatterTest * change(mention span) : add more tests on pillification * change(mention span) : clean up * Update screenshots * change(mention span) : remove unexpected print * change(mention span) : remove default values in constructor of TimelineTextBasedContent classes * Update screenshots --------- Co-authored-by: ElementBot <android@element.io>
This commit is contained in:
parent
a962479788
commit
042c0c5a6b
48 changed files with 1156 additions and 568 deletions
|
|
@ -7,32 +7,26 @@
|
|||
|
||||
package io.element.android.libraries.matrix.ui.messages
|
||||
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import io.element.android.libraries.di.RoomScope
|
||||
import io.element.android.libraries.di.SingleIn
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import io.element.android.libraries.matrix.api.room.RoomMember
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.runningFold
|
||||
import javax.inject.Inject
|
||||
|
||||
@SingleIn(RoomScope::class)
|
||||
class RoomMemberProfilesCache @Inject constructor() {
|
||||
private val cache = MutableStateFlow(mapOf<UserId, RoomMember>())
|
||||
val updateFlow = cache.drop(1).runningFold(0) { acc, _ -> acc + 1 }
|
||||
|
||||
private val _lastCacheUpdate = MutableStateFlow(0L)
|
||||
val lastCacheUpdate: StateFlow<Long> = _lastCacheUpdate
|
||||
|
||||
fun replace(items: List<RoomMember>) {
|
||||
suspend fun replace(items: List<RoomMember>) = coroutineScope {
|
||||
cache.value = items.associateBy { it.userId }
|
||||
_lastCacheUpdate.tryEmit(_lastCacheUpdate.value + 1)
|
||||
}
|
||||
|
||||
fun getDisplayName(userId: UserId): String? {
|
||||
return cache.value[userId]?.disambiguatedDisplayName
|
||||
}
|
||||
}
|
||||
|
||||
val LocalRoomMemberProfilesCache = staticCompositionLocalOf {
|
||||
RoomMemberProfilesCache()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.ui.messages
|
||||
|
||||
import io.element.android.libraries.di.RoomScope
|
||||
import io.element.android.libraries.di.SingleIn
|
||||
import io.element.android.libraries.matrix.api.core.RoomIdOrAlias
|
||||
import io.element.android.libraries.matrix.api.core.toRoomIdOrAlias
|
||||
import io.element.android.libraries.matrix.api.roomlist.RoomSummary
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.runningFold
|
||||
import javax.inject.Inject
|
||||
|
||||
@SingleIn(RoomScope::class)
|
||||
class RoomNamesCache @Inject constructor() {
|
||||
private val cache = MutableStateFlow(mapOf<RoomIdOrAlias, String?>())
|
||||
val updateFlow = cache.drop(1).runningFold(0) { acc, _ -> acc + 1 }
|
||||
|
||||
suspend fun replace(items: List<RoomSummary>) = coroutineScope {
|
||||
val roomNamesByRoomIdOrAlias = LinkedHashMap<RoomIdOrAlias, String?>(items.size * 2)
|
||||
items
|
||||
.forEach { summary ->
|
||||
roomNamesByRoomIdOrAlias[summary.info.id.toRoomIdOrAlias()] = summary.info.name
|
||||
val canonicalAlias = summary.info.canonicalAlias
|
||||
if (canonicalAlias != null) {
|
||||
roomNamesByRoomIdOrAlias[canonicalAlias.toRoomIdOrAlias()] = summary.info.name
|
||||
}
|
||||
}
|
||||
cache.value = roomNamesByRoomIdOrAlias
|
||||
}
|
||||
|
||||
fun getDisplayName(roomIdOrAlias: RoomIdOrAlias): String? {
|
||||
return cache.value[roomIdOrAlias]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue