Merge pull request #7123 from vector-im/bugfix/fre/start_dm_room_list_glitch

Start DM - Fix glitch in the room list
This commit is contained in:
Florian Renaud 2022-09-15 16:55:47 +02:00 committed by GitHub
commit 0ce72057dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 16 deletions

1
changelog.d/7121.wip Normal file
View File

@ -0,0 +1 @@
Create DM room only on first message - Fix glitch in the room list

View File

@ -68,6 +68,11 @@ sealed interface QueryStringValue {
*/
data class Contains(override val string: String, override val case: Case = Case.SENSITIVE) : ContentQueryStringValue
/**
* The tested field must not contain the [string].
*/
data class NotContains(override val string: String, override val case: Case = Case.SENSITIVE) : ContentQueryStringValue
/**
* Case enum for [ContentQueryStringValue].
*/

View File

@ -20,8 +20,10 @@ 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.RoomSummaryQueryParams.Builder
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.localecho.RoomLocalEcho
import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams
/**
@ -52,6 +54,10 @@ fun spaceSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) =
* [roomSummaryQueryParams] and [spaceSummaryQueryParams] can also be used to build an instance of this class.
*/
data class RoomSummaryQueryParams(
/**
* Query for the roomId.
*/
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].
@ -94,6 +100,7 @@ data class RoomSummaryQueryParams(
* [roomSummaryQueryParams] and [spaceSummaryQueryParams] can also be used to build an instance of [RoomSummaryQueryParams].
*/
class Builder {
var roomId: QueryStringValue = QueryStringValue.NotContains(RoomLocalEcho.PREFIX)
var displayName: QueryStringValue = QueryStringValue.NoCondition
var canonicalAlias: QueryStringValue = QueryStringValue.NoCondition
var memberships: List<Membership> = Membership.all()
@ -104,6 +111,7 @@ data class RoomSummaryQueryParams(
var spaceFilter: SpaceFilter = SpaceFilter.NoFilter
fun build() = RoomSummaryQueryParams(
roomId = roomId,
displayName = displayName,
canonicalAlias = canonicalAlias,
memberships = memberships,

View File

@ -20,7 +20,7 @@ import java.util.UUID
object RoomLocalEcho {
private const val PREFIX = "!local."
const val PREFIX = "!local."
/**
* Tell whether the provider room id is a local id.

View File

@ -38,6 +38,7 @@ internal class QueryStringValueProcessor @Inject constructor(
is ContentQueryStringValue -> when (queryStringValue) {
is QueryStringValue.Equals -> equalTo(field, queryStringValue.toRealmValue(), queryStringValue.case.toRealmCase())
is QueryStringValue.Contains -> contains(field, queryStringValue.toRealmValue(), queryStringValue.case.toRealmCase())
is QueryStringValue.NotContains -> not().process(field, QueryStringValue.Contains(queryStringValue.string, queryStringValue.case))
}
}
}

View File

@ -272,6 +272,7 @@ internal class RoomSummaryDataSource @Inject constructor(
val query = with(queryStringValueProcessor) {
RoomSummaryEntity.where(realm)
.process(RoomSummaryEntityFields.ROOM_ID, QueryStringValue.IsNotEmpty)
.process(RoomSummaryEntityFields.ROOM_ID, queryParams.roomId)
.process(queryParams.displayName.toDisplayNameField(), queryParams.displayName)
.process(RoomSummaryEntityFields.CANONICAL_ALIAS, queryParams.canonicalAlias)
.process(RoomSummaryEntityFields.MEMBERSHIP_STR, queryParams.memberships)

View File

@ -47,7 +47,6 @@ import org.matrix.android.sdk.api.session.getRoom
import org.matrix.android.sdk.api.session.getRoomSummary
import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult
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.localecho.RoomLocalEcho
import org.matrix.android.sdk.api.session.room.model.tag.RoomTag
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
@ -127,20 +126,13 @@ class RoomListViewModel @AssistedInject constructor(
}
private fun observeLocalRooms() {
val queryParams = roomSummaryQueryParams {
memberships = listOf(Membership.JOIN)
}
session
.flow()
.liveRoomSummaries(queryParams)
.map { roomSummaries ->
roomSummaries.mapNotNull { summary ->
summary.roomId.takeIf { RoomLocalEcho.isLocalEchoId(it) }
}.toSet()
}
.setOnEach { roomIds ->
copy(localRoomIds = roomIds)
}
.liveRoomSummaries(roomSummaryQueryParams {
roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX)
})
.map { page -> page.map { it.roomId } }
.setOnEach { copy(localRoomIds = it) }
}
companion object : MavericksViewModelFactory<RoomListViewModel, RoomListViewState> by hiltMavericksViewModelFactory()
@ -181,7 +173,7 @@ class RoomListViewModel @AssistedInject constructor(
return session.getRoom(roomId)?.stateService()?.isPublic().orFalse()
}
fun deleteLocalRooms(roomsIds: Set<String>) {
fun deleteLocalRooms(roomsIds: Iterable<String>) {
viewModelScope.launch {
roomsIds.forEach {
session.roomService().deleteLocalRoom(it)

View File

@ -31,7 +31,7 @@ data class RoomListViewState(
val asyncSuggestedRooms: Async<List<SpaceChildInfo>> = Uninitialized,
val currentUserName: String? = null,
val asyncSelectedSpace: Async<RoomSummary?> = Uninitialized,
val localRoomIds: Set<String> = emptySet()
val localRoomIds: List<String> = emptyList()
) : MavericksState {
constructor(args: RoomListParams) : this(displayMode = args.displayMode)