Merge pull request #6143 from vector-im/feature/bma/cleanup_RoomSummaryQueryParams

Cleanup room summary query params
This commit is contained in:
Benoit Marty 2022-05-30 12:22:26 +02:00 committed by GitHub
commit 17ccccc6e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 461 additions and 166 deletions

3
changelog.d/6143.sdk Normal file
View File

@ -0,0 +1,3 @@
Remove `RoomSummaryQueryParams.roomId`. If you need to observe a single room, use the new API `RoomService.getRoomSummaryLive(roomId: String)`
- `ActiveSpaceFilter` has been renamed to `SpaceFilter`
- `RoomCategoryFilter.ALL` has been removed, just pass `null` to not filter on Room category.

View File

@ -45,6 +45,13 @@ import org.matrix.android.sdk.api.util.toOptional
class FlowSession(private val session: Session) { class FlowSession(private val session: Session) {
fun liveRoomSummary(roomId: String): Flow<Optional<RoomSummary>> {
return session.roomService().getRoomSummaryLive(roomId).asFlow()
.startWith(session.coroutineDispatchers.io) {
session.roomService().getRoomSummary(roomId).toOptional()
}
}
fun liveRoomSummaries(queryParams: RoomSummaryQueryParams, sortOrder: RoomSortOrder = RoomSortOrder.NONE): Flow<List<RoomSummary>> { fun liveRoomSummaries(queryParams: RoomSummaryQueryParams, sortOrder: RoomSortOrder = RoomSortOrder.NONE): Flow<List<RoomSummary>> {
return session.roomService().getRoomSummariesLive(queryParams, sortOrder).asFlow() return session.roomService().getRoomSummariesLive(queryParams, sortOrder).asFlow()
.startWith(session.coroutineDispatchers.io) { .startWith(session.coroutineDispatchers.io) {

View File

@ -29,8 +29,8 @@ import org.junit.runner.RunWith
import org.junit.runners.JUnit4 import org.junit.runners.JUnit4
import org.junit.runners.MethodSorters import org.junit.runners.MethodSorters
import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.InstrumentedTest
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toContent
@ -248,7 +248,7 @@ class SpaceHierarchyTest : InstrumentedTest {
Thread.sleep(6_000) Thread.sleep(6_000)
val orphansUpdate = session.roomService().getRoomSummaries(roomSummaryQueryParams { val orphansUpdate = session.roomService().getRoomSummaries(roomSummaryQueryParams {
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null) spaceFilter = SpaceFilter.OrphanRooms
}) })
assertEquals("Unexpected number of orphan rooms ${orphansUpdate.map { it.name }}", 2, orphansUpdate.size) assertEquals("Unexpected number of orphan rooms ${orphansUpdate.map { it.name }}", 2, orphansUpdate.size)
} }

View File

@ -16,6 +16,14 @@
package org.matrix.android.sdk.api package org.matrix.android.sdk.api
/**
* This interface exists to let the implementation provide localized room display name fallback.
* The methods can be called when the room has no name, i.e. its `m.room.name` state event does not exist or
* the name in it is an empty String.
* It allows the SDK to store the room name fallback into the local storage and so let the client do
* queries on the room name.
* *Limitation*: if the locale of the device changes, the methods will not be called again.
*/
interface RoomDisplayNameFallbackProvider { interface RoomDisplayNameFallbackProvider {
fun getNameForRoomInvite(): String fun getNameForRoomInvite(): String
fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List<String>): String fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List<String>): String

View File

@ -1,23 +0,0 @@
/*
* Copyright (c) 2021 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.api.query
sealed class ActiveSpaceFilter {
object None : ActiveSpaceFilter()
data class ActiveSpace(val currentSpaceId: String?) : ActiveSpaceFilter()
data class ExcludeSpace(val spaceId: String) : ActiveSpaceFilter()
}

View File

@ -20,20 +20,52 @@ package org.matrix.android.sdk.api.query
* Basic query language. All these cases are mutually exclusive. * Basic query language. All these cases are mutually exclusive.
*/ */
sealed interface QueryStringValue { sealed interface QueryStringValue {
/**
* No condition, i.e. there will be no test on the tested field.
*/
object NoCondition : QueryStringValue
/**
* The tested field has to be null.
*/
object IsNull : QueryStringValue
/**
* The tested field has to be not null.
*/
object IsNotNull : QueryStringValue
/**
* The tested field has to be empty.
*/
object IsEmpty : QueryStringValue
/**
* The tested field has to not empty.
*/
object IsNotEmpty : QueryStringValue
/**
* Interface to check String content.
*/
sealed interface ContentQueryStringValue : QueryStringValue { sealed interface ContentQueryStringValue : QueryStringValue {
val string: String val string: String
val case: Case val case: Case
} }
object NoCondition : QueryStringValue /**
object IsNull : QueryStringValue * The tested field must match the [string].
object IsNotNull : QueryStringValue */
object IsEmpty : QueryStringValue
object IsNotEmpty : QueryStringValue
data class Equals(override val string: String, override val case: Case = Case.SENSITIVE) : ContentQueryStringValue data class Equals(override val string: String, override val case: Case = Case.SENSITIVE) : ContentQueryStringValue
/**
* The tested field must contain the [string].
*/
data class Contains(override val string: String, override val case: Case = Case.SENSITIVE) : ContentQueryStringValue data class Contains(override val string: String, override val case: Case = Case.SENSITIVE) : ContentQueryStringValue
/**
* Case enum for [ContentQueryStringValue].
*/
enum class Case { enum class Case {
/** /**
* Match query sensitive to case. * Match query sensitive to case.

View File

@ -16,9 +16,23 @@
package org.matrix.android.sdk.api.query package org.matrix.android.sdk.api.query
/**
* To filter by Room category.
* @see [org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams]
*/
enum class RoomCategoryFilter { enum class RoomCategoryFilter {
/**
* Get only the DM, i.e. the rooms referenced in `m.direct` account data.
*/
ONLY_DM, ONLY_DM,
/**
* Get only the Room, not the DM, i.e. the rooms not referenced in `m.direct` account data.
*/
ONLY_ROOMS, ONLY_ROOMS,
/**
* Get the room with non-0 notifications.
*/
ONLY_WITH_NOTIFICATIONS, ONLY_WITH_NOTIFICATIONS,
ALL
} }

View File

@ -16,8 +16,22 @@
package org.matrix.android.sdk.api.query package org.matrix.android.sdk.api.query
/**
* Filter room by their tag.
* @see [org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams]
* @see [org.matrix.android.sdk.api.session.room.model.tag.RoomTag]
*/
data class RoomTagQueryFilter( data class RoomTagQueryFilter(
/**
* Set to true to get the rooms which have the tag "m.favourite".
*/
val isFavorite: Boolean?, val isFavorite: Boolean?,
/**
* Set to true to get the rooms which have the tag "m.lowpriority".
*/
val isLowPriority: Boolean?, val isLowPriority: Boolean?,
val isServerNotice: Boolean? /**
* Set to true to get the rooms which have the tag "m.server_notice".
*/
val isServerNotice: Boolean?,
) )

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2021 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.api.query
/**
* Filter to be used to do room queries regarding the space hierarchy.
* @see [org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams]
*/
sealed interface SpaceFilter {
/**
* Used to get all the rooms that are not in any space.
*/
object OrphanRooms : SpaceFilter
/**
* Used to get all the rooms that have the provided space in their parent hierarchy.
*/
data class ActiveSpace(val spaceId: String) : SpaceFilter
/**
* Used to get all the rooms that do not have the provided space in their parent hierarchy.
*/
data class ExcludeSpace(val spaceId: String) : SpaceFilter
}
/**
* Return a [SpaceFilter.ActiveSpace] if the String is not null, or [SpaceFilter.OrphanRooms].
*/
fun String?.toActiveSpaceOrOrphanRooms(): SpaceFilter = this?.let { SpaceFilter.ActiveSpace(it) } ?: SpaceFilter.OrphanRooms

View File

@ -97,6 +97,12 @@ interface RoomService {
*/ */
fun getRoomSummary(roomIdOrAlias: String): RoomSummary? fun getRoomSummary(roomIdOrAlias: String): RoomSummary?
/**
* A live [RoomSummary] associated with the room with id [roomId].
* You can observe this summary to get dynamic data from this room, even if the room is not joined yet
*/
fun getRoomSummaryLive(roomId: String): LiveData<Optional<RoomSummary>>
/** /**
* Get a snapshot list of room summaries. * Get a snapshot list of room summaries.
* @return the immutable list of [RoomSummary] * @return the immutable list of [RoomSummary]

View File

@ -16,9 +16,28 @@
package org.matrix.android.sdk.api.session.room package org.matrix.android.sdk.api.session.room
/**
* Enum to sort room list.
*/
enum class RoomSortOrder { enum class RoomSortOrder {
/**
* Sort room list by room ascending name.
*/
NAME, NAME,
/**
* Sort room list by room descending last activity.
*/
ACTIVITY, ACTIVITY,
/**
* Sort room list by room priority and last activity: favorite room first, low priority room last,
* then descending last activity.
*/
PRIORITY_AND_ACTIVITY, PRIORITY_AND_ACTIVITY,
/**
* Do not sort room list. Useful if the order does not matter. Order can be indeterminate.
*/
NONE NONE
} }

View File

@ -16,60 +16,99 @@
package org.matrix.android.sdk.api.session.room package org.matrix.android.sdk.api.session.room
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.RoomTagQueryFilter import org.matrix.android.sdk.api.query.RoomTagQueryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomType import org.matrix.android.sdk.api.session.room.model.RoomType
import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams
/**
* Create a [RoomSummaryQueryParams] object, calling [init] with a [RoomSummaryQueryParams.Builder].
*/
fun roomSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = {}): RoomSummaryQueryParams { fun roomSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = {}): RoomSummaryQueryParams {
return RoomSummaryQueryParams.Builder().apply(init).build()
}
fun spaceSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = {}): SpaceSummaryQueryParams {
return RoomSummaryQueryParams.Builder() return RoomSummaryQueryParams.Builder()
.apply(init) .apply(init)
.apply {
includeType = listOf(RoomType.SPACE)
excludeType = null
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
}
.build() .build()
} }
/** /**
* This class can be used to filter room summaries to use with: * Create a [SpaceSummaryQueryParams] object (which is a [RoomSummaryQueryParams]), calling [init] with a [RoomSummaryQueryParams.Builder].
* [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService]. * This is specific for spaces, other filters will be applied after invoking [init]
*/
fun spaceSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = {}): SpaceSummaryQueryParams {
return roomSummaryQueryParams {
init()
includeType = listOf(RoomType.SPACE)
excludeType = null
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
}
}
/**
* This class can be used to filter room summaries to use with [RoomService].
* It provides a [Builder].
* [roomSummaryQueryParams] and [spaceSummaryQueryParams] can also be used to build an instance of this class.
*/ */
data class RoomSummaryQueryParams( data class RoomSummaryQueryParams(
val roomId: QueryStringValue, /**
* Query for the displayName of the room. The display name can be the value of the state event,
* or a value returned by [org.matrix.android.sdk.api.RoomDisplayNameFallbackProvider].
*/
val displayName: QueryStringValue, val displayName: QueryStringValue,
/**
* Query for the canonical alias of the room.
*/
val canonicalAlias: QueryStringValue, val canonicalAlias: QueryStringValue,
/**
* Used to filter room by membership.
*/
val memberships: List<Membership>, val memberships: List<Membership>,
/**
* Used to filter room by room category.
*/
val roomCategoryFilter: RoomCategoryFilter?, val roomCategoryFilter: RoomCategoryFilter?,
/**
* Used to filter room by room tag.
*/
val roomTagQueryFilter: RoomTagQueryFilter?, val roomTagQueryFilter: RoomTagQueryFilter?,
/**
* Used to filter room by room type.
* @see [includeType]
*/
val excludeType: List<String?>?, val excludeType: List<String?>?,
/**
* Used to filter room by room type.
* @see [excludeType]
*/
val includeType: List<String?>?, val includeType: List<String?>?,
val activeSpaceFilter: ActiveSpaceFilter?, /**
* Used to filter room using the current space.
*/
val spaceFilter: SpaceFilter?,
/**
* Used to filter room using the current group.
*/
val activeGroupId: String? = null val activeGroupId: String? = null
) { ) {
/**
* Builder for [RoomSummaryQueryParams].
* [roomSummaryQueryParams] and [spaceSummaryQueryParams] can also be used to build an instance of [RoomSummaryQueryParams].
*/
class Builder { class Builder {
var roomId: QueryStringValue = QueryStringValue.IsNotEmpty var displayName: QueryStringValue = QueryStringValue.NoCondition
var displayName: QueryStringValue = QueryStringValue.IsNotEmpty
var canonicalAlias: QueryStringValue = QueryStringValue.NoCondition var canonicalAlias: QueryStringValue = QueryStringValue.NoCondition
var memberships: List<Membership> = Membership.all() var memberships: List<Membership> = Membership.all()
var roomCategoryFilter: RoomCategoryFilter? = RoomCategoryFilter.ALL var roomCategoryFilter: RoomCategoryFilter? = null
var roomTagQueryFilter: RoomTagQueryFilter? = null var roomTagQueryFilter: RoomTagQueryFilter? = null
var excludeType: List<String?>? = listOf(RoomType.SPACE) var excludeType: List<String?>? = listOf(RoomType.SPACE)
var includeType: List<String?>? = null var includeType: List<String?>? = null
var activeSpaceFilter: ActiveSpaceFilter = ActiveSpaceFilter.None var spaceFilter: SpaceFilter? = null
var activeGroupId: String? = null var activeGroupId: String? = null
fun build() = RoomSummaryQueryParams( fun build() = RoomSummaryQueryParams(
roomId = roomId,
displayName = displayName, displayName = displayName,
canonicalAlias = canonicalAlias, canonicalAlias = canonicalAlias,
memberships = memberships, memberships = memberships,
@ -77,7 +116,7 @@ data class RoomSummaryQueryParams(
roomTagQueryFilter = roomTagQueryFilter, roomTagQueryFilter = roomTagQueryFilter,
excludeType = excludeType, excludeType = excludeType,
includeType = includeType, includeType = includeType,
activeSpaceFilter = activeSpaceFilter, spaceFilter = spaceFilter,
activeGroupId = activeGroupId activeGroupId = activeGroupId
) )
} }

View File

@ -28,66 +28,200 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
* It can be retrieved by [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService] * It can be retrieved by [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService]
*/ */
data class RoomSummary( data class RoomSummary(
/**
* The roomId of the room.
*/
val roomId: String, val roomId: String,
// Computed display name /**
* Computed display name. The value of the state event `m.room.name` if not empty, else can be the value returned
* by [org.matrix.android.sdk.api.RoomDisplayNameFallbackProvider].
*/
val displayName: String = "", val displayName: String = "",
/**
* The value of the live state event `m.room.name`.
*/
val name: String = "", val name: String = "",
/**
* The value of the live state event `m.room.topic`.
*/
val topic: String = "", val topic: String = "",
/**
* The value of the live state event `m.room.avatar`.
*/
val avatarUrl: String = "", val avatarUrl: String = "",
/**
* The value of the live state event `m.room.canonical_alias`.
*/
val canonicalAlias: String? = null, val canonicalAlias: String? = null,
/**
* The list of all the aliases of this room. Content of the live state event `m.room.aliases`.
*/
val aliases: List<String> = emptyList(), val aliases: List<String> = emptyList(),
/**
* The value of the live state event `m.room.join_rules`.
*/
val joinRules: RoomJoinRules? = null, val joinRules: RoomJoinRules? = null,
/**
* True is this room is referenced in the account data `m.direct`.
*/
val isDirect: Boolean = false, val isDirect: Boolean = false,
/**
* If [isDirect] is true, this is the id of the first other member of this room.
*/
val directUserId: String? = null, val directUserId: String? = null,
/**
* If [isDirect] is true, this it the presence of the first other member of this room.
*/
val directUserPresence: UserPresence? = null, val directUserPresence: UserPresence? = null,
/**
* Number of members who have joined this room.
*/
val joinedMembersCount: Int? = 0, val joinedMembersCount: Int? = 0,
/**
* Number of members who are invited to this room.
*/
val invitedMembersCount: Int? = 0, val invitedMembersCount: Int? = 0,
/**
* Latest [TimelineEvent] which can be displayed in this room. Can be used in the room list.
*/
val latestPreviewableEvent: TimelineEvent? = null, val latestPreviewableEvent: TimelineEvent? = null,
/**
* List of other member ids of this room.
*/
val otherMemberIds: List<String> = emptyList(), val otherMemberIds: List<String> = emptyList(),
/**
* Number of unread message in this room.
*/
val notificationCount: Int = 0, val notificationCount: Int = 0,
/**
* Number of unread and highlighted message in this room.
*/
val highlightCount: Int = 0, val highlightCount: Int = 0,
/**
* True if this room has unread messages.
*/
val hasUnreadMessages: Boolean = false, val hasUnreadMessages: Boolean = false,
/**
* List of tags in this room.
*/
val tags: List<RoomTag> = emptyList(), val tags: List<RoomTag> = emptyList(),
/**
* Current user membership in this room.
*/
val membership: Membership = Membership.NONE, val membership: Membership = Membership.NONE,
/**
* Versioning state of this room.
*/
val versioningState: VersioningState = VersioningState.NONE, val versioningState: VersioningState = VersioningState.NONE,
/**
* Value of `m.fully_read` for this room.
*/
val readMarkerId: String? = null, val readMarkerId: String? = null,
/**
* Message saved as draft for this room.
*/
val userDrafts: List<UserDraft> = emptyList(), val userDrafts: List<UserDraft> = emptyList(),
/**
* True if this room is encrypted.
*/
val isEncrypted: Boolean, val isEncrypted: Boolean,
/**
* Timestamp of the `m.room.encryption` state event.
*/
val encryptionEventTs: Long?, val encryptionEventTs: Long?,
/**
* List of users who are currently typing on this room.
*/
val typingUsers: List<SenderInfo>, val typingUsers: List<SenderInfo>,
/**
* UserId of the user who has invited the current user to this room.
*/
val inviterId: String? = null, val inviterId: String? = null,
/**
* Breadcrumb index, util to sort rooms by last seen.
*/
val breadcrumbsIndex: Int = NOT_IN_BREADCRUMBS, val breadcrumbsIndex: Int = NOT_IN_BREADCRUMBS,
/**
* The room encryption trust level.
* @see [RoomEncryptionTrustLevel]
*/
val roomEncryptionTrustLevel: RoomEncryptionTrustLevel? = null, val roomEncryptionTrustLevel: RoomEncryptionTrustLevel? = null,
/**
* True if a message has not been sent in this room.
*/
val hasFailedSending: Boolean = false, val hasFailedSending: Boolean = false,
/**
* The type of the room. Null for regular room.
* @see [RoomType]
*/
val roomType: String? = null, val roomType: String? = null,
/**
* List of parent spaces.
*/
val spaceParents: List<SpaceParentInfo>? = null, val spaceParents: List<SpaceParentInfo>? = null,
/**
* List of children space.
*/
val spaceChildren: List<SpaceChildInfo>? = null, val spaceChildren: List<SpaceChildInfo>? = null,
/**
* List of all the space parents. Will be empty by default, you have to explicitly request it.
*/
val flattenParents: List<RoomSummary> = emptyList(), val flattenParents: List<RoomSummary> = emptyList(),
/**
* List of all the space parent Ids.
*/
val flattenParentIds: List<String> = emptyList(), val flattenParentIds: List<String> = emptyList(),
val roomEncryptionAlgorithm: RoomEncryptionAlgorithm? = null /**
* Information about the encryption algorithm, if this room is encrypted.
*/
val roomEncryptionAlgorithm: RoomEncryptionAlgorithm? = null,
) { ) {
/**
* True if [versioningState] is not [VersioningState.NONE].
*/
val isVersioned: Boolean val isVersioned: Boolean
get() = versioningState != VersioningState.NONE get() = versioningState != VersioningState.NONE
/**
* True if [notificationCount] is not `0`.
*/
val hasNewMessages: Boolean val hasNewMessages: Boolean
get() = notificationCount != 0 get() = notificationCount != 0
/**
* True if the room has the tag `m.lowpriority`.
*/
val isLowPriority: Boolean val isLowPriority: Boolean
get() = hasTag(RoomTag.ROOM_TAG_LOW_PRIORITY) get() = hasTag(RoomTag.ROOM_TAG_LOW_PRIORITY)
/**
* True if the room has the tag `m.favourite`.
*/
val isFavorite: Boolean val isFavorite: Boolean
get() = hasTag(RoomTag.ROOM_TAG_FAVOURITE) get() = hasTag(RoomTag.ROOM_TAG_FAVOURITE)
/**
* True if [joinRules] is [RoomJoinRules.PUBLIC].
*/
val isPublic: Boolean val isPublic: Boolean
get() = joinRules == RoomJoinRules.PUBLIC get() = joinRules == RoomJoinRules.PUBLIC
/**
* Test if the room has the provided [tag].
*/
fun hasTag(tag: String) = tags.any { it.name == tag } fun hasTag(tag: String) = tags.any { it.name == tag }
/**
* True if a 1-1 call can be started, i.e. the room has exactly 2 joined members.
*/
val canStartCall: Boolean val canStartCall: Boolean
get() = joinedMembersCount == 2 get() = joinedMembersCount == 2
companion object { companion object {
/**
* Constant to indicated that the room is not on the breadcrumbs.
* Used by [breadcrumbsIndex].
*/
const val NOT_IN_BREADCRUMBS = -1 const val NOT_IN_BREADCRUMBS = -1
} }
} }

View File

@ -16,8 +16,22 @@
package org.matrix.android.sdk.api.session.room.model package org.matrix.android.sdk.api.session.room.model
/**
* Enum for the versioning state of a room.
*/
enum class VersioningState { enum class VersioningState {
/**
* The room is not versioned.
*/
NONE, NONE,
/**
* The room has been upgraded, but the new room is not joined yet.
*/
UPGRADED_ROOM_NOT_JOINED, UPGRADED_ROOM_NOT_JOINED,
UPGRADED_ROOM_JOINED
/**
* The room has been upgraded, and the new room has been joined.
*/
UPGRADED_ROOM_JOINED,
} }

View File

@ -20,7 +20,6 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations import androidx.lifecycle.Transformations
import androidx.paging.PagedList import androidx.paging.PagedList
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.session.events.model.Event import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.identity.model.SignInvitationResult import org.matrix.android.sdk.api.session.identity.model.SignInvitationResult
import org.matrix.android.sdk.api.session.room.Room import org.matrix.android.sdk.api.session.room.Room
@ -91,18 +90,25 @@ internal class DefaultRoomService @Inject constructor(
return roomSummaryDataSource.getRoomSummary(roomIdOrAlias) return roomSummaryDataSource.getRoomSummary(roomIdOrAlias)
} }
override fun getRoomSummaryLive(roomId: String): LiveData<Optional<RoomSummary>> {
return roomSummaryDataSource.getRoomSummaryLive(roomId)
}
override fun getRoomSummaries(queryParams: RoomSummaryQueryParams, override fun getRoomSummaries(queryParams: RoomSummaryQueryParams,
sortOrder: RoomSortOrder): List<RoomSummary> { sortOrder: RoomSortOrder): List<RoomSummary> {
return roomSummaryDataSource.getRoomSummaries(queryParams, sortOrder) return roomSummaryDataSource.getRoomSummaries(queryParams, sortOrder)
} }
override fun refreshJoinedRoomSummaryPreviews(roomId: String?) { override fun refreshJoinedRoomSummaryPreviews(roomId: String?) {
val roomSummaries = getRoomSummaries(roomSummaryQueryParams { val roomSummaries = if (roomId == null) {
if (roomId != null) { getRoomSummaries(roomSummaryQueryParams {
this.roomId = QueryStringValue.Equals(roomId) memberships = listOf(Membership.JOIN)
} })
memberships = listOf(Membership.JOIN) } else {
}) listOfNotNull(
getRoomSummary(roomId)?.takeIf { it.membership == Membership.JOIN }
)
}
if (roomSummaries.isNotEmpty()) { if (roomSummaries.isNotEmpty()) {
monarchy.runTransactionSync { realm -> monarchy.runTransactionSync { realm ->

View File

@ -26,8 +26,9 @@ import com.zhuinden.monarchy.Monarchy
import io.realm.Realm import io.realm.Realm
import io.realm.RealmQuery import io.realm.RealmQuery
import io.realm.kotlin.where import io.realm.kotlin.where
import org.matrix.android.sdk.api.query.ActiveSpaceFilter import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.query.isNormalized import org.matrix.android.sdk.api.query.isNormalized
import org.matrix.android.sdk.api.session.room.ResultBoundaries import org.matrix.android.sdk.api.session.room.ResultBoundaries
import org.matrix.android.sdk.api.session.room.RoomSortOrder import org.matrix.android.sdk.api.session.room.RoomSortOrder
@ -266,29 +267,13 @@ internal class RoomSummaryDataSource @Inject constructor(
private fun roomSummariesQuery(realm: Realm, queryParams: RoomSummaryQueryParams): RealmQuery<RoomSummaryEntity> { private fun roomSummariesQuery(realm: Realm, queryParams: RoomSummaryQueryParams): RealmQuery<RoomSummaryEntity> {
val query = with(queryStringValueProcessor) { val query = with(queryStringValueProcessor) {
RoomSummaryEntity.where(realm) RoomSummaryEntity.where(realm)
.process(RoomSummaryEntityFields.ROOM_ID, queryParams.roomId) .process(RoomSummaryEntityFields.ROOM_ID, QueryStringValue.IsNotEmpty)
.let { .process(queryParams.displayName.toDisplayNameField(), queryParams.displayName)
if (queryParams.displayName.isNormalized()) {
it.process(RoomSummaryEntityFields.NORMALIZED_DISPLAY_NAME, queryParams.displayName)
} else {
it.process(RoomSummaryEntityFields.DISPLAY_NAME, queryParams.displayName)
}
}
.process(RoomSummaryEntityFields.CANONICAL_ALIAS, queryParams.canonicalAlias) .process(RoomSummaryEntityFields.CANONICAL_ALIAS, queryParams.canonicalAlias)
.process(RoomSummaryEntityFields.MEMBERSHIP_STR, queryParams.memberships) .process(RoomSummaryEntityFields.MEMBERSHIP_STR, queryParams.memberships)
.equalTo(RoomSummaryEntityFields.IS_HIDDEN_FROM_USER, false) .equalTo(RoomSummaryEntityFields.IS_HIDDEN_FROM_USER, false)
} }
queryParams.roomCategoryFilter?.let {
when (it) {
RoomCategoryFilter.ONLY_DM -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
RoomCategoryFilter.ONLY_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false)
RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS -> query.greaterThan(RoomSummaryEntityFields.NOTIFICATION_COUNT, 0)
RoomCategoryFilter.ALL -> {
// nop
}
}
}
queryParams.roomTagQueryFilter?.let { queryParams.roomTagQueryFilter?.let {
it.isFavorite?.let { fav -> it.isFavorite?.let { fav ->
query.equalTo(RoomSummaryEntityFields.IS_FAVOURITE, fav) query.equalTo(RoomSummaryEntityFields.IS_FAVOURITE, fav)
@ -311,28 +296,24 @@ internal class RoomSummaryDataSource @Inject constructor(
RoomCategoryFilter.ONLY_DM -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, true) RoomCategoryFilter.ONLY_DM -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
RoomCategoryFilter.ONLY_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false) RoomCategoryFilter.ONLY_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false)
RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS -> query.greaterThan(RoomSummaryEntityFields.NOTIFICATION_COUNT, 0) RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS -> query.greaterThan(RoomSummaryEntityFields.NOTIFICATION_COUNT, 0)
RoomCategoryFilter.ALL -> Unit // nop
null -> Unit null -> Unit
} }
// Timber.w("VAL: activeSpaceId : ${queryParams.activeSpaceId}") // Timber.w("VAL: activeSpaceId : ${queryParams.activeSpaceId}")
when (queryParams.activeSpaceFilter) { when (queryParams.spaceFilter) {
is ActiveSpaceFilter.ActiveSpace -> { SpaceFilter.OrphanRooms -> {
// orphan rooms
query.isNull(RoomSummaryEntityFields.FLATTEN_PARENT_IDS)
}
is SpaceFilter.ActiveSpace -> {
// It's annoying but for now realm java does not support querying in primitive list :/ // It's annoying but for now realm java does not support querying in primitive list :/
// https://github.com/realm/realm-java/issues/5361 // https://github.com/realm/realm-java/issues/5361
if (queryParams.activeSpaceFilter.currentSpaceId == null) { query.contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.spaceFilter.spaceId)
// orphan rooms
query.isNull(RoomSummaryEntityFields.FLATTEN_PARENT_IDS)
} else {
query.contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceFilter.currentSpaceId)
}
} }
is ActiveSpaceFilter.ExcludeSpace -> { is SpaceFilter.ExcludeSpace -> {
query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceFilter.spaceId) query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.spaceFilter.spaceId)
}
else -> {
// nop
} }
null -> Unit // nop
} }
queryParams.activeGroupId?.let { activeGroupId -> queryParams.activeGroupId?.let { activeGroupId ->
@ -341,6 +322,14 @@ internal class RoomSummaryDataSource @Inject constructor(
return query return query
} }
private fun QueryStringValue.toDisplayNameField(): String {
return if (isNormalized()) {
RoomSummaryEntityFields.NORMALIZED_DISPLAY_NAME
} else {
RoomSummaryEntityFields.DISPLAY_NAME
}
}
fun getAllRoomSummaryChildOf(spaceAliasOrId: String, memberShips: List<Membership>): List<RoomSummary> { fun getAllRoomSummaryChildOf(spaceAliasOrId: String, memberShips: List<Membership>): List<RoomSummary> {
val space = getSpaceSummary(spaceAliasOrId) ?: return emptyList() val space = getSpaceSummary(spaceAliasOrId) ?: return emptyList()
val result = ArrayList<RoomSummary>() val result = ArrayList<RoomSummary>()

View File

@ -45,8 +45,9 @@ import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.crypto.NewSessionListener import org.matrix.android.sdk.api.session.crypto.NewSessionListener
import org.matrix.android.sdk.api.session.initsync.SyncStatusService import org.matrix.android.sdk.api.session.initsync.SyncStatusService
@ -241,7 +242,7 @@ class HomeDetailViewModel @AssistedInject constructor(
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.INVITE) memberships = listOf(Membership.INVITE)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM roomCategoryFilter = RoomCategoryFilter.ONLY_DM
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) } ?: ActiveSpaceFilter.None spaceFilter = activeSpaceRoomId?.let { SpaceFilter.ActiveSpace(it) }
} }
).size ).size
@ -249,7 +250,7 @@ class HomeDetailViewModel @AssistedInject constructor(
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.INVITE) memberships = listOf(Membership.INVITE)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId) spaceFilter = groupingMethod.toActiveSpaceOrOrphanRooms()
} }
).size ).size
} }
@ -258,7 +259,7 @@ class HomeDetailViewModel @AssistedInject constructor(
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.JOIN) memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM roomCategoryFilter = RoomCategoryFilter.ONLY_DM
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) } ?: ActiveSpaceFilter.None spaceFilter = activeSpaceRoomId?.let { SpaceFilter.ActiveSpace(it) }
} }
) )
@ -266,7 +267,7 @@ class HomeDetailViewModel @AssistedInject constructor(
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.JOIN) memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId) spaceFilter = groupingMethod.toActiveSpaceOrOrphanRooms()
} }
) )
@ -287,4 +288,8 @@ class HomeDetailViewModel @AssistedInject constructor(
} }
.launchIn(viewModelScope) .launchIn(viewModelScope)
} }
private fun RoomGroupingMethod.BySpace.toActiveSpaceOrOrphanRooms(): SpaceFilter? {
return spaceSummary?.roomId?.toActiveSpaceOrOrphanRooms()
}
} }

