-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathindex.ts
57 lines (51 loc) · 2.29 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import type {OnyxCollection} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as ReportUtils from '@libs/ReportUtils';
import Navigation, {navigationRef} from '@navigation/Navigation';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report} from '@src/types/onyx';
import updateUnread from './updateUnread';
let allReports: OnyxCollection<Report> = {};
export default function getUnreadReportsForUnreadIndicator(reports: OnyxCollection<Report>, currentReportID: string) {
return Object.values(reports ?? {}).filter(
(report) =>
ReportUtils.isUnread(report) &&
ReportUtils.shouldReportBeInOptionList({
report,
currentReportId: currentReportID ?? '',
betas: [],
policies: {},
doesReportHaveViolations: false,
isInGSDMode: false,
excludeEmptyChats: false,
}) &&
/**
* Chats with hidden preference remain invisible in the LHN and are not considered "unread."
* They are excluded from the LHN rendering, but not filtered from the "option list."
* This ensures they appear in Search, but not in the LHN or unread count.
*
* Furthermore, muted reports may or may not appear in the LHN depending on priority mode,
* but they should not be considered in the unread indicator count.
*/
report?.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN &&
report?.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE,
);
}
const triggerUnreadUpdate = () => {
const currentReportID = navigationRef.isReady() ? Navigation.getTopmostReportId() ?? '' : '';
// We want to keep notification count consistent with what can be accessed from the LHN list
const unreadReports = getUnreadReportsForUnreadIndicator(allReports, currentReportID);
updateUnread(unreadReports.length);
};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (reportsFromOnyx) => {
allReports = reportsFromOnyx;
triggerUnreadUpdate();
},
});
navigationRef.addListener('state', () => {
triggerUnreadUpdate();
});