Skip to content
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

Show pin and message option for current user profile #45783

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading