@@ -1294,12 +1294,9 @@ function getDefaultNotificationPreferenceForReport(report: OnyxEntry<Report>): V
1294
1294
}
1295
1295
1296
1296
/**
1297
- * Get the notification preference given a report
1297
+ * Get the notification preference given a report. This should ALWAYS default to 'hidden'. Do not change this!
1298
1298
*/
1299
- function getReportNotificationPreference ( report : OnyxEntry < Report > , shouldDefaltToHidden = true ) : ValueOf < typeof CONST . REPORT . NOTIFICATION_PREFERENCE > {
1300
- if ( ! shouldDefaltToHidden ) {
1301
- return report ?. participants ?. [ currentUserAccountID ?? - 1 ] ?. notificationPreference ?? getDefaultNotificationPreferenceForReport ( report ) ;
1302
- }
1299
+ function getReportNotificationPreference ( report : OnyxEntry < Report > ) : ValueOf < typeof CONST . REPORT . NOTIFICATION_PREFERENCE > {
1303
1300
return report ?. participants ?. [ currentUserAccountID ?? - 1 ] ?. notificationPreference ?? CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ;
1304
1301
}
1305
1302
@@ -1415,6 +1412,23 @@ function canCreateTaskInReport(report: OnyxEntry<Report>): boolean {
1415
1412
return true ;
1416
1413
}
1417
1414
1415
+ /**
1416
+ * For all intents and purposes a report that has no notificationPreference at all should be considered "hidden".
1417
+ * We will remove the 'hidden' field entirely once the backend changes for https://github.com/Expensify/Expensify/issues/450891 are done.
1418
+ */
1419
+ function isHiddenForCurrentUser ( notificationPreference : string | null | undefined ) : boolean ;
1420
+ function isHiddenForCurrentUser ( report : OnyxEntry < Report > ) : boolean ;
1421
+ function isHiddenForCurrentUser ( reportOrPreference : OnyxEntry < Report > | string | null | undefined ) : boolean {
1422
+ if ( typeof reportOrPreference === 'object' && reportOrPreference !== null ) {
1423
+ const notificationPreference = getReportNotificationPreference ( reportOrPreference ) ;
1424
+ return isHiddenForCurrentUser ( notificationPreference ) ;
1425
+ }
1426
+ if ( reportOrPreference === undefined || reportOrPreference === null || reportOrPreference === '' ) {
1427
+ return true ;
1428
+ }
1429
+ return reportOrPreference === CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ;
1430
+ }
1431
+
1418
1432
/**
1419
1433
* Returns true if there are any guides accounts (team.expensify.com) in a list of accountIDs
1420
1434
* by cross-referencing the accountIDs with personalDetails since guides that are participants
@@ -1426,7 +1440,7 @@ function hasExpensifyGuidesEmails(accountIDs: number[]): boolean {
1426
1440
1427
1441
function getMostRecentlyVisitedReport ( reports : Array < OnyxEntry < Report > > , reportMetadata : OnyxCollection < ReportMetadata > ) : OnyxEntry < Report > {
1428
1442
const filteredReports = reports . filter ( ( report ) => {
1429
- const shouldKeep = ! isChatThread ( report ) || getReportNotificationPreference ( report ) !== CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ;
1443
+ const shouldKeep = ! isChatThread ( report ) || ! isHiddenForCurrentUser ( report ) ;
1430
1444
return shouldKeep && ! ! report ?. reportID && ! ! ( reportMetadata ?. [ `${ ONYXKEYS . COLLECTION . REPORT_METADATA } ${ report . reportID } ` ] ?. lastVisitTime ?? report ?. lastReadTime ) ;
1431
1445
} ) ;
1432
1446
return lodashMaxBy ( filteredReports , ( a ) => new Date ( reportMetadata ?. [ `${ ONYXKEYS . COLLECTION . REPORT_METADATA } ${ a ?. reportID } ` ] ?. lastVisitTime ?? a ?. lastReadTime ?? '' ) . valueOf ( ) ) ;
@@ -2233,7 +2247,7 @@ function getParticipantsAccountIDsForDisplay(report: OnyxEntry<Report>, shouldEx
2233
2247
return false ;
2234
2248
}
2235
2249
2236
- if ( shouldExcludeHidden && reportParticipants [ accountID ] ?. notificationPreference === CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ) {
2250
+ if ( shouldExcludeHidden && isHiddenForCurrentUser ( reportParticipants [ accountID ] ?. notificationPreference ) ) {
2237
2251
return false ;
2238
2252
}
2239
2253
@@ -8119,7 +8133,7 @@ function canJoinChat(report: OnyxEntry<Report>, parentReportAction: OnyxInputOrE
8119
8133
}
8120
8134
8121
8135
// If the notification preference of the chat is not hidden that means we have already joined the chat
8122
- if ( getReportNotificationPreference ( report ) !== CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ) {
8136
+ if ( ! isHiddenForCurrentUser ( report ) ) {
8123
8137
return false ;
8124
8138
}
8125
8139
@@ -8153,7 +8167,7 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo
8153
8167
return false ;
8154
8168
}
8155
8169
8156
- if ( getReportNotificationPreference ( report ) === CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ) {
8170
+ if ( isHiddenForCurrentUser ( report ) ) {
8157
8171
return false ;
8158
8172
}
8159
8173
@@ -8855,6 +8869,7 @@ export {
8855
8869
getAllReportActionsErrorsAndReportActionThatRequiresAttention ,
8856
8870
hasInvoiceReports ,
8857
8871
getReportMetadata ,
8872
+ isHiddenForCurrentUser ,
8858
8873
} ;
8859
8874
8860
8875
export type {
0 commit comments