Skip to content

Commit 582c6f1

Browse files
authored
Merge pull request #54146 from Expensify/marcaaron-defaultToHidden
Replace all explicit `hidden` comparisons with `isHiddenParticipant()`
2 parents af17eae + c0a983b commit 582c6f1

13 files changed

+51
-39
lines changed

src/libs/OptionsListUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ function getPolicyExpenseReportOption(participant: Participant | ReportUtils.Opt
785785
const expenseReport = ReportUtils.isPolicyExpenseChat(participant) ? ReportUtils.getReportOrDraftReport(participant.reportID) : null;
786786

787787
const visibleParticipantAccountIDs = Object.entries(expenseReport?.participants ?? {})
788-
.filter(([, reportParticipant]) => reportParticipant && reportParticipant.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN)
788+
.filter(([, reportParticipant]) => reportParticipant && !ReportUtils.isHiddenForCurrentUser(reportParticipant.notificationPreference))
789789
.map(([accountID]) => Number(accountID));
790790

791791
const option = createOption(
@@ -1903,7 +1903,7 @@ function getEmptyOptions(): Options {
19031903

19041904
function shouldUseBoldText(report: ReportUtils.OptionData): boolean {
19051905
const notificationPreference = report.notificationPreference ?? ReportUtils.getReportNotificationPreference(report);
1906-
return report.isUnread === true && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
1906+
return report.isUnread === true && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE && !ReportUtils.isHiddenForCurrentUser(notificationPreference);
19071907
}
19081908

19091909
export {

src/libs/ReportUtils.ts

+24-9
Original file line numberDiff line numberDiff line change
@@ -1294,12 +1294,9 @@ function getDefaultNotificationPreferenceForReport(report: OnyxEntry<Report>): V
12941294
}
12951295

12961296
/**
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!
12981298
*/
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> {
13031300
return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
13041301
}
13051302

@@ -1415,6 +1412,23 @@ function canCreateTaskInReport(report: OnyxEntry<Report>): boolean {
14151412
return true;
14161413
}
14171414

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+
14181432
/**
14191433
* Returns true if there are any guides accounts (team.expensify.com) in a list of accountIDs
14201434
* by cross-referencing the accountIDs with personalDetails since guides that are participants
@@ -1426,7 +1440,7 @@ function hasExpensifyGuidesEmails(accountIDs: number[]): boolean {
14261440

14271441
function getMostRecentlyVisitedReport(reports: Array<OnyxEntry<Report>>, reportMetadata: OnyxCollection<ReportMetadata>): OnyxEntry<Report> {
14281442
const filteredReports = reports.filter((report) => {
1429-
const shouldKeep = !isChatThread(report) || getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
1443+
const shouldKeep = !isChatThread(report) || !isHiddenForCurrentUser(report);
14301444
return shouldKeep && !!report?.reportID && !!(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime);
14311445
});
14321446
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
22332247
return false;
22342248
}
22352249

2236-
if (shouldExcludeHidden && reportParticipants[accountID]?.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
2250+
if (shouldExcludeHidden && isHiddenForCurrentUser(reportParticipants[accountID]?.notificationPreference)) {
22372251
return false;
22382252
}
22392253

@@ -8119,7 +8133,7 @@ function canJoinChat(report: OnyxEntry<Report>, parentReportAction: OnyxInputOrE
81198133
}
81208134

81218135
// 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)) {
81238137
return false;
81248138
}
81258139

@@ -8153,7 +8167,7 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo
81538167
return false;
81548168
}
81558169

8156-
if (getReportNotificationPreference(report) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
8170+
if (isHiddenForCurrentUser(report)) {
81578171
return false;
81588172
}
81598173

@@ -8855,6 +8869,7 @@ export {
88558869
getAllReportActionsErrorsAndReportActionThatRequiresAttention,
88568870
hasInvoiceReports,
88578871
getReportMetadata,
8872+
isHiddenForCurrentUser,
88588873
};
88598874

88608875
export type {

src/libs/SidebarUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function getOrderedReportIDs(
125125
}
126126
const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '-1', report?.parentReportActionID ?? '-1');
127127
const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations);
128-
const isHidden = ReportUtils.getReportNotificationPreference(report) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
128+
const isHidden = ReportUtils.isHiddenForCurrentUser(report);
129129
const isFocused = report.reportID === currentReportId;
130130
const hasErrorsOtherThanFailedReceipt = ReportUtils.hasReportErrorsOtherThanFailedReceipt(report, doesReportHaveViolations, transactionViolations);
131131
const isReportInAccessible = report?.errorFields?.notFound;

src/libs/UnreadIndicatorUpdater/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function getUnreadReportsForUnreadIndicator(reports: OnyxCollection<Report>, cur
4040
* Furthermore, muted reports may or may not appear in the LHN depending on priority mode,
4141
* but they should not be considered in the unread indicator count.
4242
*/
43-
notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN &&
43+
!ReportUtils.isHiddenForCurrentUser(notificationPreference) &&
4444
notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE
4545
);
4646
});

