Skip to content
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
23 changes: 22 additions & 1 deletion src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,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 @@ -387,6 +388,7 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p
const params = {
reportID,
emailList: participantLoginList ? participantLoginList.join(',') : '',
accountIDList: participantAccountIDList ? participantAccountIDList.join(',') : '',
parentReportActionID,
};

Expand Down Expand Up @@ -492,6 +494,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 @@ -1825,6 +1845,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