Skip to content

Commit

Permalink
Merge pull request #21231 from Expensify/dm-from-profile
Browse files Browse the repository at this point in the history
Allow DM'ing from profile even if you don't "know" the user
  • Loading branch information
youssef-lr authored Jun 21, 2023
2 parents 253ec1f + d869710 commit 1745b01
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ function addComment(reportID, text) {
* @param {Object} newReportObject The optimistic report object created when making a new chat, saved as optimistic data
* @param {String} parentReportActionID The parent report action that a thread was created from (only passed for new threads)
* @param {Boolean} isFromDeepLink Whether or not this report is being opened from a deep link
* @param {Array} participantAccountIDList The list of accountIDs that are included in a new chat, not including the user creating it
*/
function openReport(reportID, participantLoginList = [], newReportObject = {}, parentReportActionID = '0', isFromDeepLink = false) {
function openReport(reportID, participantLoginList = [], newReportObject = {}, parentReportActionID = '0', isFromDeepLink = false, participantAccountIDList = []) {
const optimisticReportData = {
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
Expand Down Expand Up @@ -388,6 +389,7 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p
const params = {
reportID,
emailList: participantLoginList ? participantLoginList.join(',') : '',
accountIDList: participantAccountIDList ? participantAccountIDList.join(',') : '',
parentReportActionID,
};

Expand Down Expand Up @@ -494,6 +496,24 @@ function navigateToAndOpenReport(userLogins) {
Navigation.dismissModal(reportID);
}

/**
* This will find an existing chat, or create a new one if none exists, for the given accountID or set of accountIDs. It will then navigate to this chat.
*
* @param {Array} participantAccountIDs of user logins to start a chat report with.
*/
function navigateToAndOpenReportWithAccountIDs(participantAccountIDs) {
let newChat = {};
const chat = ReportUtils.getChatByParticipants(participantAccountIDs);
if (!chat) {
newChat = ReportUtils.buildOptimisticChatReport(participantAccountIDs);
}
const reportID = chat ? chat.reportID : newChat.reportID;

// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
openReport(reportID, [], newChat, '0', false, participantAccountIDs);
Navigation.dismissModal(reportID);
}

/**
* This will navigate to an existing thread, or create a new one if necessary
*
Expand Down Expand Up @@ -1827,6 +1847,7 @@ export {
openReport,
openReportFromDeepLink,
navigateToAndOpenReport,
navigateToAndOpenReportWithAccountIDs,
navigateToAndOpenChildReport,
updatePolicyRoomNameAndNavigate,
clearPolicyRoomNameErrors,
Expand Down
7 changes: 4 additions & 3 deletions src/pages/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {withOnyx} from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import lodashGet from 'lodash/get';
import {parsePhoneNumber} from 'awesome-phonenumber';
import * as Session from '../libs/actions/Session';
import styles from '../styles/styles';
import Text from '../components/Text';
import ONYXKEYS from '../ONYXKEYS';
Expand Down Expand Up @@ -90,7 +91,7 @@ const getPhoneNumber = (details) => {
};

function ProfilePage(props) {
const accountID = lodashGet(props.route.params, 'accountID', 0);
const accountID = Number(lodashGet(props.route.params, 'accountID', 0));

// eslint-disable-next-line rulesdir/prefer-early-return
useEffect(() => {
Expand Down Expand Up @@ -200,11 +201,11 @@ function ProfilePage(props) {
) : null}
{shouldShowLocalTime && <AutoUpdateTime timezone={timezone} />}
</View>
{!isCurrentUser && Boolean(login) && (
{!isCurrentUser && !Session.isAnonymousUser() && (
<MenuItem
title={`${props.translate('common.message')}${displayName}`}
icon={Expensicons.ChatBubble}
onPress={() => Report.navigateToAndOpenReport([login])}
onPress={() => Report.navigateToAndOpenReportWithAccountIDs([accountID])}
wrapperStyle={styles.breakAll}
shouldShowRightIcon
/>
Expand Down

0 comments on commit 1745b01

Please sign in to comment.