Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show low priority rooms in dm #3705

Merged
merged 8 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3463.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add low priority section in DM tab
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ fun spaceSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) =
.build()
}

enum class RoomCategoryFilter {
ONLY_DM,
ONLY_ROOMS,
ALL
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was not used

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh strange, was extracted to a top level class but this did stay...


/**
* 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]
Expand All @@ -59,11 +53,10 @@ data class RoomSummaryQueryParams(
val excludeType: List<String?>?,
val includeType: List<String?>?,
val activeSpaceFilter: ActiveSpaceFilter?,
var activeGroupId: String? = null
val activeGroupId: String? = null
) {

class Builder {

var roomId: QueryStringValue = QueryStringValue.IsNotEmpty
var displayName: QueryStringValue = QueryStringValue.IsNotEmpty
var canonicalAlias: QueryStringValue = QueryStringValue.NoCondition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat

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_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 -> {
RoomCategoryFilter.ALL -> {
// nop
}
}
Expand All @@ -274,15 +274,15 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
query.equalTo(RoomSummaryEntityFields.ROOM_TYPE, it)
}
when (queryParams.roomCategoryFilter) {
RoomCategoryFilter.ONLY_DM -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, true)
RoomCategoryFilter.ONLY_ROOMS -> query.equalTo(RoomSummaryEntityFields.IS_DIRECT, false)
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
RoomCategoryFilter.ALL -> Unit // nop
}

// Timber.w("VAL: activeSpaceId : ${queryParams.activeSpaceId}")
when (queryParams.activeSpaceFilter) {
is ActiveSpaceFilter.ActiveSpace -> {
is ActiveSpaceFilter.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) {
Expand All @@ -300,8 +300,8 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
}
}

if (queryParams.activeGroupId != null) {
query.contains(RoomSummaryEntityFields.GROUP_IDS, queryParams.activeGroupId!!)
queryParams.activeGroupId?.let { activeGroupId ->
query.contains(RoomSummaryEntityFields.GROUP_IDS, activeGroupId)
}
return query
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ import im.vector.app.features.home.RoomListDisplayMode

interface RoomListSectionBuilder {
fun buildSections(mode: RoomListDisplayMode) : List<RoomsSection>

fun dispose()
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import im.vector.app.core.resources.StringProvider
import im.vector.app.features.home.RoomListDisplayMode
import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.invite.showInvites
import io.reactivex.disposables.Disposable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope
import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.RoomTagQueryFilter
import org.matrix.android.sdk.api.session.Session
Expand All @@ -35,24 +34,24 @@ import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.rx.asObservable

class GroupRoomListSectionBuilder(
val session: Session,
val stringProvider: StringProvider,
val viewModelScope: CoroutineScope,
val appStateHandler: AppStateHandler,
class RoomListSectionBuilderGroup(
private val session: Session,
private val stringProvider: StringProvider,
private val appStateHandler: AppStateHandler,
private val autoAcceptInvites: AutoAcceptInvites,
val onDisposable: (Disposable) -> Unit,
val onUdpatable: (UpdatableLivePageResult) -> Unit
private val onUpdatable: (UpdatableLivePageResult) -> Unit
) : RoomListSectionBuilder {

private val disposables = CompositeDisposable()

override fun buildSections(mode: RoomListDisplayMode): List<RoomsSection> {
val activeGroupAwareQueries = mutableListOf<UpdatableLivePageResult>()
val sections = mutableListOf<RoomsSection>()
val actualGroupId = appStateHandler.safeActiveGroupId()

when (mode) {
RoomListDisplayMode.PEOPLE -> {
// 3 sections Invites / Fav / Dms
// 4 sections Invites / Fav / Dms / Low Priority
buildPeopleSections(sections, activeGroupAwareQueries, actualGroupId)
}
RoomListDisplayMode.ROOMS -> {
Expand All @@ -69,7 +68,7 @@ class GroupRoomListSectionBuilder(
val name = stringProvider.getString(R.string.bottom_action_rooms)
session.getFilteredPagedRoomSummariesLive(qpm)
.let { updatableFilterLivePageResult ->
onUdpatable(updatableFilterLivePageResult)
onUpdatable(updatableFilterLivePageResult)
sections.add(RoomsSection(name, updatableFilterLivePageResult.livePagedList))
}
}
Expand All @@ -88,6 +87,7 @@ class GroupRoomListSectionBuilder(
it.activeGroupId = actualGroupId
}
}

addSection(
sections,
activeGroupAwareQueries,
Expand All @@ -111,8 +111,9 @@ class GroupRoomListSectionBuilder(
}
}
}.also {
onDisposable.invoke(it)
disposables.add(it)
}

return sections
}

Expand Down Expand Up @@ -218,7 +219,19 @@ class GroupRoomListSectionBuilder(
) {
it.memberships = listOf(Membership.JOIN)
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
it.roomTagQueryFilter = RoomTagQueryFilter(false, null, null)
it.roomTagQueryFilter = RoomTagQueryFilter(false, false, null)
it.activeGroupId = actualGroupId
}

addSection(
sections,
activeSpaceAwareQueries,
R.string.low_priority_header,
false
) {
it.memberships = listOf(Membership.JOIN)
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
it.roomTagQueryFilter = RoomTagQueryFilter(false, true, null)
it.activeGroupId = actualGroupId
}
}
Expand All @@ -231,7 +244,6 @@ class GroupRoomListSectionBuilder(
withQueryParams(
{ query.invoke(it) },
{ roomQueryParams ->

val name = stringProvider.getString(nameRes)
session.getFilteredPagedRoomSummariesLive(roomQueryParams)
.also {
Expand All @@ -246,8 +258,9 @@ class GroupRoomListSectionBuilder(
?.notificationCount
?.postValue(session.getNotificationCountForRooms(roomQueryParams))
}.also {
onDisposable.invoke(it)
disposables.add(it)
}

sections.add(
RoomsSection(
sectionName = name,
Expand All @@ -267,4 +280,8 @@ class GroupRoomListSectionBuilder(
.build()
.let { block(it) }
}

override fun dispose() {
disposables.dispose()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.invite.showInvites
import im.vector.app.space
import io.reactivex.Observable
import io.reactivex.disposables.Disposable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxkotlin.Observables
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope
Expand All @@ -46,19 +46,20 @@ import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount
import org.matrix.android.sdk.rx.asObservable

class SpaceRoomListSectionBuilder(
val session: Session,
val stringProvider: StringProvider,
val appStateHandler: AppStateHandler,
val viewModelScope: CoroutineScope,
private val suggestedRoomJoiningState: LiveData<Map<String, Async<Unit>>>,
class RoomListSectionBuilderSpace(
private val session: Session,
private val stringProvider: StringProvider,
private val appStateHandler: AppStateHandler,
private val viewModelScope: CoroutineScope,
private val autoAcceptInvites: AutoAcceptInvites,
val onDisposable: (Disposable) -> Unit,
val onUdpatable: (UpdatableLivePageResult) -> Unit,
val onlyOrphansInHome: Boolean = false
private val onUpdatable: (UpdatableLivePageResult) -> Unit,
private val suggestedRoomJoiningState: LiveData<Map<String, Async<Unit>>>,
private val onlyOrphansInHome: Boolean = false
) : RoomListSectionBuilder {

val pagedListConfig = PagedList.Config.Builder()
private val disposables = CompositeDisposable()

private val pagedListConfig = PagedList.Config.Builder()
.setPageSize(10)
.setInitialLoadSizeHint(20)
.setEnablePlaceholders(true)
Expand All @@ -70,12 +71,15 @@ class SpaceRoomListSectionBuilder(
val activeSpaceAwareQueries = mutableListOf<RoomListViewModel.ActiveSpaceQueryUpdater>()
when (mode) {
RoomListDisplayMode.PEOPLE -> {
// 4 sections Invites / Fav / Dms / Low Priority
buildDmSections(sections, activeSpaceAwareQueries)
}
RoomListDisplayMode.ROOMS -> {
// 6 sections invites / Fav / Rooms / Low Priority / Server notice / Suggested rooms
buildRoomsSections(sections, activeSpaceAwareQueries)
}
RoomListDisplayMode.FILTERED -> {
// Used when searching for rooms
withQueryParams(
{
it.memberships = Membership.activeMemberships()
Expand All @@ -84,7 +88,7 @@ class SpaceRoomListSectionBuilder(
val name = stringProvider.getString(R.string.bottom_action_rooms)
session.getFilteredPagedRoomSummariesLive(qpm)
.let { updatableFilterLivePageResult ->
onUdpatable(updatableFilterLivePageResult)
onUpdatable(updatableFilterLivePageResult)
sections.add(RoomsSection(name, updatableFilterLivePageResult.livePagedList))
}
}
Expand Down Expand Up @@ -134,13 +138,14 @@ class SpaceRoomListSectionBuilder(
updater.updateForSpaceId(selectedSpace?.roomId)
}
}.also {
onDisposable.invoke(it)
disposables.add(it)
}

return sections
}

private fun buildRoomsSections(sections: MutableList<RoomsSection>, activeSpaceAwareQueries: MutableList<RoomListViewModel.ActiveSpaceQueryUpdater>) {
private fun buildRoomsSections(sections: MutableList<RoomsSection>,
activeSpaceAwareQueries: MutableList<RoomListViewModel.ActiveSpaceQueryUpdater>) {
if (autoAcceptInvites.showInvites()) {
addSection(
sections = sections,
Expand Down Expand Up @@ -248,7 +253,7 @@ class SpaceRoomListSectionBuilder(
}.subscribe {
liveSuggestedRooms.postValue(it)
}.also {
onDisposable.invoke(it)
disposables.add(it)
}
sections.add(
RoomsSection(
Expand All @@ -259,9 +264,11 @@ class SpaceRoomListSectionBuilder(
)
}

private fun buildDmSections(sections: MutableList<RoomsSection>, activeSpaceAwareQueries: MutableList<RoomListViewModel.ActiveSpaceQueryUpdater>) {
private fun buildDmSections(sections: MutableList<RoomsSection>,
activeSpaceAwareQueries: MutableList<RoomListViewModel.ActiveSpaceQueryUpdater>) {
if (autoAcceptInvites.showInvites()) {
addSection(sections = sections,
addSection(
sections = sections,
activeSpaceUpdaters = activeSpaceAwareQueries,
nameRes = R.string.invitations_header,
notifyOfLocalEcho = true,
Expand All @@ -273,7 +280,8 @@ class SpaceRoomListSectionBuilder(
}
}

addSection(sections,
addSection(
sections,
activeSpaceAwareQueries,
R.string.bottom_action_favourites,
false,
Expand All @@ -284,15 +292,28 @@ class SpaceRoomListSectionBuilder(
it.roomTagQueryFilter = RoomTagQueryFilter(true, null, null)
}

addSection(sections,
addSection(
sections,
activeSpaceAwareQueries,
R.string.bottom_action_people_x,
false,
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL
) {
it.memberships = listOf(Membership.JOIN)
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
it.roomTagQueryFilter = RoomTagQueryFilter(false, null, null)
it.roomTagQueryFilter = RoomTagQueryFilter(false, false, null)
}

addSection(
sections,
activeSpaceAwareQueries,
R.string.low_priority_header,
false,
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL
) {
it.memberships = listOf(Membership.JOIN)
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
it.roomTagQueryFilter = RoomTagQueryFilter(false, true, null)
}
}

Expand All @@ -306,7 +327,6 @@ class SpaceRoomListSectionBuilder(
withQueryParams(
{ query.invoke(it) },
{ roomQueryParams ->

val name = stringProvider.getString(nameRes)
session.getFilteredPagedRoomSummariesLive(
roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()),
Expand Down Expand Up @@ -349,7 +369,6 @@ class SpaceRoomListSectionBuilder(
}
}.livePagedList
.let { livePagedList ->

// use it also as a source to update count
livePagedList.asObservable()
.observeOn(Schedulers.computation())
Expand All @@ -366,7 +385,7 @@ class SpaceRoomListSectionBuilder(
}
)
}.also {
onDisposable.invoke(it)
disposables.add(it)
}

sections.add(
Expand Down Expand Up @@ -410,4 +429,8 @@ class SpaceRoomListSectionBuilder(
RoomListViewModel.SpaceFilterStrategy.NONE -> this
}
}

override fun dispose() {
disposables.dispose()
}
}
Loading