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(
roomSummaryQueryParams {
activeSpaceId = ActiveSpaceFilter.ActiveSpace(spaceId)
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(spaceId)
}
).size

View File

@ -248,7 +248,7 @@ class SpaceHierarchyTest : InstrumentedTest {
Thread.sleep(2_000)
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)
}

View File

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

View File

@ -282,19 +282,19 @@ internal class RoomSummaryDataSource @Inject constructor(@SessionDatabase privat
}
// Timber.w("VAL: activeSpaceId : ${queryParams.activeSpaceId}")
when (queryParams.activeSpaceId) {
when (queryParams.activeSpaceFilter) {
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.activeSpaceId.currentSpaceId == null) {
if (queryParams.activeSpaceFilter.currentSpaceId == null) {
// orphan rooms
query.isNull(RoomSummaryEntityFields.FLATTEN_PARENT_IDS)
} else {
query.contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceId.currentSpaceId)
query.contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceFilter.currentSpaceId)
}
}
is ActiveSpaceFilter.ExcludeSpace -> {
query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceId.spaceId)
query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceFilter.spaceId)
}
else -> {
// nop

View File

@ -166,10 +166,12 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
// TODO!!
}
is RoomGroupingMethod.BySpace -> {
val activeSpaceRoomId = groupingMethod.spaceSummary?.roomId
val dmInvites = session.getRoomSummaries(
roomSummaryQueryParams {
memberships = listOf(Membership.INVITE)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) } ?: ActiveSpaceFilter.None
}
).size
@ -177,6 +179,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
roomSummaryQueryParams {
memberships = listOf(Membership.INVITE)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
}
).size
@ -184,6 +187,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
roomSummaryQueryParams {
memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) } ?: ActiveSpaceFilter.None
}
)
@ -191,7 +195,7 @@ class HomeDetailViewModel @AssistedInject constructor(@Assisted initialState: Ho
roomSummaryQueryParams {
memberships = listOf(Membership.JOIN)
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(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
}, sortOrder = RoomSortOrder.NONE
).asObservable()
.throttleFirst(300, TimeUnit.MILLISECONDS)
@ -87,13 +87,13 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
val counts = session.getNotificationCountForRooms(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
}
)
val invites = session.getRoomSummaries(
roomSummaryQueryParams {
this.memberships = listOf(Membership.INVITE)
this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
}
).size
copy(
@ -129,7 +129,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
val counts = session.getNotificationCountForRooms(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.activeSpaceId = ActiveSpaceFilter.ActiveSpace(null)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
}
)
val rootCounts = session.spaceService().getRootSpaceSummaries()

View File

@ -129,7 +129,7 @@ class SpaceRoomListSectionBuilder(
sections, activeSpaceAwareQueries,
R.string.invitations_header,
true,
RoomListViewModel.SpaceFilterStrategy.NONE
RoomListViewModel.SpaceFilterStrategy.NOT_IF_ALL
) {
it.memberships = listOf(Membership.INVITE)
it.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
@ -259,47 +259,6 @@ class SpaceRoomListSectionBuilder(
it.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
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>,
@ -323,7 +282,7 @@ class SpaceRoomListSectionBuilder(
override fun updateForSpaceId(roomId: String?) {
it.updateQuery {
it.copy(
activeSpaceId = ActiveSpaceFilter.ActiveSpace(roomId)
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
)
}
}
@ -335,13 +294,13 @@ class SpaceRoomListSectionBuilder(
if (roomId != null) {
it.updateQuery {
it.copy(
activeSpaceId = ActiveSpaceFilter.ActiveSpace(roomId)
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
)
}
} else {
it.updateQuery {
it.copy(
activeSpaceId = ActiveSpaceFilter.None
activeSpaceFilter = ActiveSpaceFilter.None
)
}
}
@ -392,7 +351,7 @@ class SpaceRoomListSectionBuilder(
return when (spaceFilter) {
RoomListViewModel.SpaceFilterStrategy.NORMAL -> {
copy(
activeSpaceId = ActiveSpaceFilter.ActiveSpace(currentSpace)
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
)
}
RoomListViewModel.SpaceFilterStrategy.NOT_IF_ALL -> {
@ -400,7 +359,7 @@ class SpaceRoomListSectionBuilder(
this
} else {
copy(
activeSpaceId = ActiveSpaceFilter.ActiveSpace(currentSpace)
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
)
}
}

View File

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

View File

@ -60,7 +60,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
this.memberships = listOf(Membership.JOIN)
this.excludeType = null
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)
},
pagedListConfig = PagedList.Config.Builder()
@ -80,7 +80,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
this.excludeType = listOf(RoomType.SPACE)
this.includeType = null
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)
},
pagedListConfig = PagedList.Config.Builder()