From e8592546037370b914e6d3045ea20969ca5f2968 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 21 Jun 2023 13:15:33 -0400 Subject: [PATCH 1/6] Allow opening report using acocuntIDs instead of emails --- src/libs/actions/Report.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 4cf90dbcb1ab..7f639872e774 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -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}`, @@ -387,6 +388,7 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p const params = { reportID, emailList: participantLoginList ? participantLoginList.join(',') : '', + accountIDList: participantAccountIDList ? participantAccountIDList.join(',') : '', parentReportActionID, }; @@ -492,6 +494,25 @@ function navigateToAndOpenReport(userLogins) { Navigation.dismissModal(reportID); } +/** + * This will find an existing chat, or create a new one if none exists, for the given user or set of users. It will then navigate to this chat. + * + * @param {Array} participantAccountIDs of user logins to start a chat report with. + */ +function navigateToAndOpenReportWithAccountIDs(participantAccountIDs) { + console.log(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 * @@ -1825,6 +1846,7 @@ export { openReport, openReportFromDeepLink, navigateToAndOpenReport, + navigateToAndOpenReportWithAccountIDs, navigateToAndOpenChildReport, updatePolicyRoomNameAndNavigate, clearPolicyRoomNameErrors, From 84f02de4de320e3db95b8566f58fdf1a6cd250c0 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 21 Jun 2023 13:15:51 -0400 Subject: [PATCH 2/6] Allow messaging from profile page --- src/pages/ProfilePage.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index 41a5d153f0cc..e2db0b2409be 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -90,7 +90,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(() => { @@ -200,11 +200,11 @@ function ProfilePage(props) { ) : null} {shouldShowLocalTime && } - {!isCurrentUser && Boolean(login) && ( + {!isCurrentUser && ( Report.navigateToAndOpenReport([login])} + onPress={() => Report.navigateToAndOpenReportWithAccountIDs([accountID])} wrapperStyle={styles.breakAll} shouldShowRightIcon /> From a6c73cc8bac6343587fb9014dd6a16c7746cf5ac Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 21 Jun 2023 13:47:01 -0400 Subject: [PATCH 3/6] Improve function comment --- src/libs/actions/Report.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 7f639872e774..223d803dbc81 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -495,12 +495,11 @@ function navigateToAndOpenReport(userLogins) { } /** - * This will find an existing chat, or create a new one if none exists, for the given user or set of users. It will then navigate to this chat. + * 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) { - console.log(participantAccountIDs); let newChat = {}; const chat = ReportUtils.getChatByParticipants(participantAccountIDs); if (!chat) { From 249376de52352506b38b5bc2e82259f7c523cae5 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 21 Jun 2023 16:29:56 -0400 Subject: [PATCH 4/6] Dont show message option if anonymous user --- src/pages/ProfilePage.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index e2db0b2409be..f8459bc546e7 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -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'; @@ -200,7 +201,7 @@ function ProfilePage(props) { ) : null} {shouldShowLocalTime && } - {!isCurrentUser && ( + {!isCurrentUser && !Session.isAnonymousUser ( Date: Wed, 21 Jun 2023 16:44:43 -0400 Subject: [PATCH 5/6] prettier --- src/pages/ProfilePage.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index f8459bc546e7..1742ab91ce7f 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -201,15 +201,16 @@ function ProfilePage(props) { ) : null} {shouldShowLocalTime && } - {!isCurrentUser && !Session.isAnonymousUser ( - Report.navigateToAndOpenReportWithAccountIDs([accountID])} - wrapperStyle={styles.breakAll} - shouldShowRightIcon - /> - )} + {!isCurrentUser && + !Session.isAnonymousUser( + Report.navigateToAndOpenReportWithAccountIDs([accountID])} + wrapperStyle={styles.breakAll} + shouldShowRightIcon + />, + )} )} {!hasMinimumDetails && isLoading && } From d869710570504dad6ed5204afc004bb945af15da Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Wed, 21 Jun 2023 17:48:02 -0400 Subject: [PATCH 6/6] Fix anonymous user function call --- src/pages/ProfilePage.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index 1742ab91ce7f..2b69c541c44d 100755 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -201,16 +201,15 @@ function ProfilePage(props) { ) : null} {shouldShowLocalTime && } - {!isCurrentUser && - !Session.isAnonymousUser( - Report.navigateToAndOpenReportWithAccountIDs([accountID])} - wrapperStyle={styles.breakAll} - shouldShowRightIcon - />, - )} + {!isCurrentUser && !Session.isAnonymousUser() && ( + Report.navigateToAndOpenReportWithAccountIDs([accountID])} + wrapperStyle={styles.breakAll} + shouldShowRightIcon + /> + )} )} {!hasMinimumDetails && isLoading && }