Adds space name to rooms in filtered search

This commit is contained in:
ericdecanini 2022-04-28 10:41:40 +02:00
parent a3367d4075
commit 9e53e6cc8f
11 changed files with 52 additions and 41 deletions

View File

@ -43,7 +43,6 @@ internal class RoomChildRelationInfo(
data class SpaceChildInfo( data class SpaceChildInfo(
val roomId: String, val roomId: String,
val order: String?, val order: String?,
// val autoJoin: Boolean,
val viaServers: List<String> val viaServers: List<String>
) )
@ -60,18 +59,13 @@ internal class RoomChildRelationInfo(
fun getDirectChildrenDescriptions(): List<SpaceChildInfo> { fun getDirectChildrenDescriptions(): List<SpaceChildInfo> {
return CurrentStateEventEntity.whereType(realm, roomId, EventType.STATE_SPACE_CHILD) return CurrentStateEventEntity.whereType(realm, roomId, EventType.STATE_SPACE_CHILD)
.findAll() .findAll()
// .also {
// Timber.v("## Space: Found ${it.count()} m.space.child state events for $roomId")
// }
.mapNotNull { .mapNotNull {
ContentMapper.map(it.root?.content).toModel<SpaceChildContent>()?.let { scc -> ContentMapper.map(it.root?.content).toModel<SpaceChildContent>()?.let { scc ->
// Timber.v("## Space child desc state event $scc")
// Children where via is not present are ignored. // Children where via is not present are ignored.
scc.via?.let { via -> scc.via?.let { via ->
SpaceChildInfo( SpaceChildInfo(
roomId = it.stateKey, roomId = it.stateKey,
order = scc.validOrder(), order = scc.validOrder(),
// autoJoin = scc.autoJoin ?: false,
viaServers = via viaServers = via
) )
} }
@ -83,17 +77,13 @@ internal class RoomChildRelationInfo(
fun getParentDescriptions(): List<SpaceParentInfo> { fun getParentDescriptions(): List<SpaceParentInfo> {
return CurrentStateEventEntity.whereType(realm, roomId, EventType.STATE_SPACE_PARENT) return CurrentStateEventEntity.whereType(realm, roomId, EventType.STATE_SPACE_PARENT)
.findAll() .findAll()
// .also {
// Timber.v("## Space: Found ${it.count()} m.space.parent state events for $roomId")
// }
.mapNotNull { .mapNotNull {
ContentMapper.map(it.root?.content).toModel<SpaceParentContent>()?.let { scc -> ContentMapper.map(it.root?.content).toModel<SpaceParentContent>()?.let { spaceParentContent ->
// Timber.v("## Space parent desc state event $scc")
// Parent where via is not present are ignored. // Parent where via is not present are ignored.
scc.via?.let { via -> spaceParentContent.via?.let { via ->
SpaceParentInfo( SpaceParentInfo(
roomId = it.stateKey, roomId = it.stateKey,
canonical = scc.canonical ?: false, canonical = spaceParentContent.canonical ?: false,
viaServers = via, viaServers = via,
stateEventSender = it.root?.sender ?: "" stateEventSender = it.root?.sender ?: ""
) )

View File

@ -17,6 +17,7 @@
package org.matrix.android.sdk.internal.session.room.summary package org.matrix.android.sdk.internal.session.room.summary
import io.realm.Realm import io.realm.Realm
import io.realm.RealmList
import io.realm.kotlin.createObject import io.realm.kotlin.createObject
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.orFalse
@ -349,39 +350,34 @@ internal class RoomSummaryUpdater @Inject constructor(
} }
val acyclicGraph = graph.withoutEdges(backEdges) val acyclicGraph = graph.withoutEdges(backEdges)
// Timber.v("## SPACES: acyclicGraph $acyclicGraph")
val flattenSpaceParents = acyclicGraph.flattenDestination().map { val flattenSpaceParents = acyclicGraph.flattenDestination().map {
it.key.name to it.value.map { it.name } it.key.name to it.value.map { it.name }
}.toMap() }.toMap()
// Timber.v("## SPACES: flattenSpaceParents ${flattenSpaceParents.map { it.key.name to it.value.map { it.name } }.joinToString("\n") {
// it.first + ": [" + it.second.joinToString(",") + "]"
// }}")
// Timber.v("## SPACES: lookup map ${lookupMap.map { it.key.name to it.value.map { it.name } }.toMap()}")
lookupMap.entries lookupMap.entries
.filter { it.key.roomType == RoomType.SPACE && it.key.membership == Membership.JOIN } .filter { it.key.roomType == RoomType.SPACE && it.key.membership == Membership.JOIN }
.forEach { entry -> .forEach { entry ->
val parent = RoomSummaryEntity.where(realm, entry.key.roomId).findFirst() val parent = RoomSummaryEntity.where(realm, entry.key.roomId).findFirst()
if (parent != null) { if (parent != null) {
// Timber.v("## SPACES: check hierarchy of ${parent.name} id ${parent.roomId}")
// Timber.v("## SPACES: flat known parents of ${parent.name} are ${flattenSpaceParents[parent.roomId]}")
val flattenParentsIds = (flattenSpaceParents[parent.roomId] ?: emptyList()) + listOf(parent.roomId) val flattenParentsIds = (flattenSpaceParents[parent.roomId] ?: emptyList()) + listOf(parent.roomId)
// Timber.v("## SPACES: flatten known parents of children of ${parent.name} are ${flattenParentsIds}")
entry.value.forEach { child -> entry.value.forEach { child ->
RoomSummaryEntity.where(realm, child.roomId).findFirst()?.let { childSum -> RoomSummaryEntity.where(realm, child.roomId).findFirst()?.let { childSum ->
// TODO: Revisit
// Timber.w("## SPACES: ${childSum.name} is ${childSum.roomId} fc: ${childSum.flattenParentIds}") childSum.parents.add(SpaceParentSummaryEntity(
// var allParents = childSum.flattenParentIds ?: "" true,
parent.roomId,
parent,
RealmList()
))
if (childSum.flattenParentIds == null) childSum.flattenParentIds = "" if (childSum.flattenParentIds == null) childSum.flattenParentIds = ""
flattenParentsIds.forEach { flattenParentsIds.forEach {
if (childSum.flattenParentIds?.contains(it) != true) { if (childSum.flattenParentIds?.contains(it) != true) {
childSum.flattenParentIds += "|$it" if (childSum.flattenParentIds?.isEmpty() == false) {
childSum.flattenParentIds += "|"
}
childSum.flattenParentIds += it
} }
} }
// childSum.flattenParentIds = "$allParents|"
// Timber.v("## SPACES: flatten of ${childSum.name} is ${childSum.flattenParentIds}")
} }
} }
} }
@ -411,7 +407,6 @@ internal class RoomSummaryUpdater @Inject constructor(
// we keep real m.child/m.parent relations and add the one for common memberships // we keep real m.child/m.parent relations and add the one for common memberships
dmRoom.flattenParentIds += "|${flattenRelated.joinToString("|")}|" dmRoom.flattenParentIds += "|${flattenRelated.joinToString("|")}|"
} }
// Timber.v("## SPACES: flatten of ${dmRoom.otherMemberIds.joinToString(",")} is ${dmRoom.flattenParentIds}")
} }
// Maybe a good place to count the number of notifications for spaces? // Maybe a good place to count the number of notifications for spaces?

View File

@ -68,7 +68,7 @@ abstract class CollapsableTypedEpoxyController<T> :
} }
override fun buildModels() { override fun buildModels() {
check(isBuildingModels()) { check(isBuildingModels) {
("You cannot call `buildModels` directly. Call `setData` instead to trigger a model " + ("You cannot call `buildModels` directly. Call `setData` instead to trigger a model " +
"refresh with new data.") "refresh with new data.")
} }

View File

@ -287,7 +287,7 @@ class RoomListFragment @Inject constructor(
val contentAdapter = val contentAdapter =
when { when {
section.livePages != null -> { section.livePages != null -> {
pagedControllerFactory.createRoomSummaryPagedController() pagedControllerFactory.createRoomSummaryPagedController(roomListParams.displayMode)
.also { controller -> .also { controller ->
section.livePages.observe(viewLifecycleOwner) { pl -> section.livePages.observe(viewLifecycleOwner) { pl ->
controller.submitList(pl) controller.submitList(pl)

View File

@ -36,6 +36,7 @@ import im.vector.app.core.ui.views.PresenceStateImageView
import im.vector.app.core.ui.views.ShieldImageView import im.vector.app.core.ui.views.ShieldImageView
import im.vector.app.features.displayname.getBestName import im.vector.app.features.displayname.getBestName
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.RoomListDisplayMode
import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.themes.ThemeUtils
import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence import im.vector.lib.core.utils.epoxy.charsequence.EpoxyCharSequence
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
@ -54,6 +55,12 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
@EpoxyAttribute @EpoxyAttribute
lateinit var matrixItem: MatrixItem lateinit var matrixItem: MatrixItem
@EpoxyAttribute
var displayMode: RoomListDisplayMode = RoomListDisplayMode.PEOPLE
@EpoxyAttribute
var spaceName: String? = null
@EpoxyAttribute @EpoxyAttribute
lateinit var lastFormattedEvent: EpoxyCharSequence lateinit var lastFormattedEvent: EpoxyCharSequence
@ -105,7 +112,7 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
} }
holder.titleView.text = matrixItem.getBestName() holder.titleView.text = matrixItem.getBestName()
holder.lastEventTimeView.text = lastEventTime holder.lastEventTimeView.text = lastEventTime
holder.lastEventView.text = lastFormattedEvent.charSequence holder.lastEventView.text = getTextForLastEventView()
holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted)) holder.unreadCounterBadgeView.render(UnreadCounterBadgeView.State(unreadNotificationCount, showHighlighted))
holder.unreadIndentIndicator.isVisible = hasUnreadMessage holder.unreadIndentIndicator.isVisible = hasUnreadMessage
holder.draftView.isVisible = hasDraft holder.draftView.isVisible = hasDraft
@ -119,6 +126,14 @@ abstract class RoomSummaryItem : VectorEpoxyModel<RoomSummaryItem.Holder>() {
holder.roomAvatarPresenceImageView.render(showPresence, userPresence) holder.roomAvatarPresenceImageView.render(showPresence, userPresence)
} }
private fun getTextForLastEventView(): CharSequence {
return if (displayMode == RoomListDisplayMode.FILTERED) {
spaceName.orEmpty() // TODO: handle other cases
} else {
lastFormattedEvent.charSequence
}
}
override fun unbind(holder: Holder) { override fun unbind(holder: Holder) {
holder.rootView.setOnClickListener(null) holder.rootView.setOnClickListener(null)
holder.rootView.setOnLongClickListener(null) holder.rootView.setOnLongClickListener(null)

View File

@ -26,6 +26,7 @@ import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.error.ErrorFormatter import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.RoomListDisplayMode
import im.vector.app.features.home.room.detail.timeline.format.DisplayableEventFormatter import im.vector.app.features.home.room.detail.timeline.format.DisplayableEventFormatter
import im.vector.app.features.home.room.typing.TypingHelper import im.vector.app.features.home.room.typing.TypingHelper
import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
@ -46,13 +47,14 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor
fun create(roomSummary: RoomSummary, fun create(roomSummary: RoomSummary,
roomChangeMembershipStates: Map<String, ChangeMembershipState>, roomChangeMembershipStates: Map<String, ChangeMembershipState>,
selectedRoomIds: Set<String>, selectedRoomIds: Set<String>,
displayMode: RoomListDisplayMode,
listener: RoomListListener?): VectorEpoxyModel<*> { listener: RoomListListener?): VectorEpoxyModel<*> {
return when (roomSummary.membership) { return when (roomSummary.membership) {
Membership.INVITE -> { Membership.INVITE -> {
val changeMembershipState = roomChangeMembershipStates[roomSummary.roomId] ?: ChangeMembershipState.Unknown val changeMembershipState = roomChangeMembershipStates[roomSummary.roomId] ?: ChangeMembershipState.Unknown
createInvitationItem(roomSummary, changeMembershipState, listener) createInvitationItem(roomSummary, changeMembershipState, listener)
} }
else -> createRoomItem(roomSummary, selectedRoomIds, listener?.let { it::onRoomClicked }, listener?.let { it::onRoomLongClicked }) else -> createRoomItem(roomSummary, selectedRoomIds, displayMode, listener?.let { it::onRoomClicked }, listener?.let { it::onRoomLongClicked })
} }
} }
@ -105,6 +107,7 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor
fun createRoomItem( fun createRoomItem(
roomSummary: RoomSummary, roomSummary: RoomSummary,
selectedRoomIds: Set<String>, selectedRoomIds: Set<String>,
displayMode: RoomListDisplayMode,
onClick: ((RoomSummary) -> Unit)?, onClick: ((RoomSummary) -> Unit)?,
onLongClick: ((RoomSummary) -> Boolean)? onLongClick: ((RoomSummary) -> Boolean)?
): VectorEpoxyModel<*> { ): VectorEpoxyModel<*> {
@ -124,6 +127,8 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor
.avatarRenderer(avatarRenderer) .avatarRenderer(avatarRenderer)
// We do not display shield in the room list anymore // We do not display shield in the room list anymore
// .encryptionTrustLevel(roomSummary.roomEncryptionTrustLevel) // .encryptionTrustLevel(roomSummary.roomEncryptionTrustLevel)
.displayMode(displayMode)
.spaceName(roomSummary.spaceParents?.firstOrNull()?.roomSummary?.name.orEmpty())
.isPublic(roomSummary.isPublic) .isPublic(roomSummary.isPublic)
.showPresence(roomSummary.isDirect) .showPresence(roomSummary.isDirect)
.userPresence(roomSummary.directUserPresence) .userPresence(roomSummary.directUserPresence)

View File

@ -16,6 +16,7 @@
package im.vector.app.features.home.room.list package im.vector.app.features.home.room.list
import im.vector.app.features.home.RoomListDisplayMode
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
class RoomSummaryListController( class RoomSummaryListController(
@ -26,7 +27,7 @@ class RoomSummaryListController(
override fun buildModels(data: List<RoomSummary>?) { override fun buildModels(data: List<RoomSummary>?) {
data?.forEach { data?.forEach {
add(roomSummaryItemFactory.create(it, emptyMap(), emptySet(), listener)) add(roomSummaryItemFactory.create(it, emptyMap(), emptySet(), RoomListDisplayMode.ROOMS /* TODO: change */, listener))
} }
} }
} }

View File

@ -19,11 +19,13 @@ package im.vector.app.features.home.room.list
import com.airbnb.epoxy.EpoxyModel import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.paging.PagedListEpoxyController import com.airbnb.epoxy.paging.PagedListEpoxyController
import im.vector.app.core.utils.createUIHandler import im.vector.app.core.utils.createUIHandler
import im.vector.app.features.home.RoomListDisplayMode
import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
class RoomSummaryPagedController( class RoomSummaryPagedController(
private val roomSummaryItemFactory: RoomSummaryItemFactory private val roomSummaryItemFactory: RoomSummaryItemFactory,
private val displayMode: RoomListDisplayMode
) : PagedListEpoxyController<RoomSummary>( ) : PagedListEpoxyController<RoomSummary>(
// Important it must match the PageList builder notify Looper // Important it must match the PageList builder notify Looper
modelBuildingHandler = createUIHandler() modelBuildingHandler = createUIHandler()
@ -57,6 +59,6 @@ class RoomSummaryPagedController(
override fun buildItemModel(currentPosition: Int, item: RoomSummary?): EpoxyModel<*> { override fun buildItemModel(currentPosition: Int, item: RoomSummary?): EpoxyModel<*> {
// for place holder if enabled // for place holder if enabled
item ?: return RoomSummaryItemPlaceHolder_().apply { id(currentPosition) } item ?: return RoomSummaryItemPlaceHolder_().apply { id(currentPosition) }
return roomSummaryItemFactory.create(item, roomChangeMembershipStates.orEmpty(), emptySet(), listener) return roomSummaryItemFactory.create(item, roomChangeMembershipStates.orEmpty(), emptySet(), displayMode, listener)
} }
} }

View File

@ -16,14 +16,15 @@
package im.vector.app.features.home.room.list package im.vector.app.features.home.room.list
import im.vector.app.features.home.RoomListDisplayMode
import javax.inject.Inject import javax.inject.Inject
class RoomSummaryPagedControllerFactory @Inject constructor( class RoomSummaryPagedControllerFactory @Inject constructor(
private val roomSummaryItemFactory: RoomSummaryItemFactory private val roomSummaryItemFactory: RoomSummaryItemFactory
) { ) {
fun createRoomSummaryPagedController(): RoomSummaryPagedController { fun createRoomSummaryPagedController(displayMode: RoomListDisplayMode): RoomSummaryPagedController {
return RoomSummaryPagedController(roomSummaryItemFactory) return RoomSummaryPagedController(roomSummaryItemFactory, displayMode)
} }
fun createRoomSummaryListController(): RoomSummaryListController { fun createRoomSummaryListController(): RoomSummaryListController {

View File

@ -22,6 +22,7 @@ import im.vector.app.R
import im.vector.app.core.epoxy.loadingItem import im.vector.app.core.epoxy.loadingItem
import im.vector.app.core.epoxy.noResultItem import im.vector.app.core.epoxy.noResultItem
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.app.features.home.RoomListDisplayMode
import im.vector.app.features.home.room.list.RoomSummaryItemFactory import im.vector.app.features.home.room.list.RoomSummaryItemFactory
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
import javax.inject.Inject import javax.inject.Inject
@ -53,7 +54,7 @@ class IncomingShareController @Inject constructor(private val roomSummaryItemFac
} else { } else {
roomSummaries.forEach { roomSummary -> roomSummaries.forEach { roomSummary ->
roomSummaryItemFactory roomSummaryItemFactory
.createRoomItem(roomSummary, data.selectedRoomIds, callback?.let { it::onRoomClicked }, callback?.let { it::onRoomLongClicked }) .createRoomItem(roomSummary, data.selectedRoomIds, RoomListDisplayMode.ROOMS /* TODO: Change */, callback?.let { it::onRoomClicked }, callback?.let { it::onRoomLongClicked })
.addTo(this) .addTo(this)
} }
} }

View File

@ -213,7 +213,8 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/roomNameView" app:layout_constraintStart_toStartOf="@id/roomNameView"
app:layout_constraintTop_toBottomOf="@id/roomNameView" app:layout_constraintTop_toBottomOf="@id/roomNameView"
tools:text="Alice is typing…" /> tools:text="Alice is typing…"
tools:visibility="gone" />
<!-- Margin bottom does not work, so I use space --> <!-- Margin bottom does not work, so I use space -->
<Space <Space