From 8a8ad868062138d21af91e2dfaf5b9acc6088bf9 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sat, 11 Sep 2021 10:22:23 +0200 Subject: [PATCH] Drawer notif count badge: use total count Upstream decided to only count notifications for other spaces than the currently selected one for the drawer icon. This however leads to notification counts multiplying for rooms present in multiple spaces. Instead, it's more useful to just show the total notification count, without doing any kind of space-based filtering. Fixes https://github.com/SchildiChat/SchildiChat-android/issues/79 Change-Id: I2a76d4fbc768b36470d9183741f57a5f834d374a --- .../home/UnreadMessagesSharedViewModel.kt | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt index c37f92b0be..066746a361 100644 --- a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt @@ -139,7 +139,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia ) } is RoomGroupingMethod.BySpace -> { - val selectedSpace = appStateHandler.safeActiveSpaceId() + //val selectedSpace = appStateHandler.safeActiveSpaceId() val inviteCount = if (autoAcceptInvites.hideInvites) { 0 @@ -148,11 +148,12 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia roomSummaryQueryParams { this.memberships = listOf(Membership.INVITE) } ).size } + val spacesShowAllRoomsInHome = vectorPreferences.prefSpacesShowAllRoomInHome() val totalCount = session.getNotificationCountForRooms( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf { - !vectorPreferences.prefSpacesShowAllRoomInHome() + !spacesShowAllRoomsInHome } ?: ActiveSpaceFilter.None }, scSdkPreferences @@ -164,6 +165,31 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia totalCount.unreadCount, totalCount.markedUnreadCount ) + + // SC: count total room notifications for drawer badge, instead of filtering for others like Element does, + // to prevent counting rooms multiple times + val topLevelTotalCount = if (spacesShowAllRoomsInHome) { + totalCount + } else { + session.getNotificationCountForRooms( + roomSummaryQueryParams { + this.memberships = listOf(Membership.JOIN) + this.activeSpaceFilter = ActiveSpaceFilter.None + }, + scSdkPreferences + ) + } + + val topLevelCounts = RoomAggregateNotificationCount( + topLevelTotalCount.notificationCount + inviteCount, + topLevelTotalCount.highlightCount + inviteCount, + topLevelTotalCount.unreadCount, + topLevelTotalCount.markedUnreadCount + ) + + CountInfo(homeCount = counts, otherCount = topLevelCounts) + + /* val rootCounts = session.spaceService().getRootSpaceSummaries() .filter { // filter out current selection @@ -187,6 +213,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia }) + (counts.markedUnreadCount.takeIf { selectedSpace != null } ?: 0) ) ) + */ } null -> { CountInfo(