diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e619cb3c80dd..545dbf664771 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1095,13 +1095,25 @@ function getReportNotificationPreference(report: OnyxEntry): string | nu } /** - * Returns whether or not the author of the action is this user - * + * Checks if the current user is the action's author */ -function isActionCreator(reportAction: OnyxEntry): boolean { +function isActionCreator(reportAction: OnyxEntry | Partial): boolean { return reportAction?.actorAccountID === currentUserAccountID; } +/** + * Returns the notification preference of the action's child report if it exists. + * Otherwise, calculates it based on the action's authorship. + */ +function getChildReportNotificationPreference(reportAction: OnyxEntry | Partial): NotificationPreference { + const childReportNotificationPreference = reportAction?.childReportNotificationPreference ?? ''; + if (childReportNotificationPreference) { + return childReportNotificationPreference; + } + + return isActionCreator(reportAction) ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; +} + /** * Can only delete if the author is this user and the action is an ADDCOMMENT action or an IOU action in an unsettled report, or if the user is a * policy admin @@ -4533,6 +4545,7 @@ export { shouldAutoFocusOnKeyPress, shouldDisplayThreadReplies, shouldDisableThread, + getChildReportNotificationPreference, }; export type {ExpenseOriginalMessage, OptionData, OptimisticChatReport, OptimisticCreatedReportAction}; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 55e91834a803..90ef14c96128 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -739,7 +739,7 @@ function navigateToAndOpenChildReport(childReportID = '0', parentReportAction: P '', undefined, undefined, - CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + ReportUtils.getChildReportNotificationPreference(parentReportAction), parentReportAction.reportActionID, parentReportID, ); diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index edf6b65b2f4a..2e6fbf61240d 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -109,9 +109,7 @@ function HeaderView(props) { const isAutomatedExpensifyAccount = ReportUtils.hasSingleParticipant(props.report) && ReportUtils.hasAutomatedExpensifyAccountIDs(participants); const parentReportAction = ReportActionsUtils.getParentReportAction(props.report); const isCanceledTaskReport = ReportUtils.isCanceledTaskReport(props.report, parentReportAction); - const lastVisibleMessage = ReportActionsUtils.getLastVisibleMessage(props.report.reportID); const isWhisperAction = ReportActionsUtils.isWhisperAction(parentReportAction); - const isEmptyChat = !props.report.lastMessageText && !props.report.lastMessageTranslationKey && !lastVisibleMessage.lastMessageText && !lastVisibleMessage.lastMessageTranslationKey; const isUserCreatedPolicyRoom = ReportUtils.isUserCreatedPolicyRoom(props.report); const isPolicyMember = useMemo(() => !_.isEmpty(props.policy), [props.policy]); const canLeaveRoom = ReportUtils.canLeaveRoom(props.report, isPolicyMember); @@ -153,7 +151,7 @@ function HeaderView(props) { ), ); - const canJoinOrLeave = (isChatThread && !isEmptyChat) || isUserCreatedPolicyRoom || canLeaveRoom; + const canJoinOrLeave = isChatThread || isUserCreatedPolicyRoom || canLeaveRoom; const canJoin = canJoinOrLeave && !isWhisperAction && props.report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; const canLeave = canJoinOrLeave && ((isChatThread && props.report.notificationPreference.length) || isUserCreatedPolicyRoom || canLeaveRoom); if (canJoin) { diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index f22eda58ce7f..eb48dafbe584 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -156,14 +156,10 @@ export default [ successTextTranslateKey: '', successIcon: null, shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID) => { - let childReportNotificationPreference = lodashGet(reportAction, 'childReportNotificationPreference', ''); - if (!childReportNotificationPreference) { - const isActionCreator = ReportUtils.isActionCreator(reportAction); - childReportNotificationPreference = isActionCreator ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; - } + const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, reportID); - const subscribed = childReportNotificationPreference !== 'hidden'; + const subscribed = childReportNotificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; const isCommentAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportUtils.isThreadFirstChat(reportAction, reportID); const isReportPreviewAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; const isIOUAction = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && !ReportActionsUtils.isSplitBillAction(reportAction); @@ -171,11 +167,7 @@ export default [ return !subscribed && !isWhisperAction && (isCommentAction || isReportPreviewAction || isIOUAction) && (!isDeletedAction || shouldDisplayThreadReplies); }, onPress: (closePopover, {reportAction, reportID}) => { - let childReportNotificationPreference = lodashGet(reportAction, 'childReportNotificationPreference', ''); - if (!childReportNotificationPreference) { - const isActionCreator = ReportUtils.isActionCreator(reportAction); - childReportNotificationPreference = isActionCreator ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; - } + const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction); if (closePopover) { hideContextMenu(false, () => { ReportActionComposeFocusManager.focus(); @@ -196,14 +188,10 @@ export default [ successTextTranslateKey: '', successIcon: null, shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID) => { - let childReportNotificationPreference = lodashGet(reportAction, 'childReportNotificationPreference', ''); - if (!childReportNotificationPreference) { - const isActionCreator = ReportUtils.isActionCreator(reportAction); - childReportNotificationPreference = isActionCreator ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; - } + const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction); const isDeletedAction = ReportActionsUtils.isDeletedAction(reportAction); const shouldDisplayThreadReplies = ReportUtils.shouldDisplayThreadReplies(reportAction, reportID); - const subscribed = childReportNotificationPreference !== 'hidden'; + const subscribed = childReportNotificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; if (type !== CONST.CONTEXT_MENU_TYPES.REPORT_ACTION) { return false; } @@ -213,11 +201,7 @@ export default [ return subscribed && (isCommentAction || isReportPreviewAction || isIOUAction) && (!isDeletedAction || shouldDisplayThreadReplies); }, onPress: (closePopover, {reportAction, reportID}) => { - let childReportNotificationPreference = lodashGet(reportAction, 'childReportNotificationPreference', ''); - if (!childReportNotificationPreference) { - const isActionCreator = ReportUtils.isActionCreator(reportAction); - childReportNotificationPreference = isActionCreator ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; - } + const childReportNotificationPreference = ReportUtils.getChildReportNotificationPreference(reportAction); if (closePopover) { hideContextMenu(false, () => { ReportActionComposeFocusManager.focus();