diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 6f317cc08d29..63093869b590 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..3e541b1dd854 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; @@ -479,10 +480,11 @@ 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 formattedUserLogins = _.map(userLogins, (login) => OptionsListUtils.addSMSDomainIfPhoneNumber(login).toLowerCase()); + const chat = ReportUtils.getChatByParticipantsByLoginList(formattedUserLogins); if (!chat) { + const participantAccountIDs = PersonalDetailsUtils.getAccountIDsByLogins(userLogins); newChat = ReportUtils.buildOptimisticChatReport(participantAccountIDs); } const reportID = chat ? chat.reportID : newChat.reportID;