Skip to content

Commit 1925044

Browse files
Chat folders: for unread, check setting and active notification profile
1 parent aa78798 commit 1925044

File tree

7 files changed

+42
-18
lines changed

7 files changed

+42
-18
lines changed

ts/ConversationController.preload.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,6 @@ export class ConversationController {
391391
const unreadStats = countAllConversationsUnreadStats(
392392
this.#_conversations.map(
393393
(conversation): ConversationPropsForUnreadStats | undefined => {
394-
if (
395-
activeProfile &&
396-
!activeProfile.allowedMembers.has(conversation.id)
397-
) {
398-
return undefined;
399-
}
400-
401394
// Need to pull this out manually into the Redux shape
402395
// because `conversation.format()` can return cached props by the
403396
// time this runs
@@ -414,6 +407,7 @@ export class ConversationController {
414407
}
415408
),
416409
{
410+
activeProfile,
417411
includeMuted: badgeCountMutedConversationsSetting
418412
? 'setting-on'
419413
: 'setting-off',

ts/services/notificationProfilesService.preload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class NotificationProfilesService {
177177
updateCurrentState(currentState, currentActiveProfile);
178178

179179
// The active profile can influence the overall badge count
180-
window.ConversationController.updateUnreadCount();
180+
window.Whisper.events.emit('updateUnreadCount');
181181
}
182182

183183
if (previousActiveProfile?.id === currentActiveProfileId) {

ts/state/ducks/search.preload.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ function shouldRemoveConversationFromUnreadList(
333333
conversation &&
334334
(selectedConversationId == null ||
335335
selectedConversationId !== conversation.id) &&
336-
!isConversationUnread(conversation, { includeMuted: 'force-exclude' })
336+
!isConversationUnread(conversation, {
337+
activeProfile: undefined,
338+
includeMuted: 'force-exclude',
339+
})
337340
) {
338341
return true;
339342
}
@@ -499,6 +502,7 @@ const doSearch = debounce(
499502
selectedConversation &&
500503
state.search.conversationIds.includes(selectedConversationId) &&
501504
!isConversationUnread(selectedConversation, {
505+
activeProfile: undefined,
502506
includeMuted: 'force-include',
503507
})
504508
? selectedConversation

ts/state/selectors/conversations.dom.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import {
8989
} from '../../util/countUnreadStats.std.js';
9090
import type { AllChatFoldersMutedStats } from '../../util/countMutedStats.std.js';
9191
import { countAllChatFoldersMutedStats } from '../../util/countMutedStats.std.js';
92+
import { getActiveProfile } from './notificationProfiles.dom.js';
9293

9394
const { isNumber, pick } = lodash;
9495

@@ -699,8 +700,10 @@ export const getAllConversationsUnreadStats: StateSelector<UnreadStats> =
699700
createSelector(
700701
getAllConversations,
701702
getBadgeCountMutedConversations,
702-
(conversations, badgeCountMutedConversations) => {
703+
getActiveProfile,
704+
(conversations, badgeCountMutedConversations, activeProfile) => {
703705
return countAllConversationsUnreadStats(conversations, {
706+
activeProfile,
704707
includeMuted: badgeCountMutedConversations
705708
? 'setting-on'
706709
: 'setting-off',
@@ -713,11 +716,18 @@ export const getAllChatFoldersUnreadStats: StateSelector<AllChatFoldersUnreadSta
713716
getCurrentChatFolders,
714717
getAllConversations,
715718
getBadgeCountMutedConversations,
716-
(currentChatFolders, allConversations, badgeCountMutedConversations) => {
719+
getActiveProfile,
720+
(
721+
currentChatFolders,
722+
allConversations,
723+
badgeCountMutedConversations,
724+
activeProfile
725+
) => {
717726
return countAllChatFoldersUnreadStats(
718727
currentChatFolders,
719728
allConversations,
720729
{
730+
activeProfile,
721731
includeMuted: badgeCountMutedConversations
722732
? 'setting-on'
723733
: 'setting-off',

ts/test-node/util/countUnreadStats_test.node.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ describe('countUnreadStats', () => {
9090
expected: boolean,
9191
includeMuted: UnreadStatsIncludeMuted = 'force-include'
9292
) {
93-
const actual = _canCountConversation(mockChat(chat), { includeMuted });
93+
const actual = _canCountConversation(mockChat(chat), {
94+
activeProfile: undefined,
95+
includeMuted,
96+
});
9497
assert.equal(actual, expected);
9598
}
9699

@@ -172,7 +175,10 @@ describe('countUnreadStats', () => {
172175
expected: boolean,
173176
includeMuted: UnreadStatsIncludeMuted = 'force-exclude'
174177
) {
175-
const actual = isConversationUnread(mockChat(chat), { includeMuted });
178+
const actual = isConversationUnread(mockChat(chat), {
179+
activeProfile: undefined,
180+
includeMuted,
181+
});
176182
assert.equal(actual, expected);
177183
}
178184

@@ -213,6 +219,7 @@ describe('countUnreadStats', () => {
213219
includeMuted: UnreadStatsIncludeMuted = 'force-exclude'
214220
) {
215221
const actual = countConversationUnreadStats(mockChat(chat), {
222+
activeProfile: undefined,
216223
includeMuted,
217224
});
218225
assert.deepEqual(actual, mockStats(expected));
@@ -252,6 +259,7 @@ describe('countUnreadStats', () => {
252259
includeMuted: UnreadStatsIncludeMuted = 'force-exclude'
253260
) {
254261
const actual = countAllConversationsUnreadStats(chats.map(mockChat), {
262+
activeProfile: undefined,
255263
includeMuted,
256264
});
257265
assert.deepEqual(actual, mockStats(expected));
@@ -323,7 +331,7 @@ describe('countUnreadStats', () => {
323331
const actual = countAllChatFoldersUnreadStats(
324332
CurrentChatFolders.fromArray(folders),
325333
chats.map(mockChat),
326-
{ includeMuted }
334+
{ activeProfile: undefined, includeMuted }
327335
);
328336

329337
assert.deepEqual(actual, expected);

ts/util/countUnreadStats.std.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Copyright 2023 Signal Messenger, LLC
22
// SPDX-License-Identifier: AGPL-3.0-only
33

4-
import type { ConversationType } from '../state/ducks/conversations.preload.js';
54
import { isConversationInChatFolder } from '../types/ChatFolder.std.js';
6-
import type { ChatFolderId } from '../types/ChatFolder.std.js';
75
import { CurrentChatFolders } from '../types/CurrentChatFolders.std.js';
86
import { isConversationMuted } from './isConversationMuted.std.js';
97

8+
import type { ConversationType } from '../state/ducks/conversations.preload.js';
9+
import type { ChatFolderId } from '../types/ChatFolder.std.js';
10+
import type { NotificationProfileType } from '../types/NotificationProfile.std.js';
11+
1012
type MutableUnreadStats = {
1113
/**
1214
* Total of `conversation.unreadCount`
@@ -53,6 +55,7 @@ export type UnreadStatsIncludeMuted =
5355

5456
export type UnreadStatsOptions = Readonly<{
5557
includeMuted: UnreadStatsIncludeMuted;
58+
activeProfile: NotificationProfileType | undefined;
5659
}>;
5760

5861
export type ConversationPropsForUnreadStats = Readonly<
@@ -93,7 +96,9 @@ export function _canCountConversation(
9396

9497
if (
9598
_shouldExcludeMuted(options.includeMuted) &&
96-
isConversationMuted(conversation)
99+
(isConversationMuted(conversation) ||
100+
(options.activeProfile &&
101+
!options.activeProfile.allowedMembers.has(conversation.id)))
97102
) {
98103
return false;
99104
}

ts/util/filterAndSortConversations.std.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ function filterConversationsByUnread(
7272
includeMuted: UnreadStatsIncludeMuted
7373
): Array<ConversationType> {
7474
return conversations.filter(conversation => {
75-
return isConversationUnread(conversation, { includeMuted });
75+
return isConversationUnread(conversation, {
76+
activeProfile: undefined,
77+
includeMuted,
78+
});
7679
});
7780
}
7881

0 commit comments

Comments
 (0)