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
This commit is contained in:
SpiritCroc 2021-09-11 10:22:23 +02:00
parent 4803fbbc05
commit 8a8ad86806

View file

@ -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(