View File

@ -37,7 +37,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.flowOn
import org.matrix.android.sdk.api.query.ActiveSpaceFilter import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.RoomSortOrder import org.matrix.android.sdk.api.session.room.RoomSortOrder
import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.Membership
@ -74,11 +74,10 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
private val roomService = session.roomService() private val roomService = session.roomService()
init { init {
roomService.getPagedRoomSummariesLive( roomService.getPagedRoomSummariesLive(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null) this.spaceFilter = SpaceFilter.OrphanRooms
}, sortOrder = RoomSortOrder.NONE }, sortOrder = RoomSortOrder.NONE
).asFlow() ).asFlow()
.throttleFirst(300) .throttleFirst(300)
@ -86,7 +85,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
val counts = roomService.getNotificationCountForRooms( val counts = roomService.getNotificationCountForRooms(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null) this.spaceFilter = SpaceFilter.OrphanRooms
} }
) )
val invites = if (autoAcceptInvites.hideInvites) { val invites = if (autoAcceptInvites.hideInvites) {
@ -95,7 +94,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
roomService.getRoomSummaries( roomService.getRoomSummaries(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.INVITE) this.memberships = listOf(Membership.INVITE)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null) this.spaceFilter = SpaceFilter.OrphanRooms
} }
).size ).size
} }
@ -151,9 +150,9 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
val totalCount = roomService.getNotificationCountForRooms( val totalCount = roomService.getNotificationCountForRooms(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf { this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
!vectorPreferences.prefSpacesShowAllRoomInHome() !vectorPreferences.prefSpacesShowAllRoomInHome()
} ?: ActiveSpaceFilter.None }
} }
) )

