From 3c599c75fa1981cb159d0b2c888c74c2857f52e4 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 19 Jul 2024 22:20:18 +0800 Subject: [PATCH] show pin and message option for current user profile --- src/components/PromotedActionsBar.tsx | 9 +++++++-- src/pages/ProfilePage.tsx | 18 ++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) 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]);