Merge pull request #3283 from vector-im/feature/bca/spaces_fix_notif_filter

Fix unread badges and invite filtering
This commit is contained in:
Benoit Marty 2021-05-06 10:36:09 +02:00 committed by GitHub
commit 89d71ceedc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 65 deletions

View file

@ -210,7 +210,7 @@ class SpaceCreationTest : InstrumentedTest {
val childCount = bobSession.getRoomSummaries( val childCount = bobSession.getRoomSummaries(
roomSummaryQueryParams { roomSummaryQueryParams {
activeSpaceId = ActiveSpaceFilter.ActiveSpace(spaceId) activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(spaceId)
} }
).size ).size

View file

@ -248,7 +248,7 @@ class SpaceHierarchyTest : InstrumentedTest {
Thread.sleep(2_000) Thread.sleep(2_000)
val orphansUpdate = session.getRoomSummaries(roomSummaryQueryParams { val orphansUpdate = session.getRoomSummaries(roomSummaryQueryParams {
activeSpaceId = ActiveSpaceFilter.ActiveSpace(null) activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
}) })
assertEquals("Unexpected number of orphan rooms ${orphansUpdate.map { it.name }}", 2, orphansUpdate.size) assertEquals("Unexpected number of orphan rooms ${orphansUpdate.map { it.name }}", 2, orphansUpdate.size)
} }

View file

@ -58,7 +58,7 @@ data class RoomSummaryQueryParams(
val roomTagQueryFilter: RoomTagQueryFilter?, val roomTagQueryFilter: RoomTagQueryFilter?,
val excludeType: List<String?>?, val excludeType: List<String?>?,
val includeType: List<String?>?, val includeType: List<String?>?,
val activeSpaceId: ActiveSpaceFilter?, val activeSpaceFilter: ActiveSpaceFilter?,
var activeGroupId: String? = null var activeGroupId: String? = null
) { ) {
@ -72,7 +72,7 @@ data class RoomSummaryQueryParams(
var roomTagQueryFilter: RoomTagQueryFilter? = null var roomTagQueryFilter: RoomTagQueryFilter? = null
var excludeType: List<String?>? = listOf(RoomType.SPACE) var excludeType: List<String?>? = listOf(RoomType.SPACE)
var includeType: List<String?>? = null var includeType: List<String?>? = null
var activeSpaceId: ActiveSpaceFilter = ActiveSpaceFilter.None var activeSpaceFilter: ActiveSpaceFilter = ActiveSpaceFilter.None
var activeGroupId: String? = null var activeGroupId: String? = null
fun build() = RoomSummaryQueryParams( fun build() = RoomSummaryQueryParams(
@ -84,7 +84,7 @@ data class RoomSummaryQueryParams(
roomTagQueryFilter = roomTagQueryFilter, roomTagQueryFilter = roomTagQueryFilter,
excludeType = excludeType, excludeType = excludeType,
includeType = includeType, includeType = includeType,
activeSpaceId = activeSpaceId, activeSpaceFilter = activeSpaceFilter,
activeGroupId = activeGroupId activeGroupId = activeGroupId
) )
} }

View file

@ -282,19 +282,19 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
} }
// Timber.w("VAL: activeSpaceId : ${queryParams.activeSpaceId}") // Timber.w("VAL: activeSpaceId : ${queryParams.activeSpaceId}")
when (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 :/ // It's annoying but for now realm java does not support querying in primitive list :/
// https://github.com/realm/realm-java/issues/5361 // https://github.com/realm/realm-java/issues/5361
if (queryParams.activeSpaceId.currentSpaceId == null) { if (queryParams.activeSpaceFilter.currentSpaceId == null) {
// orphan rooms // orphan rooms
query.isNull(RoomSummaryEntityFields.FLATTEN_PARENT_IDS) query.isNull(RoomSummaryEntityFields.FLATTEN_PARENT_IDS)
} else { } else {
query.contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceId.currentSpaceId) query.contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceFilter.currentSpaceId)
} }
} }
is ActiveSpaceFilter.ExcludeSpace -> { is ActiveSpaceFilter.ExcludeSpace -> {
query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceId.spaceId) query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceFilter.spaceId)
} }
else -> { else -> {
// nop // nop

View file

@ -166,10 +166,12 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
// TODO!! // TODO!!
} }
is RoomGroupingMethod.BySpace -> { is RoomGroupingMethod.BySpace -> {
val activeSpaceRoomId = groupingMethod.spaceSummary?.roomId
val dmInvites = session.getRoomSummaries( val dmInvites = session.getRoomSummaries(
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.INVITE) memberships = listOf(Membership.INVITE)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM roomCategoryFilter = RoomCategoryFilter.ONLY_DM
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) } ?: ActiveSpaceFilter.None
} }
).size ).size
@ -177,6 +179,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.INVITE) memberships = listOf(Membership.INVITE)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
} }
).size ).size
@ -184,6 +187,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.JOIN) memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM roomCategoryFilter = RoomCategoryFilter.ONLY_DM
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) } ?: ActiveSpaceFilter.None
} }
) )
@ -191,7 +195,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.JOIN) memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
activeSpaceId = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId) activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
} }
) )

View file

@ -79,7 +79,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
session.getPagedRoomSummariesLive( session.getPagedRoomSummariesLive(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
}, sortOrder = RoomSortOrder.NONE }, sortOrder = RoomSortOrder.NONE
).asObservable() ).asObservable()
.throttleFirst(300, TimeUnit.MILLISECONDS) .throttleFirst(300, TimeUnit.MILLISECONDS)
@ -87,13 +87,13 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
val counts = session.getNotificationCountForRooms( val counts = session.getNotificationCountForRooms(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
} }
) )
val invites = session.getRoomSummaries( val invites = session.getRoomSummaries(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.INVITE) this.memberships = listOf(Membership.INVITE)
this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
} }
).size ).size
copy( copy(
@ -129,7 +129,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
val counts = session.getNotificationCountForRooms( val counts = session.getNotificationCountForRooms(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
} }
) )
val rootCounts = session.spaceService().getRootSpaceSummaries() val rootCounts = session.spaceService().getRootSpaceSummaries()

