-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace all explicit hidden
comparisons with isHiddenParticipant()
#54146
Changes from all commits
0a0bf76
4898e6d
b416e25
c0a983b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -348,7 +348,7 @@ | |
* Get the participant option for a report. | ||
*/ | ||
function getParticipantsOption(participant: ReportUtils.OptionData | Participant, personalDetails: OnyxEntry<PersonalDetailsList>): Participant { | ||
const detail = getPersonalDetailsForAccountIDs([participant.accountID ?? -1], personalDetails)[participant.accountID ?? -1]; | ||
Check failure on line 351 in src/libs/OptionsListUtils.ts
|
||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
const login = detail?.login || participant.login || ''; | ||
const displayName = LocalePhoneNumber.formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(detail, login || participant.text)); | ||
|
@@ -356,7 +356,7 @@ | |
return { | ||
keyForList: String(detail?.accountID), | ||
login, | ||
accountID: detail?.accountID ?? -1, | ||
Check failure on line 359 in src/libs/OptionsListUtils.ts
|
||
text: displayName, | ||
firstName: detail?.firstName ?? '', | ||
lastName: detail?.lastName ?? '', | ||
|
@@ -483,7 +483,7 @@ | |
* Get the last message text from the report directly or from other sources for special cases. | ||
*/ | ||
function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails: Partial<PersonalDetails> | null, policy?: OnyxEntry<Policy>): string { | ||
const reportID = report?.reportID ?? '-1'; | ||
Check failure on line 486 in src/libs/OptionsListUtils.ts
|
||
const lastReportAction = lastVisibleReportActions[reportID] ?? null; | ||
|
||
// some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action | ||
|
@@ -517,7 +517,7 @@ | |
lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForMoneyRequestMessage); | ||
} else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { | ||
const iouReport = ReportUtils.getReportOrDraftReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)); | ||
const lastIOUMoneyReportAction = allSortedReportActions[iouReport?.reportID ?? '-1']?.find( | ||
Check failure on line 520 in src/libs/OptionsListUtils.ts
|
||
(reportAction, key): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> => | ||
ReportActionUtils.shouldReportActionBeVisible(reportAction, key, ReportUtils.canUserPerformWriteAction(report)) && | ||
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && | ||
|
@@ -539,9 +539,9 @@ | |
lastMessageTextFromReport = ReportUtils.getReimbursementDeQueuedActionMessage(lastReportAction, report, true); | ||
} else if (ReportActionUtils.isDeletedParentAction(lastReportAction) && ReportUtils.isChatReport(report)) { | ||
lastMessageTextFromReport = ReportUtils.getDeletedParentActionMessageForChatReport(lastReportAction); | ||
} else if (ReportActionUtils.isPendingRemove(lastReportAction) && ReportActionUtils.isThreadParentMessage(lastReportAction, report?.reportID ?? '-1')) { | ||
Check failure on line 542 in src/libs/OptionsListUtils.ts
|
||
lastMessageTextFromReport = Localize.translateLocal('parentReportAction.hiddenMessage'); | ||
} else if (ReportUtils.isReportMessageAttachment({text: report?.lastMessageText ?? '-1', html: report?.lastMessageHtml, translationKey: report?.lastMessageTranslationKey, type: ''})) { | ||
Check failure on line 544 in src/libs/OptionsListUtils.ts
|
||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
lastMessageTextFromReport = `[${Localize.translateLocal((report?.lastMessageTranslationKey || 'common.attachment') as TranslationPaths)}]`; | ||
} else if (ReportActionUtils.isModifiedExpenseAction(lastReportAction)) { | ||
|
@@ -682,7 +682,7 @@ | |
hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat || ReportUtils.isGroupChat(report); | ||
subtitle = ReportUtils.getChatRoomSubtitle(report); | ||
|
||
const lastActorDetails = personalDetailMap[report.lastActorAccountID ?? -1] ?? null; | ||
Check failure on line 685 in src/libs/OptionsListUtils.ts
|
||
const lastActorDisplayName = getLastActorDisplayName(lastActorDetails, hasMultipleParticipants); | ||
const lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails); | ||
let lastMessageText = lastMessageTextFromReport; | ||
|
@@ -767,7 +767,7 @@ | |
const expenseReport = ReportUtils.isPolicyExpenseChat(participant) ? ReportUtils.getReportOrDraftReport(participant.reportID) : null; | ||
|
||
const visibleParticipantAccountIDs = Object.entries(expenseReport?.participants ?? {}) | ||
.filter(([, reportParticipant]) => reportParticipant && reportParticipant.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) | ||
.filter(([, reportParticipant]) => reportParticipant && !ReportUtils.isHiddenForCurrentUser(reportParticipant.notificationPreference)) | ||
.map(([accountID]) => Number(accountID)); | ||
|
||
const option = createOption( | ||
|
@@ -897,7 +897,7 @@ | |
|
||
const allPersonalDetailsOptions = Object.values(personalDetails ?? {}).map((personalDetail) => ({ | ||
item: personalDetail, | ||
...createOption([personalDetail?.accountID ?? -1], personalDetails, reportMapForAccountIDs[personalDetail?.accountID ?? -1], {}, {showPersonalDetails: true}), | ||
Check failure on line 900 in src/libs/OptionsListUtils.ts
|
||
})); | ||
|
||
return { | ||
|
@@ -1787,7 +1787,7 @@ | |
|
||
function shouldUseBoldText(report: ReportUtils.OptionData): boolean { | ||
const notificationPreference = report.notificationPreference ?? ReportUtils.getReportNotificationPreference(report); | ||
return report.isUnread === true && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; | ||
return report.isUnread === true && notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE && !ReportUtils.isHiddenForCurrentUser(notificationPreference); | ||
} | ||
|
||
export { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1294,12 +1294,9 @@ function getDefaultNotificationPreferenceForReport(report: OnyxEntry<Report>): V | |||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Get the notification preference given a report | ||||||||||||||||||||||||||||
* Get the notification preference given a report. This should ALWAYS default to 'hidden'. Do not change this! | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
function getReportNotificationPreference(report: OnyxEntry<Report>, shouldDefaltToHidden = true): ValueOf<typeof CONST.REPORT.NOTIFICATION_PREFERENCE> { | ||||||||||||||||||||||||||||
if (!shouldDefaltToHidden) { | ||||||||||||||||||||||||||||
return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? getDefaultNotificationPreferenceForReport(report); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
function getReportNotificationPreference(report: OnyxEntry<Report>): ValueOf<typeof CONST.REPORT.NOTIFICATION_PREFERENCE> { | ||||||||||||||||||||||||||||
return report?.participants?.[currentUserAccountID ?? -1]?.notificationPreference ?? CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -1415,6 +1412,23 @@ function canCreateTaskInReport(report: OnyxEntry<Report>): boolean { | |||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* For all intents and purposes a report that has no notificationPreference at all should be considered "hidden". | ||||||||||||||||||||||||||||
* We will remove the 'hidden' field entirely once the backend changes for https://github.com/Expensify/Expensify/issues/450891 are done. | ||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||
function isHiddenForCurrentUser(notificationPreference: string | null | undefined): boolean; | ||||||||||||||||||||||||||||
function isHiddenForCurrentUser(report: OnyxEntry<Report>): boolean; | ||||||||||||||||||||||||||||
function isHiddenForCurrentUser(reportOrPreference: OnyxEntry<Report> | string | null | undefined): boolean { | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can avoid overloading here because the number of params for the function and the return type are same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very fair, that would be cleaner |
||||||||||||||||||||||||||||
if (typeof reportOrPreference === 'object' && reportOrPreference !== null) { | ||||||||||||||||||||||||||||
const notificationPreference = getReportNotificationPreference(reportOrPreference); | ||||||||||||||||||||||||||||
return isHiddenForCurrentUser(notificationPreference); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
if (reportOrPreference === undefined || reportOrPreference === null || reportOrPreference === '') { | ||||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||||
Comment on lines
+1422
to
+1427
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
NIT |
||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
return reportOrPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||
* Returns true if there are any guides accounts (team.expensify.com) in a list of accountIDs | ||||||||||||||||||||||||||||
* by cross-referencing the accountIDs with personalDetails since guides that are participants | ||||||||||||||||||||||||||||
|
@@ -1426,7 +1440,7 @@ function hasExpensifyGuidesEmails(accountIDs: number[]): boolean { | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
function getMostRecentlyVisitedReport(reports: Array<OnyxEntry<Report>>, reportMetadata: OnyxCollection<ReportMetadata>): OnyxEntry<Report> { | ||||||||||||||||||||||||||||
const filteredReports = reports.filter((report) => { | ||||||||||||||||||||||||||||
const shouldKeep = !isChatThread(report) || getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; | ||||||||||||||||||||||||||||
const shouldKeep = !isChatThread(report) || !isHiddenForCurrentUser(report); | ||||||||||||||||||||||||||||
return shouldKeep && !!report?.reportID && !!(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime); | ||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||
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 | |||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if (shouldExcludeHidden && reportParticipants[accountID]?.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { | ||||||||||||||||||||||||||||
if (shouldExcludeHidden && isHiddenForCurrentUser(reportParticipants[accountID]?.notificationPreference)) { | ||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -8119,7 +8133,7 @@ function canJoinChat(report: OnyxEntry<Report>, parentReportAction: OnyxInputOrE | |||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// If the notification preference of the chat is not hidden that means we have already joined the chat | ||||||||||||||||||||||||||||
if (getReportNotificationPreference(report) !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { | ||||||||||||||||||||||||||||
if (!isHiddenForCurrentUser(report)) { | ||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -8153,7 +8167,7 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boo | |||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if (getReportNotificationPreference(report) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { | ||||||||||||||||||||||||||||
if (isHiddenForCurrentUser(report)) { | ||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -8835,6 +8849,7 @@ export { | |||||||||||||||||||||||||||
getAllReportActionsErrorsAndReportActionThatRequiresAttention, | ||||||||||||||||||||||||||||
hasInvoiceReports, | ||||||||||||||||||||||||||||
getReportMetadata, | ||||||||||||||||||||||||||||
isHiddenForCurrentUser, | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
export type { | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mountiny / @youssef-lr / @c3024 Do you know why this is always defaulting to
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN
instead ofgetDefaultNotificationPreferenceForReport(report)
?Sorry for asking you directly, but @marcaaron is ooo and you reviewed this.
I'm asking because:
#announce
room, we push the notificationPreference of all participants to everyone in the report. This means potentially pushing thousands of participants withnotificationPreference = always
notificationPreference = always
is the default for#announce
rooms (and maybe other rooms)getDefaultNotificationPreferenceForReport
) and not'hidden'
.Does this make sense to you?
Context: https://github.com/Expensify/Expensify/issues/473841#issuecomment-2683501084
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an alternative that would not require to mess with the defaults in the front end: https://github.com/Expensify/Expensify/issues/473841#issuecomment-2695868187