diff --git a/src/components/PromotedActionsBar.tsx b/src/components/PromotedActionsBar.tsx index 1aefe941011b..e3c795045048 100644 --- a/src/components/PromotedActionsBar.tsx +++ b/src/components/PromotedActionsBar.tsx @@ -27,7 +27,7 @@ type PromotedAction = { type BasePromotedActions = typeof CONST.PROMOTED_ACTIONS.PIN | typeof CONST.PROMOTED_ACTIONS.SHARE | typeof CONST.PROMOTED_ACTIONS.JOIN; type PromotedActionsType = Record PromotedAction> & { - message: (params: {accountID?: number; login?: string}) => PromotedAction; + message: (params: {reportID?: string; accountID?: number; login?: string}) => PromotedAction; } & { hold: (params: {isTextHold: boolean; reportAction: ReportAction | undefined}) => PromotedAction; }; @@ -50,11 +50,16 @@ const PromotedActions = { ReportActions.joinRoom(report); }), }), - message: ({accountID, login}) => ({ + message: ({reportID, accountID, login}) => ({ key: CONST.PROMOTED_ACTIONS.MESSAGE, icon: Expensicons.CommentBubbles, text: Localize.translateLocal('common.message'), onSelected: () => { + if (reportID) { + Navigation.dismissModal(reportID); + return; + } + // The accountID might be optimistic, so we should use the login if we have it if (login) { ReportActions.navigateToAndOpenReport([login]); diff --git a/src/pages/ProfilePage.tsx b/src/pages/ProfilePage.tsx index b7b36d0dab45..d172e2089983 100755 --- a/src/pages/ProfilePage.tsx +++ b/src/pages/ProfilePage.tsx @@ -84,21 +84,22 @@ function ProfilePage({route}: ProfilePageProps) { selector: (account) => account?.guideCalendarLink, }); + const accountID = Number(route.params?.accountID ?? -1); + const isCurrentUser = session?.accountID === accountID; const reportKey = useMemo(() => { - const accountID = Number(route.params?.accountID ?? -1); - const reportID = ReportUtils.getChatByParticipants(session?.accountID ? [accountID, session.accountID] : [], reports)?.reportID ?? '-1'; + const reportID = isCurrentUser + ? ReportUtils.findSelfDMReportID() + : ReportUtils.getChatByParticipants(session?.accountID ? [accountID, session.accountID] : [], reports)?.reportID ?? '-1'; - if ((!!session && Number(session?.accountID) === accountID) || SessionActions.isAnonymousUser() || !reportID) { + if (SessionActions.isAnonymousUser() || !reportID) { return `${ONYXKEYS.COLLECTION.REPORT}0` as const; } return `${ONYXKEYS.COLLECTION.REPORT}${reportID}` as const; - }, [reports, route.params?.accountID, session]); + }, [accountID, isCurrentUser, reports, session]); const [report] = useOnyx(reportKey); const styles = useThemeStyles(); const {translate, formatPhoneNumber} = useLocalize(); - const accountID = Number(route.params?.accountID ?? -1); - const isCurrentUser = session?.accountID === accountID; const isValidAccountID = ValidationUtils.isValidAccountRoute(accountID); const loginParams = route.params?.login; @@ -173,8 +174,9 @@ function ProfilePage({route}: ProfilePageProps) { result.push(PromotedActions.pin(report)); } - if (!isCurrentUser && !SessionActions.isAnonymousUser()) { - result.push(PromotedActions.message({accountID, login: loginParams})); + // If it's a self DM, we only want to show the Message button if the self DM report exists because we don't want to optimistically create a report for self DM + if ((!isCurrentUser || report) && !SessionActions.isAnonymousUser()) { + result.push(PromotedActions.message({reportID: report?.reportID, accountID, login: loginParams})); } return result; }, [accountID, isCurrentUser, loginParams, report]);