View File

@ -38,6 +38,7 @@ import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams
import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult
import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
class RoomListSectionBuilderGroup( class RoomListSectionBuilderGroup(
private val coroutineScope: CoroutineScope, private val coroutineScope: CoroutineScope,
@ -96,7 +97,6 @@ class RoomListSectionBuilderGroup(
true true
) { ) {
it.memberships = listOf(Membership.INVITE) it.memberships = listOf(Membership.INVITE)
it.roomCategoryFilter = RoomCategoryFilter.ALL
it.activeGroupId = actualGroupId it.activeGroupId = actualGroupId
} }
} }
@ -281,9 +281,6 @@ class RoomListSectionBuilderGroup(
} }
private fun withQueryParams(builder: (RoomSummaryQueryParams.Builder) -> Unit, block: (RoomSummaryQueryParams) -> Unit) { private fun withQueryParams(builder: (RoomSummaryQueryParams.Builder) -> Unit, block: (RoomSummaryQueryParams) -> Unit) {
RoomSummaryQueryParams.Builder() block(roomSummaryQueryParams { builder.invoke(this) })
.apply { builder.invoke(this) }
.build()
.let { block(it) }
} }
} }

View File

@ -43,14 +43,16 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.RoomTagQueryFilter import org.matrix.android.sdk.api.query.RoomTagQueryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.getRoomSummary
import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams
import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult
import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount
import timber.log.Timber import timber.log.Timber
@ -297,7 +299,6 @@ class RoomListSectionBuilderSpace(
countRoomAsNotif = true countRoomAsNotif = true
) { ) {
it.memberships = listOf(Membership.INVITE) it.memberships = listOf(Membership.INVITE)
it.roomCategoryFilter = RoomCategoryFilter.ALL
} }
} }
@ -370,7 +371,7 @@ class RoomListSectionBuilderSpace(
activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater { activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater {
override fun updateForSpaceId(roomId: String?) { override fun updateForSpaceId(roomId: String?) {
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId) spaceFilter = roomId?.toActiveSpaceOrOrphanRooms()
) )
liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams } liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams }
} }
@ -381,11 +382,11 @@ class RoomListSectionBuilderSpace(
override fun updateForSpaceId(roomId: String?) { override fun updateForSpaceId(roomId: String?) {
if (roomId != null) { if (roomId != null) {
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId) spaceFilter = SpaceFilter.ActiveSpace(roomId)
) )
} else { } else {
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
activeSpaceFilter = ActiveSpaceFilter.None spaceFilter = null
) )
} }
liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams } liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams }
@ -429,29 +430,20 @@ class RoomListSectionBuilderSpace(
} }
private fun withQueryParams(builder: (RoomSummaryQueryParams.Builder) -> Unit, block: (RoomSummaryQueryParams) -> Unit) { private fun withQueryParams(builder: (RoomSummaryQueryParams.Builder) -> Unit, block: (RoomSummaryQueryParams) -> Unit) {
RoomSummaryQueryParams.Builder() block(roomSummaryQueryParams { builder.invoke(this) })
.apply { builder.invoke(this) }
.build()
.let { block(it) }
} }
internal fun RoomSummaryQueryParams.process(spaceFilter: RoomListViewModel.SpaceFilterStrategy, currentSpace: String?): RoomSummaryQueryParams { internal fun RoomSummaryQueryParams.process(spaceFilter: RoomListViewModel.SpaceFilterStrategy, currentSpace: String?): RoomSummaryQueryParams {
return when (spaceFilter) { return when (spaceFilter) {
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> { RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> {
copy( copy(
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace) spaceFilter = currentSpace?.toActiveSpaceOrOrphanRooms()
) )
} }
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> { RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> {
if (currentSpace == null) { copy(
copy( spaceFilter = currentSpace?.let { SpaceFilter.ActiveSpace(it) }
activeSpaceFilter = ActiveSpaceFilter.None )
)
} else {
copy(
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
)
}
} }
RoomListViewModel.SpaceFilterStrategy.NONE -> this RoomListViewModel.SpaceFilterStrategy.NONE -> this
} }

View File

@ -35,7 +35,6 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.getRoomSummary
import org.matrix.android.sdk.api.session.identity.SharedState import org.matrix.android.sdk.api.session.identity.SharedState
@ -43,8 +42,8 @@ import org.matrix.android.sdk.api.session.identity.ThreePid
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.Membership import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.peeking.PeekResult import org.matrix.android.sdk.api.session.room.peeking.PeekResult
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
import org.matrix.android.sdk.flow.flow import org.matrix.android.sdk.flow.flow
import org.matrix.android.sdk.flow.unwrap
import timber.log.Timber import timber.log.Timber
class RoomPreviewViewModel @AssistedInject constructor( class RoomPreviewViewModel @AssistedInject constructor(
@ -160,24 +159,25 @@ class RoomPreviewViewModel @AssistedInject constructor(
} }
private fun observeRoomSummary() { private fun observeRoomSummary() {
val queryParams = roomSummaryQueryParams {
roomId = QueryStringValue.Equals(initialState.roomId)
excludeType = null
}
session session
.flow() .flow()
.liveRoomSummaries(queryParams) .liveRoomSummary(initialState.roomId)
.onEach { list -> .unwrap()
val isRoomJoined = list.any { .onEach { roomSummary ->
it.membership == Membership.JOIN val isRoomJoined = roomSummary.membership == Membership.JOIN
}
list.firstOrNull { it.roomId == initialState.roomId }?.roomType?.let {
setState {
copy(roomType = it)
}
}
if (isRoomJoined) { if (isRoomJoined) {
setState { copy(roomJoinState = JoinState.JOINED) } setState {
copy(
roomType = roomSummary.roomType,
roomJoinState = JoinState.JOINED
)
}
} else {
setState {
copy(
roomType = roomSummary.roomType
)
}
} }
} }
.launchIn(viewModelScope) .launchIn(viewModelScope)

View File

@ -44,8 +44,8 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.sample import kotlinx.coroutines.flow.sample
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toContent
import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.events.model.toModel
@ -110,9 +110,9 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
session.roomService().getPagedRoomSummariesLive( session.roomService().getPagedRoomSummariesLive(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf { this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
!vectorPreferences.prefSpacesShowAllRoomInHome() !vectorPreferences.prefSpacesShowAllRoomInHome()
} ?: ActiveSpaceFilter.None }
}, sortOrder = RoomSortOrder.NONE }, sortOrder = RoomSortOrder.NONE
).asFlow() ).asFlow()
.sample(300) .sample(300)
@ -127,9 +127,9 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
val totalCount = session.roomService().getNotificationCountForRooms( val totalCount = session.roomService().getNotificationCountForRooms(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf { this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
!vectorPreferences.prefSpacesShowAllRoomInHome() !vectorPreferences.prefSpacesShowAllRoomInHome()
} ?: ActiveSpaceFilter.None }
} }
) )
val counts = RoomAggregateNotificationCount( val counts = RoomAggregateNotificationCount(

View File

@ -34,8 +34,8 @@ import im.vector.app.features.session.coroutineScope
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.getRoom
@ -141,7 +141,7 @@ class SpaceMenuViewModel @AssistedInject constructor(
session.roomService().getRoomSummaries( session.roomService().getRoomSummaries(
roomSummaryQueryParams { roomSummaryQueryParams {
excludeType = null excludeType = null
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(initialState.spaceId) spaceFilter = SpaceFilter.ActiveSpace(initialState.spaceId)
memberships = listOf(Membership.JOIN) memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
} }

View File

@ -33,8 +33,8 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import okhttp3.internal.toImmutableList import okhttp3.internal.toImmutableList
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.events.model.toModel
@ -93,7 +93,7 @@ class SpaceLeaveAdvancedViewModel @AssistedInject constructor(
roomSummaryQueryParams { roomSummaryQueryParams {
includeType = null includeType = null
memberships = listOf(Membership.JOIN) memberships = listOf(Membership.JOIN)
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(initialState.spaceId) spaceFilter = SpaceFilter.ActiveSpace(initialState.spaceId)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
} }
) )

View File

@ -35,9 +35,9 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.getRoomSummary
import org.matrix.android.sdk.api.session.room.RoomSortOrder import org.matrix.android.sdk.api.session.room.RoomSortOrder
@ -72,7 +72,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.excludeType = null this.excludeType = null
this.includeType = listOf(RoomType.SPACE) this.includeType = listOf(RoomType.SPACE)
this.activeSpaceFilter = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId) this.spaceFilter = SpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE) this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
}, },
pagedListConfig = PagedList.Config.Builder() pagedListConfig = PagedList.Config.Builder()
@ -98,7 +98,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
this.excludeType = listOf(RoomType.SPACE) this.excludeType = listOf(RoomType.SPACE)
this.includeType = null this.includeType = null
this.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS this.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
this.activeSpaceFilter = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId) this.spaceFilter = SpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE) this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
}, },
pagedListConfig = PagedList.Config.Builder() pagedListConfig = PagedList.Config.Builder()
@ -124,7 +124,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
this.excludeType = listOf(RoomType.SPACE) this.excludeType = listOf(RoomType.SPACE)
this.includeType = null this.includeType = null
this.roomCategoryFilter = RoomCategoryFilter.ONLY_DM this.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
this.activeSpaceFilter = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId) this.spaceFilter = SpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE) this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
}, },
pagedListConfig = PagedList.Config.Builder() pagedListConfig = PagedList.Config.Builder()
@ -168,9 +168,6 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
override fun handle(action: SpaceAddRoomActions) { override fun handle(action: SpaceAddRoomActions) {
when (action) { when (action) {
is SpaceAddRoomActions.UpdateFilter -> { is SpaceAddRoomActions.UpdateFilter -> {
roomUpdatableLivePageResult.queryParams = roomUpdatableLivePageResult.queryParams.copy(
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
)
roomUpdatableLivePageResult.queryParams = roomUpdatableLivePageResult.queryParams.copy( roomUpdatableLivePageResult.queryParams = roomUpdatableLivePageResult.queryParams.copy(
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE) displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
) )