mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
Merge pull request #3705 from vector-im/feature/bma/low_dm
Show low priority rooms in dm
This commit is contained in:
commit
f5c79baf63
7 changed files with 121 additions and 86 deletions
1
changelog.d/3463.feature
Normal file
1
changelog.d/3463.feature
Normal file
|
@ -0,0 +1 @@
|
|||
Add low priority section in DM tab
|
|
@ -39,12 +39,6 @@ fun spaceSummaryQueryParams(init: (RoomSummaryQueryParams.Builder.() -> Unit) =
|
|||
.build()
|
||||
}
|
||||
|
||||
enum class RoomCategoryFilter {
|
||||
ONLY_DM,
|
||||
ONLY_ROOMS,
|
||||
ALL
|
||||
}
|
||||
|
||||
/**
|
||||
* 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]
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -20,4 +20,6 @@ import im.vector.app.features.home.RoomListDisplayMode
|
|||
|
||||
interface RoomListSectionBuilder {
|
||||
fun buildSections(mode: RoomListDisplayMode) : List<RoomsSection>
|
||||
|
||||
fun dispose()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -35,16 +34,16 @@ 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>()
|
||||
|
@ -52,7 +51,7 @@ class GroupRoomListSectionBuilder(
|
|||
|
||||
when (mode) {
|
||||
RoomListDisplayMode.PEOPLE -> {
|
||||
// 3 sections Invites / Fav / Dms
|
||||
// 4 sections Invites / Fav / Dms / Low Priority
|
||||
buildPeopleSections(sections, activeGroupAwareQueries, actualGroupId)
|
||||
}
|
||||
RoomListDisplayMode.ROOMS -> {
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -88,6 +87,7 @@ class GroupRoomListSectionBuilder(
|
|||
it.activeGroupId = actualGroupId
|
||||
}
|
||||
}
|
||||
|
||||
addSection(
|
||||
sections,
|
||||
activeGroupAwareQueries,
|
||||
|
@ -111,8 +111,9 @@ class GroupRoomListSectionBuilder(
|
|||
}
|
||||
}
|
||||
}.also {
|
||||
onDisposable.invoke(it)
|
||||
disposables.add(it)
|
||||
}
|
||||
|
||||
return sections
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +244,6 @@ class GroupRoomListSectionBuilder(
|
|||
withQueryParams(
|
||||
{ query.invoke(it) },
|
||||
{ roomQueryParams ->
|
||||
|
||||
val name = stringProvider.getString(nameRes)
|
||||
session.getFilteredPagedRoomSummariesLive(roomQueryParams)
|
||||
.also {
|
||||
|
@ -246,8 +258,9 @@ class GroupRoomListSectionBuilder(
|
|||
?.notificationCount
|
||||
?.postValue(session.getNotificationCountForRooms(roomQueryParams))
|
||||
}.also {
|
||||
onDisposable.invoke(it)
|
||||
disposables.add(it)
|
||||
}
|
||||
|
||||
sections.add(
|
||||
RoomsSection(
|
||||
sectionName = name,
|
||||
|
@ -267,4 +280,8 @@ class GroupRoomListSectionBuilder(
|
|||
.build()
|
||||
.let { block(it) }
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
disposables.dispose()
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -248,7 +253,7 @@ class SpaceRoomListSectionBuilder(
|
|||
}.subscribe {
|
||||
liveSuggestedRooms.postValue(it)
|
||||
}.also {
|
||||
onDisposable.invoke(it)
|
||||
disposables.add(it)
|
||||
}
|
||||
sections.add(
|
||||
RoomsSection(
|
||||
|
@ -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,
|
||||
|
@ -273,7 +280,8 @@ class SpaceRoomListSectionBuilder(
|
|||
}
|
||||
}
|
||||
|
||||
addSection(sections,
|
||||
addSection(
|
||||
sections,
|
||||
activeSpaceAwareQueries,
|
||||
R.string.bottom_action_favourites,
|
||||
false,
|
||||
|
@ -284,7 +292,8 @@ class SpaceRoomListSectionBuilder(
|
|||
it.roomTagQueryFilter = RoomTagQueryFilter(true, null, null)
|
||||
}
|
||||
|
||||
addSection(sections,
|
||||
addSection(
|
||||
sections,
|
||||
activeSpaceAwareQueries,
|
||||
R.string.bottom_action_people_x,
|
||||
false,
|
||||
|
@ -292,7 +301,19 @@ class SpaceRoomListSectionBuilder(
|
|||
) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,7 +327,6 @@ class SpaceRoomListSectionBuilder(
|
|||
withQueryParams(
|
||||
{ query.invoke(it) },
|
||||
{ roomQueryParams ->
|
||||
|
||||
val name = stringProvider.getString(nameRes)
|
||||
session.getFilteredPagedRoomSummariesLive(
|
||||
roomQueryParams.process(spaceFilterStrategy, appStateHandler.safeActiveSpaceId()),
|
||||
|
@ -349,7 +369,6 @@ class SpaceRoomListSectionBuilder(
|
|||
}
|
||||
}.livePagedList
|
||||
.let { livePagedList ->
|
||||
|
||||
// use it also as a source to update count
|
||||
livePagedList.asObservable()
|
||||
.observeOn(Schedulers.computation())
|
||||
|
@ -366,7 +385,7 @@ class SpaceRoomListSectionBuilder(
|
|||
}
|
||||
)
|
||||
}.also {
|
||||
onDisposable.invoke(it)
|
||||
disposables.add(it)
|
||||
}
|
||||
|
||||
sections.add(
|
||||
|
@ -410,4 +429,8 @@ class SpaceRoomListSectionBuilder(
|
|||
RoomListViewModel.SpaceFilterStrategy.NONE -> this
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
disposables.dispose()
|
||||
}
|
||||
}
|
|
@ -120,38 +120,32 @@ class RoomListViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
val sections: List<RoomsSection> by lazy {
|
||||
if (appStateHandler.getCurrentRoomGroupingMethod() is RoomGroupingMethod.BySpace) {
|
||||
SpaceRoomListSectionBuilder(
|
||||
private val roomListSectionBuilder = if (appStateHandler.getCurrentRoomGroupingMethod() is RoomGroupingMethod.BySpace) {
|
||||
RoomListSectionBuilderSpace(
|
||||
session,
|
||||
stringProvider,
|
||||
appStateHandler,
|
||||
viewModelScope,
|
||||
autoAcceptInvites,
|
||||
{
|
||||
updatableQuery = it
|
||||
},
|
||||
suggestedRoomJoiningState,
|
||||
autoAcceptInvites,
|
||||
{
|
||||
it.disposeOnClear()
|
||||
},
|
||||
{
|
||||
updatableQuery = it
|
||||
},
|
||||
vectorPreferences.labsSpacesOnlyOrphansInHome()
|
||||
).buildSections(initialState.displayMode)
|
||||
)
|
||||
} else {
|
||||
GroupRoomListSectionBuilder(
|
||||
RoomListSectionBuilderGroup(
|
||||
session,
|
||||
stringProvider,
|
||||
viewModelScope,
|
||||
appStateHandler,
|
||||
autoAcceptInvites,
|
||||
{
|
||||
it.disposeOnClear()
|
||||
},
|
||||
{
|
||||
autoAcceptInvites
|
||||
) {
|
||||
updatableQuery = it
|
||||
}
|
||||
).buildSections(initialState.displayMode)
|
||||
}
|
||||
|
||||
val sections: List<RoomsSection> by lazy {
|
||||
roomListSectionBuilder.buildSections(initialState.displayMode)
|
||||
}
|
||||
|
||||
override fun handle(action: RoomListAction) {
|
||||
|
@ -341,4 +335,9 @@ class RoomListViewModel @Inject constructor(
|
|||
_viewEvents.post(value)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
roomListSectionBuilder.dispose()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue