mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Merge pull request #6143 from vector-im/feature/bma/cleanup_RoomSummaryQueryParams
Cleanup room summary query params
This commit is contained in:
commit
17ccccc6e6
25 changed files with 461 additions and 166 deletions
3
changelog.d/6143.sdk
Normal file
3
changelog.d/6143.sdk
Normal 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.
|
|
@ -45,6 +45,13 @@ import org.matrix.android.sdk.api.util.toOptional
|
|||
|
||||
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>> {
|
||||
return session.roomService().getRoomSummariesLive(queryParams, sortOrder).asFlow()
|
||||
.startWith(session.coroutineDispatchers.io) {
|
||||
|
|
|
@ -29,8 +29,8 @@ import org.junit.runner.RunWith
|
|||
import org.junit.runners.JUnit4
|
||||
import org.junit.runners.MethodSorters
|
||||
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.SpaceFilter
|
||||
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.toContent
|
||||
|
@ -248,7 +248,7 @@ class SpaceHierarchyTest : InstrumentedTest {
|
|||
|
||||
Thread.sleep(6_000)
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,14 @@
|
|||
|
||||
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 {
|
||||
fun getNameForRoomInvite(): String
|
||||
fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List<String>): String
|
||||
|
|
|
@ -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()
|
||||
}
|
|
@ -20,20 +20,52 @@ package org.matrix.android.sdk.api.query
|
|||
* Basic query language. All these cases are mutually exclusive.
|
||||
*/
|
||||
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 {
|
||||
val string: String
|
||||
val case: Case
|
||||
}
|
||||
|
||||
object NoCondition : QueryStringValue
|
||||
object IsNull : QueryStringValue
|
||||
object IsNotNull : QueryStringValue
|
||||
object IsEmpty : QueryStringValue
|
||||
object IsNotEmpty : QueryStringValue
|
||||
|
||||
/**
|
||||
* The tested field must match the [string].
|
||||
*/
|
||||
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
|
||||
|
||||
/**
|
||||
* Case enum for [ContentQueryStringValue].
|
||||
*/
|
||||
enum class Case {
|
||||
/**
|
||||
* Match query sensitive to case.
|
||||
|
|
|
@ -16,9 +16,23 @@
|
|||
|
||||
package org.matrix.android.sdk.api.query
|
||||
|
||||
/**
|
||||
* To filter by Room category.
|
||||
* @see [org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams]
|
||||
*/
|
||||
enum class RoomCategoryFilter {
|
||||
/**
|
||||
* Get only the DM, i.e. the rooms referenced in `m.direct` account data.
|
||||
*/
|
||||
ONLY_DM,
|
||||
|
||||
/**
|
||||
* Get only the Room, not the DM, i.e. the rooms not referenced in `m.direct` account data.
|
||||
*/
|
||||
ONLY_ROOMS,
|
||||
|
||||
/**
|
||||
* Get the room with non-0 notifications.
|
||||
*/
|
||||
ONLY_WITH_NOTIFICATIONS,
|
||||
ALL
|
||||
}
|
||||
|
|
|
@ -16,8 +16,22 @@
|
|||
|
||||
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(
|
||||
/**
|
||||
* Set to true to get the rooms which have the tag "m.favourite".
|
||||
*/
|
||||
val isFavorite: Boolean?,
|
||||
/**
|
||||
* Set to true to get the rooms which have the tag "m.lowpriority".
|
||||
*/
|
||||
val isLowPriority: Boolean?,
|
||||
val isServerNotice: Boolean?
|
||||
/**
|
||||
* Set to true to get the rooms which have the tag "m.server_notice".
|
||||
*/
|
||||
val isServerNotice: Boolean?,
|
||||
)
|
||||
|
|
|
@ -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
|
|
@ -97,6 +97,12 @@ interface RoomService {
|
|||
*/
|
||||
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.
|
||||
* @return the immutable list of [RoomSummary]
|
||||
|
|
|
@ -16,9 +16,28 @@
|
|||
|
||||
package org.matrix.android.sdk.api.session.room
|
||||
|
||||
/**
|
||||
* Enum to sort room list.
|
||||
*/
|
||||
enum class RoomSortOrder {
|
||||
/**
|
||||
* Sort room list by room ascending name.
|
||||
*/
|
||||
NAME,
|
||||
|
||||
/**
|
||||
* Sort room list by room descending last 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,
|
||||
|
||||
/**
|
||||
* Do not sort room list. Useful if the order does not matter. Order can be indeterminate.
|
||||
*/
|
||||
NONE
|
||||
}
|
||||
|
|
|
@ -16,60 +16,99 @@
|
|||
|
||||
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.RoomCategoryFilter
|
||||
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.RoomType
|
||||
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 {
|
||||
return RoomSummaryQueryParams.Builder().apply(init).build()
|
||||
}
|
||||
|
||||
fun spaceSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) = {}): SpaceSummaryQueryParams {
|
||||
return RoomSummaryQueryParams.Builder()
|
||||
.apply(init)
|
||||
.apply {
|
||||
includeType = listOf(RoomType.SPACE)
|
||||
excludeType = null
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||
}
|
||||
.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* This class can be used to filter room summaries to use with:
|
||||
* [org.matrix.android.sdk.api.session.room.Room] and [org.matrix.android.sdk.api.session.room.RoomService].
|
||||
* Create a [SpaceSummaryQueryParams] object (which is a [RoomSummaryQueryParams]), calling [init] with a [RoomSummaryQueryParams.Builder].
|
||||
* 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(
|
||||
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,
|
||||
/**
|
||||
* Query for the canonical alias of the room.
|
||||
*/
|
||||
val canonicalAlias: QueryStringValue,
|
||||
/**
|
||||
* Used to filter room by membership.
|
||||
*/
|
||||
val memberships: List<Membership>,
|
||||
/**
|
||||
* Used to filter room by room category.
|
||||
*/
|
||||
val roomCategoryFilter: RoomCategoryFilter?,
|
||||
/**
|
||||
* Used to filter room by room tag.
|
||||
*/
|
||||
val roomTagQueryFilter: RoomTagQueryFilter?,
|
||||
/**
|
||||
* Used to filter room by room type.
|
||||
* @see [includeType]
|
||||
*/
|
||||
val excludeType: List<String?>?,
|
||||
/**
|
||||
* Used to filter room by room type.
|
||||
* @see [excludeType]
|
||||
*/
|
||||
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
|
||||
) {
|
||||
|
||||
/**
|
||||
* Builder for [RoomSummaryQueryParams].
|
||||
* [roomSummaryQueryParams] and [spaceSummaryQueryParams] can also be used to build an instance of [RoomSummaryQueryParams].
|
||||
*/
|
||||
class Builder {
|
||||
var roomId: QueryStringValue = QueryStringValue.IsNotEmpty
|
||||
var displayName: QueryStringValue = QueryStringValue.IsNotEmpty
|
||||
var displayName: QueryStringValue = QueryStringValue.NoCondition
|
||||
var canonicalAlias: QueryStringValue = QueryStringValue.NoCondition
|
||||
var memberships: List<Membership> = Membership.all()
|
||||
var roomCategoryFilter: RoomCategoryFilter? = RoomCategoryFilter.ALL
|
||||
var roomCategoryFilter: RoomCategoryFilter? = null
|
||||
var roomTagQueryFilter: RoomTagQueryFilter? = null
|
||||
var excludeType: List<String?>? = listOf(RoomType.SPACE)
|
||||
var includeType: List<String?>? = null
|
||||
var activeSpaceFilter: ActiveSpaceFilter = ActiveSpaceFilter.None
|
||||
var spaceFilter: SpaceFilter? = null
|
||||
var activeGroupId: String? = null
|
||||
|
||||
fun build() = RoomSummaryQueryParams(
|
||||
roomId = roomId,
|
||||
displayName = displayName,
|
||||
canonicalAlias = canonicalAlias,
|
||||
memberships = memberships,
|
||||
|
@ -77,7 +116,7 @@ data class RoomSummaryQueryParams(
|
|||
roomTagQueryFilter = roomTagQueryFilter,
|
||||
excludeType = excludeType,
|
||||
includeType = includeType,
|
||||
activeSpaceFilter = activeSpaceFilter,
|
||||
spaceFilter = spaceFilter,
|
||||
activeGroupId = activeGroupId
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
*/
|
||||
data class RoomSummary(
|
||||
/**
|
||||
* The roomId of the room.
|
||||
*/
|
||||
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 = "",
|
||||
/**
|
||||
* The value of the live state event `m.room.name`.
|
||||
*/
|
||||
val name: String = "",
|
||||
/**
|
||||
* The value of the live state event `m.room.topic`.
|
||||
*/
|
||||
val topic: String = "",
|
||||
/**
|
||||
* The value of the live state event `m.room.avatar`.
|
||||
*/
|
||||
val avatarUrl: String = "",
|
||||
/**
|
||||
* The value of the live state event `m.room.canonical_alias`.
|
||||
*/
|
||||
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(),
|
||||
/**
|
||||
* The value of the live state event `m.room.join_rules`.
|
||||
*/
|
||||
val joinRules: RoomJoinRules? = null,
|
||||
/**
|
||||
* True is this room is referenced in the account data `m.direct`.
|
||||
*/
|
||||
val isDirect: Boolean = false,
|
||||
/**
|
||||
* If [isDirect] is true, this is the id of the first other member of this room.
|
||||
*/
|
||||
val directUserId: String? = null,
|
||||
/**
|
||||
* If [isDirect] is true, this it the presence of the first other member of this room.
|
||||
*/
|
||||
val directUserPresence: UserPresence? = null,
|
||||
/**
|
||||
* Number of members who have joined this room.
|
||||
*/
|
||||
val joinedMembersCount: Int? = 0,
|
||||
/**
|
||||
* Number of members who are invited to this room.
|
||||
*/
|
||||
val invitedMembersCount: Int? = 0,
|
||||
/**
|
||||
* Latest [TimelineEvent] which can be displayed in this room. Can be used in the room list.
|
||||
*/
|
||||
val latestPreviewableEvent: TimelineEvent? = null,
|
||||
/**
|
||||
* List of other member ids of this room.
|
||||
*/
|
||||
val otherMemberIds: List<String> = emptyList(),
|
||||
/**
|
||||
* Number of unread message in this room.
|
||||
*/
|
||||
val notificationCount: Int = 0,
|
||||
/**
|
||||
* Number of unread and highlighted message in this room.
|
||||
*/
|
||||
val highlightCount: Int = 0,
|
||||
/**
|
||||
* True if this room has unread messages.
|
||||
*/
|
||||
val hasUnreadMessages: Boolean = false,
|
||||
/**
|
||||
* List of tags in this room.
|
||||
*/
|
||||
val tags: List<RoomTag> = emptyList(),
|
||||
/**
|
||||
* Current user membership in this room.
|
||||
*/
|
||||
val membership: Membership = Membership.NONE,
|
||||
/**
|
||||
* Versioning state of this room.
|
||||
*/
|
||||
val versioningState: VersioningState = VersioningState.NONE,
|
||||
/**
|
||||
* Value of `m.fully_read` for this room.
|
||||
*/
|
||||
val readMarkerId: String? = null,
|
||||
/**
|
||||
* Message saved as draft for this room.
|
||||
*/
|
||||
val userDrafts: List<UserDraft> = emptyList(),
|
||||
/**
|
||||
* True if this room is encrypted.
|
||||
*/
|
||||
val isEncrypted: Boolean,
|
||||
/**
|
||||
* Timestamp of the `m.room.encryption` state event.
|
||||
*/
|
||||
val encryptionEventTs: Long?,
|
||||
/**
|
||||
* List of users who are currently typing on this room.
|
||||
*/
|
||||
val typingUsers: List<SenderInfo>,
|
||||
/**
|
||||
* UserId of the user who has invited the current user to this room.
|
||||
*/
|
||||
val inviterId: String? = null,
|
||||
/**
|
||||
* Breadcrumb index, util to sort rooms by last seen.
|
||||
*/
|
||||
val breadcrumbsIndex: Int = NOT_IN_BREADCRUMBS,
|
||||
/**
|
||||
* The room encryption trust level.
|
||||
* @see [RoomEncryptionTrustLevel]
|
||||
*/
|
||||
val roomEncryptionTrustLevel: RoomEncryptionTrustLevel? = null,
|
||||
/**
|
||||
* True if a message has not been sent in this room.
|
||||
*/
|
||||
val hasFailedSending: Boolean = false,
|
||||
/**
|
||||
* The type of the room. Null for regular room.
|
||||
* @see [RoomType]
|
||||
*/
|
||||
val roomType: String? = null,
|
||||
/**
|
||||
* List of parent spaces.
|
||||
*/
|
||||
val spaceParents: List<SpaceParentInfo>? = null,
|
||||
/**
|
||||
* List of children space.
|
||||
*/
|
||||
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(),
|
||||
/**
|
||||
* List of all the space parent Ids.
|
||||
*/
|
||||
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
|
||||
get() = versioningState != VersioningState.NONE
|
||||
|
||||
/**
|
||||
* True if [notificationCount] is not `0`.
|
||||
*/
|
||||
val hasNewMessages: Boolean
|
||||
get() = notificationCount != 0
|
||||
|
||||
/**
|
||||
* True if the room has the tag `m.lowpriority`.
|
||||
*/
|
||||
val isLowPriority: Boolean
|
||||
get() = hasTag(RoomTag.ROOM_TAG_LOW_PRIORITY)
|
||||
|
||||
/**
|
||||
* True if the room has the tag `m.favourite`.
|
||||
*/
|
||||
val isFavorite: Boolean
|
||||
get() = hasTag(RoomTag.ROOM_TAG_FAVOURITE)
|
||||
|
||||
/**
|
||||
* True if [joinRules] is [RoomJoinRules.PUBLIC].
|
||||
*/
|
||||
val isPublic: Boolean
|
||||
get() = joinRules == RoomJoinRules.PUBLIC
|
||||
|
||||
/**
|
||||
* Test if the room has the provided [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
|
||||
get() = joinedMembersCount == 2
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Constant to indicated that the room is not on the breadcrumbs.
|
||||
* Used by [breadcrumbsIndex].
|
||||
*/
|
||||
const val NOT_IN_BREADCRUMBS = -1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,22 @@
|
|||
|
||||
package org.matrix.android.sdk.api.session.room.model
|
||||
|
||||
/**
|
||||
* Enum for the versioning state of a room.
|
||||
*/
|
||||
enum class VersioningState {
|
||||
/**
|
||||
* The room is not versioned.
|
||||
*/
|
||||
NONE,
|
||||
|
||||
/**
|
||||
* The room has been upgraded, but the new room is not joined yet.
|
||||
*/
|
||||
UPGRADED_ROOM_NOT_JOINED,
|
||||
UPGRADED_ROOM_JOINED
|
||||
|
||||
/**
|
||||
* The room has been upgraded, and the new room has been joined.
|
||||
*/
|
||||
UPGRADED_ROOM_JOINED,
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import androidx.lifecycle.LiveData
|
|||
import androidx.lifecycle.Transformations
|
||||
import androidx.paging.PagedList
|
||||
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.identity.model.SignInvitationResult
|
||||
import org.matrix.android.sdk.api.session.room.Room
|
||||
|
@ -91,18 +90,25 @@ internal class DefaultRoomService @Inject constructor(
|
|||
return roomSummaryDataSource.getRoomSummary(roomIdOrAlias)
|
||||
}
|
||||
|
||||
override fun getRoomSummaryLive(roomId: String): LiveData<Optional<RoomSummary>> {
|
||||
return roomSummaryDataSource.getRoomSummaryLive(roomId)
|
||||
}
|
||||
|
||||
override fun getRoomSummaries(queryParams: RoomSummaryQueryParams,
|
||||
sortOrder: RoomSortOrder): List<RoomSummary> {
|
||||
return roomSummaryDataSource.getRoomSummaries(queryParams, sortOrder)
|
||||
}
|
||||
|
||||
override fun refreshJoinedRoomSummaryPreviews(roomId: String?) {
|
||||
val roomSummaries = getRoomSummaries(roomSummaryQueryParams {
|
||||
if (roomId != null) {
|
||||
this.roomId = QueryStringValue.Equals(roomId)
|
||||
}
|
||||
memberships = listOf(Membership.JOIN)
|
||||
})
|
||||
val roomSummaries = if (roomId == null) {
|
||||
getRoomSummaries(roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.JOIN)
|
||||
})
|
||||
} else {
|
||||
listOfNotNull(
|
||||
getRoomSummary(roomId)?.takeIf { it.membership == Membership.JOIN }
|
||||
)
|
||||
}
|
||||
|
||||
if (roomSummaries.isNotEmpty()) {
|
||||
monarchy.runTransactionSync { realm ->
|
||||
|
|
|
@ -26,8 +26,9 @@ import com.zhuinden.monarchy.Monarchy
|
|||
import io.realm.Realm
|
||||
import io.realm.RealmQuery
|
||||
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.SpaceFilter
|
||||
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.RoomSortOrder
|
||||
|
@ -266,29 +267,13 @@ internal class RoomSummaryDataSource @Inject constructor(
|
|||
private fun roomSummariesQuery(realm: Realm, queryParams: RoomSummaryQueryParams): RealmQuery<RoomSummaryEntity> {
|
||||
val query = with(queryStringValueProcessor) {
|
||||
RoomSummaryEntity.where(realm)
|
||||
.process(RoomSummaryEntityFields.ROOM_ID, queryParams.roomId)
|
||||
.let {
|
||||
if (queryParams.displayName.isNormalized()) {
|
||||
it.process(RoomSummaryEntityFields.NORMALIZED_DISPLAY_NAME, queryParams.displayName)
|
||||
} else {
|
||||
it.process(RoomSummaryEntityFields.DISPLAY_NAME, queryParams.displayName)
|
||||
}
|
||||
}
|
||||
.process(RoomSummaryEntityFields.ROOM_ID, QueryStringValue.IsNotEmpty)
|
||||
.process(queryParams.displayName.toDisplayNameField(), queryParams.displayName)
|
||||
.process(RoomSummaryEntityFields.CANONICAL_ALIAS, queryParams.canonicalAlias)
|
||||
.process(RoomSummaryEntityFields.MEMBERSHIP_STR, queryParams.memberships)
|
||||
.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 {
|
||||
it.isFavorite?.let { 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_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false)
|
||||
RoomCategoryFilter.ONLY_WITH_NOTIFICATIONS -> query.greaterThan(RoomSummaryEntityFields.NOTIFICATION_COUNT, 0)
|
||||
RoomCategoryFilter.ALL -> Unit // nop
|
||||
null -> Unit
|
||||
}
|
||||
|
||||
// Timber.w("VAL: activeSpaceId : ${queryParams.activeSpaceId}")
|
||||
when (queryParams.activeSpaceFilter) {
|
||||
is ActiveSpaceFilter.ActiveSpace -> {
|
||||
when (queryParams.spaceFilter) {
|
||||
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 :/
|
||||
// https://github.com/realm/realm-java/issues/5361
|
||||
if (queryParams.activeSpaceFilter.currentSpaceId == null) {
|
||||
// orphan rooms
|
||||
query.isNull(RoomSummaryEntityFields.FLATTEN_PARENT_IDS)
|
||||
} else {
|
||||
query.contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceFilter.currentSpaceId)
|
||||
}
|
||||
query.contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.spaceFilter.spaceId)
|
||||
}
|
||||
is ActiveSpaceFilter.ExcludeSpace -> {
|
||||
query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceFilter.spaceId)
|
||||
}
|
||||
else -> {
|
||||
// nop
|
||||
is SpaceFilter.ExcludeSpace -> {
|
||||
query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.spaceFilter.spaceId)
|
||||
}
|
||||
null -> Unit // nop
|
||||
}
|
||||
|
||||
queryParams.activeGroupId?.let { activeGroupId ->
|
||||
|
@ -341,6 +322,14 @@ internal class RoomSummaryDataSource @Inject constructor(
|
|||
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> {
|
||||
val space = getSpaceSummary(spaceAliasOrId) ?: return emptyList()
|
||||
val result = ArrayList<RoomSummary>()
|
||||
|
|
|
@ -45,8 +45,9 @@ import kotlinx.coroutines.flow.flatMapLatest
|
|||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
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.SpaceFilter
|
||||
import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.crypto.NewSessionListener
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
|
@ -241,7 +242,7 @@ class HomeDetailViewModel @AssistedInject constructor(
|
|||
roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.INVITE)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
|
||||
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) } ?: ActiveSpaceFilter.None
|
||||
spaceFilter = activeSpaceRoomId?.let { SpaceFilter.ActiveSpace(it) }
|
||||
}
|
||||
).size
|
||||
|
||||
|
@ -249,7 +250,7 @@ class HomeDetailViewModel @AssistedInject constructor(
|
|||
roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.INVITE)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
|
||||
spaceFilter = groupingMethod.toActiveSpaceOrOrphanRooms()
|
||||
}
|
||||
).size
|
||||
}
|
||||
|
@ -258,7 +259,7 @@ class HomeDetailViewModel @AssistedInject constructor(
|
|||
roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.JOIN)
|
||||
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 {
|
||||
memberships = listOf(Membership.JOIN)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
|
||||
spaceFilter = groupingMethod.toActiveSpaceOrOrphanRooms()
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -287,4 +288,8 @@ class HomeDetailViewModel @AssistedInject constructor(
|
|||
}
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
private fun RoomGroupingMethod.BySpace.toActiveSpaceOrOrphanRooms(): SpaceFilter? {
|
||||
return spaceSummary?.roomId?.toActiveSpaceOrOrphanRooms()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ import kotlinx.coroutines.flow.combine
|
|||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
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.room.RoomSortOrder
|
||||
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()
|
||||
|
||||
init {
|
||||
|
||||
roomService.getPagedRoomSummariesLive(
|
||||
roomSummaryQueryParams {
|
||||
this.memberships = listOf(Membership.JOIN)
|
||||
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
|
||||
this.spaceFilter = SpaceFilter.OrphanRooms
|
||||
}, sortOrder = RoomSortOrder.NONE
|
||||
).asFlow()
|
||||
.throttleFirst(300)
|
||||
|
@ -86,7 +85,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
|
|||
val counts = roomService.getNotificationCountForRooms(
|
||||
roomSummaryQueryParams {
|
||||
this.memberships = listOf(Membership.JOIN)
|
||||
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
|
||||
this.spaceFilter = SpaceFilter.OrphanRooms
|
||||
}
|
||||
)
|
||||
val invites = if (autoAcceptInvites.hideInvites) {
|
||||
|
@ -95,7 +94,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
|
|||
roomService.getRoomSummaries(
|
||||
roomSummaryQueryParams {
|
||||
this.memberships = listOf(Membership.INVITE)
|
||||
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
|
||||
this.spaceFilter = SpaceFilter.OrphanRooms
|
||||
}
|
||||
).size
|
||||
}
|
||||
|
@ -151,9 +150,9 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
|
|||
val totalCount = roomService.getNotificationCountForRooms(
|
||||
roomSummaryQueryParams {
|
||||
this.memberships = listOf(Membership.JOIN)
|
||||
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf {
|
||||
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
|
||||
!vectorPreferences.prefSpacesShowAllRoomInHome()
|
||||
} ?: ActiveSpaceFilter.None
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -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.UpdatableLivePageResult
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||
|
||||
class RoomListSectionBuilderGroup(
|
||||
private val coroutineScope: CoroutineScope,
|
||||
|
@ -96,7 +97,6 @@ class RoomListSectionBuilderGroup(
|
|||
true
|
||||
) {
|
||||
it.memberships = listOf(Membership.INVITE)
|
||||
it.roomCategoryFilter = RoomCategoryFilter.ALL
|
||||
it.activeGroupId = actualGroupId
|
||||
}
|
||||
}
|
||||
|
@ -281,9 +281,6 @@ class RoomListSectionBuilderGroup(
|
|||
}
|
||||
|
||||
private fun withQueryParams(builder: (RoomSummaryQueryParams.Builder) -> Unit, block: (RoomSummaryQueryParams) -> Unit) {
|
||||
RoomSummaryQueryParams.Builder()
|
||||
.apply { builder.invoke(this) }
|
||||
.build()
|
||||
.let { block(it) }
|
||||
block(roomSummaryQueryParams { builder.invoke(this) })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,14 +43,16 @@ import kotlinx.coroutines.flow.map
|
|||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.update
|
||||
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.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.getRoomSummary
|
||||
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.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
|
||||
import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount
|
||||
import timber.log.Timber
|
||||
|
||||
|
@ -297,7 +299,6 @@ class RoomListSectionBuilderSpace(
|
|||
countRoomAsNotif = true
|
||||
) {
|
||||
it.memberships = listOf(Membership.INVITE)
|
||||
it.roomCategoryFilter = RoomCategoryFilter.ALL
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -370,7 +371,7 @@ class RoomListSectionBuilderSpace(
|
|||
activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater {
|
||||
override fun updateForSpaceId(roomId: String?) {
|
||||
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
|
||||
spaceFilter = roomId?.toActiveSpaceOrOrphanRooms()
|
||||
)
|
||||
liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams }
|
||||
}
|
||||
|
@ -381,11 +382,11 @@ class RoomListSectionBuilderSpace(
|
|||
override fun updateForSpaceId(roomId: String?) {
|
||||
if (roomId != null) {
|
||||
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
|
||||
spaceFilter = SpaceFilter.ActiveSpace(roomId)
|
||||
)
|
||||
} else {
|
||||
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.None
|
||||
spaceFilter = null
|
||||
)
|
||||
}
|
||||
liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams }
|
||||
|
@ -429,29 +430,20 @@ class RoomListSectionBuilderSpace(
|
|||
}
|
||||
|
||||
private fun withQueryParams(builder: (RoomSummaryQueryParams.Builder) -> Unit, block: (RoomSummaryQueryParams) -> Unit) {
|
||||
RoomSummaryQueryParams.Builder()
|
||||
.apply { builder.invoke(this) }
|
||||
.build()
|
||||
.let { block(it) }
|
||||
block(roomSummaryQueryParams { builder.invoke(this) })
|
||||
}
|
||||
|
||||
internal fun RoomSummaryQueryParams.process(spaceFilter: RoomListViewModel.SpaceFilterStrategy, currentSpace: String?): RoomSummaryQueryParams {
|
||||
return when (spaceFilter) {
|
||||
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> {
|
||||
copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
|
||||
spaceFilter = currentSpace?.toActiveSpaceOrOrphanRooms()
|
||||
)
|
||||
}
|
||||
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> {
|
||||
if (currentSpace == null) {
|
||||
copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.None
|
||||
)
|
||||
} else {
|
||||
copy(
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
|
||||
)
|
||||
}
|
||||
copy(
|
||||
spaceFilter = currentSpace?.let { SpaceFilter.ActiveSpace(it) }
|
||||
)
|
||||
}
|
||||
RoomListViewModel.SpaceFilterStrategy.NONE -> this
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import kotlinx.coroutines.flow.launchIn
|
|||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
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.getRoomSummary
|
||||
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.model.Membership
|
||||
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.unwrap
|
||||
import timber.log.Timber
|
||||
|
||||
class RoomPreviewViewModel @AssistedInject constructor(
|
||||
|
@ -160,24 +159,25 @@ class RoomPreviewViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
private fun observeRoomSummary() {
|
||||
val queryParams = roomSummaryQueryParams {
|
||||
roomId = QueryStringValue.Equals(initialState.roomId)
|
||||
excludeType = null
|
||||
}
|
||||
session
|
||||
.flow()
|
||||
.liveRoomSummaries(queryParams)
|
||||
.onEach { list ->
|
||||
val isRoomJoined = list.any {
|
||||
it.membership == Membership.JOIN
|
||||
}
|
||||
list.firstOrNull { it.roomId == initialState.roomId }?.roomType?.let {
|
||||
setState {
|
||||
copy(roomType = it)
|
||||
}
|
||||
}
|
||||
.liveRoomSummary(initialState.roomId)
|
||||
.unwrap()
|
||||
.onEach { roomSummary ->
|
||||
val isRoomJoined = roomSummary.membership == Membership.JOIN
|
||||
if (isRoomJoined) {
|
||||
setState { copy(roomJoinState = JoinState.JOINED) }
|
||||
setState {
|
||||
copy(
|
||||
roomType = roomSummary.roomType,
|
||||
roomJoinState = JoinState.JOINED
|
||||
)
|
||||
}
|
||||
} else {
|
||||
setState {
|
||||
copy(
|
||||
roomType = roomSummary.roomType
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.launchIn(viewModelScope)
|
||||
|
|
|
@ -44,8 +44,8 @@ import kotlinx.coroutines.flow.onEach
|
|||
import kotlinx.coroutines.flow.sample
|
||||
import kotlinx.coroutines.launch
|
||||
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.SpaceFilter
|
||||
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.toModel
|
||||
|
@ -110,9 +110,9 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
|
|||
session.roomService().getPagedRoomSummariesLive(
|
||||
roomSummaryQueryParams {
|
||||
this.memberships = listOf(Membership.JOIN)
|
||||
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf {
|
||||
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
|
||||
!vectorPreferences.prefSpacesShowAllRoomInHome()
|
||||
} ?: ActiveSpaceFilter.None
|
||||
}
|
||||
}, sortOrder = RoomSortOrder.NONE
|
||||
).asFlow()
|
||||
.sample(300)
|
||||
|
@ -127,9 +127,9 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
|
|||
val totalCount = session.roomService().getNotificationCountForRooms(
|
||||
roomSummaryQueryParams {
|
||||
this.memberships = listOf(Membership.JOIN)
|
||||
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf {
|
||||
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
|
||||
!vectorPreferences.prefSpacesShowAllRoomInHome()
|
||||
} ?: ActiveSpaceFilter.None
|
||||
}
|
||||
}
|
||||
)
|
||||
val counts = RoomAggregateNotificationCount(
|
||||
|
|
|
@ -34,8 +34,8 @@ import im.vector.app.features.session.coroutineScope
|
|||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
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.SpaceFilter
|
||||
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.getRoom
|
||||
|
@ -141,7 +141,7 @@ class SpaceMenuViewModel @AssistedInject constructor(
|
|||
session.roomService().getRoomSummaries(
|
||||
roomSummaryQueryParams {
|
||||
excludeType = null
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(initialState.spaceId)
|
||||
spaceFilter = SpaceFilter.ActiveSpace(initialState.spaceId)
|
||||
memberships = listOf(Membership.JOIN)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ import kotlinx.coroutines.flow.launchIn
|
|||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
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.SpaceFilter
|
||||
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.toModel
|
||||
|
@ -93,7 +93,7 @@ class SpaceLeaveAdvancedViewModel @AssistedInject constructor(
|
|||
roomSummaryQueryParams {
|
||||
includeType = null
|
||||
memberships = listOf(Membership.JOIN)
|
||||
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(initialState.spaceId)
|
||||
spaceFilter = SpaceFilter.ActiveSpace(initialState.spaceId)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||
}
|
||||
)
|
||||
|
|
|
@ -35,9 +35,9 @@ import kotlinx.coroutines.flow.distinctUntilChanged
|
|||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.launch
|
||||
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.RoomCategoryFilter
|
||||
import org.matrix.android.sdk.api.query.SpaceFilter
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.getRoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.RoomSortOrder
|
||||
|
@ -72,7 +72,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
|
|||
this.memberships = listOf(Membership.JOIN)
|
||||
this.excludeType = null
|
||||
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)
|
||||
},
|
||||
pagedListConfig = PagedList.Config.Builder()
|
||||
|
@ -98,7 +98,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
|
|||
this.excludeType = listOf(RoomType.SPACE)
|
||||
this.includeType = null
|
||||
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)
|
||||
},
|
||||
pagedListConfig = PagedList.Config.Builder()
|
||||
|
@ -124,7 +124,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
|
|||
this.excludeType = listOf(RoomType.SPACE)
|
||||
this.includeType = null
|
||||
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)
|
||||
},
|
||||
pagedListConfig = PagedList.Config.Builder()
|
||||
|
@ -168,9 +168,6 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
|
|||
override fun handle(action: SpaceAddRoomActions) {
|
||||
when (action) {
|
||||
is SpaceAddRoomActions.UpdateFilter -> {
|
||||
roomUpdatableLivePageResult.queryParams = roomUpdatableLivePageResult.queryParams.copy(
|
||||
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
|
||||
)
|
||||
roomUpdatableLivePageResult.queryParams = roomUpdatableLivePageResult.queryParams.copy(
|
||||
displayName = QueryStringValue.Contains(action.filter, QueryStringValue.Case.INSENSITIVE)
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue