From fa2b95228604dece50dd895ef6d53b2a91ed8538 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Wed, 29 Oct 2025 15:20:47 -0500 Subject: [PATCH] Notification Profiles: Exclude silenced conversations from badge count Co-authored-by: Scott Nonnenberg --- ts/ConversationController.preload.ts | 10 +++++++++- ts/services/notificationProfilesService.preload.ts | 13 +++++++++++-- ts/util/countUnreadStats.std.ts | 4 ++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ts/ConversationController.preload.ts b/ts/ConversationController.preload.ts index 78406b2e2d..1e047634ed 100644 --- a/ts/ConversationController.preload.ts +++ b/ts/ConversationController.preload.ts @@ -371,10 +371,18 @@ export class ConversationController { const badgeCountMutedConversationsSetting = itemStorage.get('badge-count-muted-conversations') || false; + const { activeProfile } = window.reduxStore.getState().notificationProfiles; const unreadStats = countAllConversationsUnreadStats( this.#_conversations.map( - (conversation): ConversationPropsForUnreadStats => { + (conversation): ConversationPropsForUnreadStats | undefined => { + if ( + activeProfile && + !activeProfile.allowedMembers.has(conversation.id) + ) { + return undefined; + } + // Need to pull this out manually into the Redux shape // because `conversation.format()` can return cached props by the // time this runs diff --git a/ts/services/notificationProfilesService.preload.ts b/ts/services/notificationProfilesService.preload.ts index 351292f8ab..39ce8cc061 100644 --- a/ts/services/notificationProfilesService.preload.ts +++ b/ts/services/notificationProfilesService.preload.ts @@ -164,11 +164,20 @@ export class NotificationProfilesService { ) : undefined; - if (!isEqual(previousCurrentState, currentState)) { + if ( + !isEqual(previousCurrentState, currentState) || + !isEqual(currentActiveProfile, previousActiveProfile) + ) { + const idForLogging = currentActiveProfile + ? redactNotificationProfileId(currentActiveProfile.id) + : 'NONE'; log.info( - 'notificationProfileService: next profile event has changed, updating redux' + `notificationProfileService: next profile event has changed, updating redux. Active profile is ${idForLogging}` ); updateCurrentState(currentState, currentActiveProfile); + + // The active profile can influence the overall badge count + window.ConversationController.updateUnreadCount(); } if (previousActiveProfile?.id === currentActiveProfileId) { diff --git a/ts/util/countUnreadStats.std.ts b/ts/util/countUnreadStats.std.ts index 6e79369fe2..d732fbc777 100644 --- a/ts/util/countUnreadStats.std.ts +++ b/ts/util/countUnreadStats.std.ts @@ -157,13 +157,13 @@ export function countConversationUnreadStats( } export function countAllConversationsUnreadStats( - conversations: ReadonlyArray, + conversations: ReadonlyArray, options: UnreadStatsOptions ): UnreadStats { const unreadStats = _createUnreadStats(); for (const conversation of conversations) { - if (_canCountConversation(conversation, options)) { + if (conversation && _canCountConversation(conversation, options)) { _countConversation(unreadStats, conversation); } }