Skip to content

Commit

Permalink
Merge pull request #45783 from bernhardoj/fix/45654-missing-pin-optio…
Browse files Browse the repository at this point in the history
…n-for-self-dm

Show pin and message option for current user profile
  • Loading branch information
nkuoch authored Jul 22, 2024
2 parents c2ded1d + 3c599c7 commit ccf9591
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/components/PromotedActionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<BasePromotedActions, (report: OnyxReport) => 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;
};
Expand All @@ -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]);
Expand Down
18 changes: 10 additions & 8 deletions src/pages/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit ccf9591

Please sign in to comment.