View file

@ -129,7 +129,7 @@ class SpaceRoomListSectionBuilder(
sections, activeSpaceAwareQueries, sections, activeSpaceAwareQueries,
R.string.invitations_header, R.string.invitations_header,
true, true,
RoomListViewModel.SpaceFilterStrategy.NONE RoomListViewModel.SpaceFilterStrategy.NOT_IF_ALL
) { ) {
it.memberships = listOf(Membership.INVITE) it.memberships = listOf(Membership.INVITE)
it.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS it.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
@ -259,47 +259,6 @@ class SpaceRoomListSectionBuilder(
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
it.roomTagQueryFilter = RoomTagQueryFilter(false, null, null) it.roomTagQueryFilter = RoomTagQueryFilter(false, null, null)
} }
// // For DMs we still need some post query filter :/
// // It's probably less important as home is not filtering at all
// val dmList = MutableLiveData<List<RoomSummary>>()
// Observables.combineLatest(
// session.getRoomSummariesLive(
// roomSummaryQueryParams {
// memberships = listOf(Membership.JOIN)
// roomCategoryFilter = RoomCategoryFilter.ONLY_DM
// }
// ).asObservable(),
// appStateHandler.selectedSpaceDataSource.observe()
//
// ) { rooms, currentSpaceOption ->
// val currentSpace = currentSpaceOption.orNull()
// .takeIf {
// // the +ALL trick is annoying, should find a way to fix that at the source!
// MatrixPatterns.isRoomId(it?.roomId)
// }
// if (currentSpace == null) {
// rooms
// } else {
// rooms.filter {
// it.otherMemberIds
// .intersect(currentSpace.otherMemberIds)
// .isNotEmpty()
// }
// }
// }.subscribe {
// dmList.postValue(it)
// }.also {
// onDisposable.invoke(it)
// }
//
// sections.add(
// RoomsSection(
// sectionName = stringProvider.getString(R.string.bottom_action_people_x),
// liveList = dmList,
// notifyOfLocalEcho = false
// )
// )
} }
private fun addSection(sections: MutableList<RoomsSection>, private fun addSection(sections: MutableList<RoomsSection>,
@ -323,7 +282,7 @@ class SpaceRoomListSectionBuilder(
override fun updateForSpaceId(roomId: String?) { override fun updateForSpaceId(roomId: String?) {
it.updateQuery { it.updateQuery {
it.copy( it.copy(
activeSpaceId = ActiveSpaceFilter.ActiveSpace(roomId) activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
) )
} }
} }
@ -335,13 +294,13 @@ class SpaceRoomListSectionBuilder(
if (roomId != null) { if (roomId != null) {
it.updateQuery { it.updateQuery {
it.copy( it.copy(
activeSpaceId = ActiveSpaceFilter.ActiveSpace(roomId) activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
) )
} }
} else { } else {
it.updateQuery { it.updateQuery {
it.copy( it.copy(
activeSpaceId = ActiveSpaceFilter.None activeSpaceFilter = ActiveSpaceFilter.None
) )
} }
} }
@ -392,7 +351,7 @@ class SpaceRoomListSectionBuilder(
return when (spaceFilter) { return when (spaceFilter) {
RoomListViewModel.SpaceFilterStrategy.NORMAL -> { RoomListViewModel.SpaceFilterStrategy.NORMAL -> {
copy( copy(
activeSpaceId = ActiveSpaceFilter.ActiveSpace(currentSpace) activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
) )
} }
RoomListViewModel.SpaceFilterStrategy.NOT_IF_ALL -> { RoomListViewModel.SpaceFilterStrategy.NOT_IF_ALL -> {
@ -400,7 +359,7 @@ class SpaceRoomListSectionBuilder(
this this
} else { } else {
copy( copy(
activeSpaceId = ActiveSpaceFilter.ActiveSpace(currentSpace) activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
) )
} }
} }

View file

@ -111,7 +111,7 @@ class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: Sp
session.getPagedRoomSummariesLive( session.getPagedRoomSummariesLive(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
}, sortOrder = RoomSortOrder.NONE }, sortOrder = RoomSortOrder.NONE
).asObservable() ).asObservable()
.throttleFirst(300, TimeUnit.MILLISECONDS) .throttleFirst(300, TimeUnit.MILLISECONDS)
@ -120,7 +120,7 @@ class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: Sp
val counts = session.getNotificationCountForRooms( val counts = session.getNotificationCountForRooms(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
} }
) )
setState { setState {

View file

@ -60,7 +60,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.excludeType = null this.excludeType = null
this.includeType = listOf(RoomType.SPACE) this.includeType = listOf(RoomType.SPACE)
this.activeSpaceId = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId) this.activeSpaceFilter = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE) this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
}, },
pagedListConfig = PagedList.Config.Builder() pagedListConfig = PagedList.Config.Builder()
@ -80,7 +80,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
this.excludeType = listOf(RoomType.SPACE) this.excludeType = listOf(RoomType.SPACE)
this.includeType = null this.includeType = null
this.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS this.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
this.activeSpaceId = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId) this.activeSpaceFilter = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE) this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
}, },
pagedListConfig = PagedList.Config.Builder() pagedListConfig = PagedList.Config.Builder()