From 54caadbfe03ee41f23bed3cc9598be533376052f Mon Sep 17 00:00:00 2001 From: Monil Bhavsar Date: Thu, 22 Jun 2023 01:56:48 +0530 Subject: [PATCH 1/4] Search for chats by emails --- src/libs/ReportUtils.js | 23 +++++++++++++++++++++++ src/libs/actions/Report.js | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 6f317cc08d29..1c9eefac8826 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1970,6 +1970,28 @@ function getChatByParticipants(newParticipantList) { }); } +/** + * Attempts to find a report in onyx with the provided email list of participants. Does not include threads + * This is temporary function while Migrating from PersonalDetails to PersonalDetailsList + * + * @deprecated - use getChatByParticipants() + * + * @param {Array} participantsloginList + * @returns {Array|undefined} + */ +function getChatByParticipantsByLoginList(participantsloginList) { + participantsloginList.sort(); + return _.find(allReports, (report) => { + // If the report has been deleted, or there are no participants (like an empty #admins room) then skip it + if (!report || !report.participants || isThread(report)) { + return false; + } + + // Only return the room if it has all the participants and is not a policy room + return !isUserCreatedPolicyRoom(report) && _.isEqual(participantsloginList, _.sortBy(report.participants)); + }); +} + /** * Attempts to find a report in onyx with the provided list of participants in given policy * @param {Array} newParticipantList @@ -2295,6 +2317,7 @@ export { buildOptimisticTaskCommentReportAction, shouldReportBeInOptionList, getChatByParticipants, + getChatByParticipantsByLoginList, getChatByParticipantsAndPolicy, getAllPolicyReports, getIOUReportActionMessage, diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 4cf90dbcb1ab..5730e3b62a07 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -479,10 +479,10 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p * @param {Array} userLogins list of user logins to start a chat report with. */ function navigateToAndOpenReport(userLogins) { - const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins(userLogins); let newChat = {}; - const chat = ReportUtils.getChatByParticipants(participantAccountIDs); + const chat = ReportUtils.getChatByParticipantsByLoginList(userLogins); if (!chat) { + const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins(userLogins); newChat = ReportUtils.buildOptimisticChatReport(participantAccountIDs); } const reportID = chat ? chat.reportID : newChat.reportID; From a9d61c3a5f715e866c8825a2bd6ccd20ec5e4bfd Mon Sep 17 00:00:00 2001 From: Monil Bhavsar Date: Thu, 22 Jun 2023 02:15:15 +0530 Subject: [PATCH 2/4] Address review Update comment Co-authored-by: Carlos Martins --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 1c9eefac8826..ba5c469a6ebe 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1972,7 +1972,7 @@ function getChatByParticipants(newParticipantList) { /** * Attempts to find a report in onyx with the provided email list of participants. Does not include threads - * This is temporary function while Migrating from PersonalDetails to PersonalDetailsList + * This is temporary function while migrating from PersonalDetails to PersonalDetailsList * * @deprecated - use getChatByParticipants() * From f50e88eb63702e915a0326e6577a0ed7da0b3cc7 Mon Sep 17 00:00:00 2001 From: Monil Bhavsar Date: Thu, 22 Jun 2023 02:58:34 +0530 Subject: [PATCH 3/4] Format before comparing --- src/libs/ReportUtils.js | 8 ++++---- src/libs/actions/Report.js | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 1c9eefac8826..000ef6fae31e 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1976,11 +1976,11 @@ function getChatByParticipants(newParticipantList) { * * @deprecated - use getChatByParticipants() * - * @param {Array} participantsloginList + * @param {Array} participantsLoginList * @returns {Array|undefined} */ -function getChatByParticipantsByLoginList(participantsloginList) { - participantsloginList.sort(); +function getChatByParticipantsByLoginList(participantsLoginList) { + participantsLoginList.sort(); return _.find(allReports, (report) => { // If the report has been deleted, or there are no participants (like an empty #admins room) then skip it if (!report || !report.participants || isThread(report)) { @@ -1988,7 +1988,7 @@ function getChatByParticipantsByLoginList(participantsloginList) { } // Only return the room if it has all the participants and is not a policy room - return !isUserCreatedPolicyRoom(report) && _.isEqual(participantsloginList, _.sortBy(report.participants)); + return !isUserCreatedPolicyRoom(report) && _.isEqual(participantsLoginList, _.sortBy(report.participants)); }); } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 5730e3b62a07..98a1a46732b4 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -25,6 +25,7 @@ import * as UserUtils from '../UserUtils'; import * as Welcome from './Welcome'; import * as PersonalDetailsUtils from '../PersonalDetailsUtils'; import SidebarUtils from '../SidebarUtils'; +import * as OptionsListUtils from "../OptionsListUtils"; let currentUserEmail; let currentUserAccountID; @@ -480,7 +481,8 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p */ function navigateToAndOpenReport(userLogins) { let newChat = {}; - const chat = ReportUtils.getChatByParticipantsByLoginList(userLogins); + const formattedUserLogins = _.map(userLogins, login => OptionsListUtils.addSMSDomainIfPhoneNumber(login).toLowerCase()); + const chat = ReportUtils.getChatByParticipantsByLoginList(formattedUserLogins); if (!chat) { const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins(userLogins); newChat = ReportUtils.buildOptimisticChatReport(participantAccountIDs); From 398b6368f874de24ade8a2f6685c78f4ca211790 Mon Sep 17 00:00:00 2001 From: Monil Bhavsar Date: Thu, 22 Jun 2023 03:04:46 +0530 Subject: [PATCH 4/4] Lint fix --- src/libs/actions/Report.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 98a1a46732b4..3e541b1dd854 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -25,7 +25,7 @@ import * as UserUtils from '../UserUtils'; import * as Welcome from './Welcome'; import * as PersonalDetailsUtils from '../PersonalDetailsUtils'; import SidebarUtils from '../SidebarUtils'; -import * as OptionsListUtils from "../OptionsListUtils"; +import * as OptionsListUtils from '../OptionsListUtils'; let currentUserEmail; let currentUserAccountID; @@ -481,7 +481,7 @@ function openReport(reportID, participantLoginList = [], newReportObject = {}, p */ function navigateToAndOpenReport(userLogins) { let newChat = {}; - const formattedUserLogins = _.map(userLogins, login => OptionsListUtils.addSMSDomainIfPhoneNumber(login).toLowerCase()); + const formattedUserLogins = _.map(userLogins, (login) => OptionsListUtils.addSMSDomainIfPhoneNumber(login).toLowerCase()); const chat = ReportUtils.getChatByParticipantsByLoginList(formattedUserLogins); if (!chat) { const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins(userLogins);