src/libs/actions/Report.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,8 @@ function addActions(reportID: string, text = '', file?: FileObject) {
545545
};
546546

547547
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
548-
const shouldUpdateNotificationPrefernece = !isEmptyObject(report) && ReportUtils.getReportNotificationPreference(report) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
549-
550-
if (shouldUpdateNotificationPrefernece) {
548+
const shouldUpdateNotificationPreference = !isEmptyObject(report) && ReportUtils.isHiddenForCurrentUser(report);
549+
if (shouldUpdateNotificationPreference) {
551550
optimisticReport.participants = {
552551
[currentUserAccountID]: {notificationPreference: ReportUtils.getDefaultNotificationPreferenceForReport(report)},
553552
};
@@ -1932,7 +1931,7 @@ function toggleSubscribeToChildReport(childReportID = '-1', parentReportAction:
19321931
if (childReportID !== '-1') {
19331932
openReport(childReportID);
19341933
const parentReportActionID = parentReportAction?.reportActionID ?? '-1';
1935-
if (!prevNotificationPreference || prevNotificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
1934+
if (!prevNotificationPreference || ReportUtils.isHiddenForCurrentUser(prevNotificationPreference)) {
19361935
updateNotificationPreference(childReportID, prevNotificationPreference, CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, parentReportID, parentReportActionID);
19371936
} else {
19381937
updateNotificationPreference(childReportID, prevNotificationPreference, CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, parentReportID, parentReportActionID);
@@ -1957,8 +1956,9 @@ function toggleSubscribeToChildReport(childReportID = '-1', parentReportAction:
19571956

19581957
const participantLogins = PersonalDetailsUtils.getLoginsByAccountIDs(participantAccountIDs);
19591958
openReport(newChat.reportID, '', participantLogins, newChat, parentReportAction.reportActionID);
1960-
const notificationPreference =
1961-
prevNotificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
1959+
const notificationPreference = ReportUtils.isHiddenForCurrentUser(prevNotificationPreference)
1960+
? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS
1961+
: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
19621962
updateNotificationPreference(newChat.reportID, prevNotificationPreference, notificationPreference, parentReportID, parentReportAction?.reportActionID);
19631963
}
19641964
}
@@ -3062,7 +3062,12 @@ function leaveRoom(reportID: string, isWorkspaceMemberLeavingWorkspaceRoom = fal
30623062
failureData.push({
30633063
onyxMethod: Onyx.METHOD.MERGE,
30643064
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`,
3065-
value: {[report.parentReportActionID]: {childReportNotificationPreference: ReportUtils.getReportNotificationPreference(report, false)}},
3065+
value: {
3066+
[report.parentReportActionID]: {
3067+
childReportNotificationPreference:
3068+
report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? ReportUtils.getDefaultNotificationPreferenceForReport(report),
3069+
},
3070+
},
30663071
});
30673072
}
30683073

src/libs/actions/Task.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function createTaskAndNavigate(
252252
},
253253
);
254254

255-
const shouldUpdateNotificationPreference = !isEmptyObject(parentReport) && ReportUtils.getReportNotificationPreference(parentReport) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
255+
const shouldUpdateNotificationPreference = !isEmptyObject(parentReport) && ReportUtils.isHiddenForCurrentUser(parentReport);
256256
if (shouldUpdateNotificationPreference) {
257257
optimisticData.push({
258258
onyxMethod: Onyx.METHOD.MERGE,

src/libs/actions/User.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
3232
import * as Pusher from '@libs/Pusher/pusher';
3333
import PusherUtils from '@libs/PusherUtils';
3434
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
35+
import * as ReportUtils from '@libs/ReportUtils';
3536
import playSound, {SOUNDS} from '@libs/Sound';
3637
import playSoundExcludingMobile from '@libs/Sound/playSoundExcludingMobile';
3738
import Visibility from '@libs/Visibility';
@@ -795,9 +796,7 @@ const isChannelMuted = (reportId: string) =>
795796
Onyx.disconnect(connection);
796797
const notificationPreference = report?.participants?.[currentUserAccountID]?.notificationPreference;
797798

798-
resolve(
799-
!notificationPreference || notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE || notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
800-
);
799+
resolve(!notificationPreference || notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE || ReportUtils.isHiddenForCurrentUser(notificationPreference));
801800
},
802801
});
803802
});

src/pages/ProfilePage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function ProfilePage({route}: ProfilePageProps) {
158158

159159
const notificationPreferenceValue = ReportUtils.getReportNotificationPreference(report);
160160

161-
const shouldShowNotificationPreference = !isEmptyObject(report) && !isCurrentUser && notificationPreferenceValue !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
161+
const shouldShowNotificationPreference = !isEmptyObject(report) && !isCurrentUser && !ReportUtils.isHiddenForCurrentUser(notificationPreferenceValue);
162162
const notificationPreference = shouldShowNotificationPreference
163163
? translate(`notificationPreferencesPage.notificationPreferences.${notificationPreferenceValue}` as TranslationPaths)
164164
: '';

src/pages/ReportDetailsPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta
288288
roomDescription = translate('newRoomPage.roomName');
289289
}
290290

291-
const shouldShowNotificationPref = !isMoneyRequestReport && ReportUtils.getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
291+
const shouldShowNotificationPref = !isMoneyRequestReport && !ReportUtils.isHiddenForCurrentUser(report);
292292
const shouldShowWriteCapability = !isMoneyRequestReport;
293293
const shouldShowMenuItem = shouldShowNotificationPref || shouldShowWriteCapability || (!!report?.visibility && report.chatType !== CONST.REPORT.CHAT_TYPE.INVOICE);
294294

src/pages/RoomInvitePage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function RoomInvitePage({
6363
// Any existing participants and Expensify emails should not be eligible for invitation
6464
const excludedUsers = useMemo(() => {
6565
const visibleParticipantAccountIDs = Object.entries(report.participants ?? {})
66-
.filter(([, participant]) => participant && participant.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN)
66+
.filter(([, participant]) => participant && !ReportUtils.isHiddenForCurrentUser(participant.notificationPreference))
6767
.map(([accountID]) => Number(accountID));
6868
return [...PersonalDetailsUtils.getLoginsByAccountIDs(visibleParticipantAccountIDs), ...CONST.EXPENSIFY_EMAILS].map((participant) =>
6969
PhoneNumber.addSMSDomainIfPhoneNumber(participant),

src/pages/home/ReportScreen.tsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
558558

559559
// If a user has chosen to leave a thread, and then returns to it (e.g. with the back button), we need to call `openReport` again in order to allow the user to rejoin and to receive real-time updates
560560
useEffect(() => {
561-
if (
562-
!shouldUseNarrowLayout ||
563-
!isFocused ||
564-
prevIsFocused ||
565-
!ReportUtils.isChatThread(report) ||
566-
ReportUtils.getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN ||
567-
isSingleTransactionView
568-
) {
561+
if (!shouldUseNarrowLayout || !isFocused || prevIsFocused || !ReportUtils.isChatThread(report) || !ReportUtils.isHiddenForCurrentUser(report) || isSingleTransactionView) {
569562
return;
570563
}
571564
Report.openReport(reportID ?? '');

src/pages/settings/Report/NotificationPreferencePage.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ function NotificationPreferencePage({report}: NotificationPreferencePageProps) {
2929
const shouldDisableNotificationPreferences =
3030
ReportUtils.isArchivedRoom(report, reportNameValuePairs) ||
3131
ReportUtils.isSelfDM(report) ||
32-
(!isMoneyRequestReport && currentNotificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);
32+
(!isMoneyRequestReport && ReportUtils.isHiddenForCurrentUser(currentNotificationPreference));
3333
const notificationPreferenceOptions = Object.values(CONST.REPORT.NOTIFICATION_PREFERENCE)
34-
.filter((pref) => pref !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN)
34+
.filter((pref) => !ReportUtils.isHiddenForCurrentUser(pref))
3535
.map((preference) => ({
3636
value: preference,
3737
text: translate(`notificationPreferencesPage.notificationPreferences.${preference}`),

src/pages/settings/Report/ReportSettingsPage.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps)
3636
const shouldDisableSettings = isEmptyObject(report) || ReportUtils.isArchivedRoom(report, reportNameValuePairs) || ReportUtils.isSelfDM(report);
3737
const notificationPreferenceValue = ReportUtils.getReportNotificationPreference(report);
3838
const notificationPreference =
39-
notificationPreferenceValue && notificationPreferenceValue !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN
39+
notificationPreferenceValue && !ReportUtils.isHiddenForCurrentUser(notificationPreferenceValue)
4040
? translate(`notificationPreferencesPage.notificationPreferences.${notificationPreferenceValue}`)
4141
: '';
4242
const writeCapability = ReportUtils.isAdminRoom(report) ? CONST.REPORT.WRITE_CAPABILITIES.ADMINS : report?.writeCapability ?? CONST.REPORT.WRITE_CAPABILITIES.ALL;
@@ -45,7 +45,7 @@ function ReportSettingsPage({report, policies, route}: ReportSettingsPageProps)
4545
const shouldAllowWriteCapabilityEditing = useMemo(() => ReportUtils.canEditWriteCapability(report, linkedWorkspace), [report, linkedWorkspace]);
4646
const shouldAllowChangeVisibility = useMemo(() => ReportUtils.canEditRoomVisibility(report, linkedWorkspace), [report, linkedWorkspace]);
4747

48-
const shouldShowNotificationPref = !isMoneyRequestReport && notificationPreferenceValue !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
48+
const shouldShowNotificationPref = !isMoneyRequestReport && !ReportUtils.isHiddenForCurrentUser(notificationPreferenceValue);
4949

5050
const shouldShowWriteCapability = !isMoneyRequestReport;
5151

0 commit comments

Comments
 (0)