Use RoomSummaryQueryParams as per Ganfra's excellent suggestion

This commit is contained in:
Benoit Marty 2020-06-04 14:36:51 +02:00
parent a3fd49499b
commit 1ad77530aa
4 changed files with 20 additions and 22 deletions

View File

@ -56,10 +56,10 @@ class RxSession(private val session: Session) {
}
}
fun liveBreadcrumbs(onlyJoinedRooms: Boolean): Observable<List<RoomSummary>> {
return session.getBreadcrumbsLive(onlyJoinedRooms).asObservable()
fun liveBreadcrumbs(queryParams: RoomSummaryQueryParams): Observable<List<RoomSummary>> {
return session.getBreadcrumbsLive(queryParams).asObservable()
.startWithCallable {
session.getBreadcrumbs(onlyJoinedRooms)
session.getBreadcrumbs(queryParams)
}
}

View File

@ -73,17 +73,17 @@ interface RoomService {
/**
* Get a snapshot list of Breadcrumbs
* @param onlyJoinedRooms set to true to keep only joined rooms, and filter out left rooms
* @param queryParams parameters to query the room summaries. It can be use to keep only joined rooms, for instance.
* @return the immutable list of [RoomSummary]
*/
fun getBreadcrumbs(onlyJoinedRooms: Boolean): List<RoomSummary>
fun getBreadcrumbs(queryParams: RoomSummaryQueryParams): List<RoomSummary>
/**
* Get a live list of Breadcrumbs
* @param onlyJoinedRooms set to true to keep only joined rooms, and filter out left rooms
* @param queryParams parameters to query the room summaries. It can be use to keep only joined rooms, for instance.
* @return the [LiveData] of [RoomSummary]
*/
fun getBreadcrumbsLive(onlyJoinedRooms: Boolean): LiveData<List<RoomSummary>>
fun getBreadcrumbsLive(queryParams: RoomSummaryQueryParams): LiveData<List<RoomSummary>>
/**
* Inform the Matrix SDK that a room is displayed.

View File

@ -22,7 +22,6 @@ import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.session.room.Room
import im.vector.matrix.android.api.session.room.RoomService
import im.vector.matrix.android.api.session.room.RoomSummaryQueryParams
import im.vector.matrix.android.api.session.room.model.Membership
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.matrix.android.api.session.room.model.VersioningState
import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
@ -112,29 +111,22 @@ internal class DefaultRoomService @Inject constructor(
return query
}
override fun getBreadcrumbs(onlyJoinedRooms: Boolean): List<RoomSummary> {
override fun getBreadcrumbs(queryParams: RoomSummaryQueryParams): List<RoomSummary> {
return monarchy.fetchAllMappedSync(
{ breadcrumbsQuery(it, onlyJoinedRooms) },
{ breadcrumbsQuery(it, queryParams) },
{ roomSummaryMapper.map(it) }
)
}
override fun getBreadcrumbsLive(onlyJoinedRooms: Boolean): LiveData<List<RoomSummary>> {
override fun getBreadcrumbsLive(queryParams: RoomSummaryQueryParams): LiveData<List<RoomSummary>> {
return monarchy.findAllMappedWithChanges(
{ breadcrumbsQuery(it, onlyJoinedRooms) },
{ breadcrumbsQuery(it, queryParams) },
{ roomSummaryMapper.map(it) }
)
}
private fun breadcrumbsQuery(realm: Realm, onlyJoinedRooms: Boolean): RealmQuery<RoomSummaryEntity> {
return RoomSummaryEntity.where(realm)
.isNotEmpty(RoomSummaryEntityFields.DISPLAY_NAME)
.notEqualTo(RoomSummaryEntityFields.VERSIONING_STATE_STR, VersioningState.UPGRADED_ROOM_JOINED.name)
.apply {
if (onlyJoinedRooms) {
equalTo(RoomSummaryEntityFields.MEMBERSHIP_STR, Membership.JOIN.name)
}
}
private fun breadcrumbsQuery(realm: Realm, queryParams: RoomSummaryQueryParams): RealmQuery<RoomSummaryEntity> {
return roomSummariesQuery(realm, queryParams)
.greaterThan(RoomSummaryEntityFields.BREADCRUMBS_INDEX, RoomSummary.NOT_IN_BREADCRUMBS)
.sort(RoomSummaryEntityFields.BREADCRUMBS_INDEX)
}

View File

@ -21,7 +21,10 @@ import com.airbnb.mvrx.MvRxViewModelFactory
import com.airbnb.mvrx.ViewModelContext
import com.squareup.inject.assisted.Assisted
import com.squareup.inject.assisted.AssistedInject
import im.vector.matrix.android.api.query.QueryStringValue
import im.vector.matrix.android.api.session.Session
import im.vector.matrix.android.api.session.room.model.Membership
import im.vector.matrix.android.api.session.room.roomSummaryQueryParams
import im.vector.matrix.rx.rx
import im.vector.riotx.core.platform.EmptyAction
import im.vector.riotx.core.platform.EmptyViewEvents
@ -58,7 +61,10 @@ class BreadcrumbsViewModel @AssistedInject constructor(@Assisted initialState: B
private fun observeBreadcrumbs() {
session.rx()
.liveBreadcrumbs(true)
.liveBreadcrumbs(roomSummaryQueryParams {
displayName = QueryStringValue.NoCondition
memberships = listOf(Membership.JOIN)
})
.observeOn(Schedulers.computation())
.execute { asyncBreadcrumbs ->
copy(asyncBreadcrumbs = asyncBreadcrumbs)