From 26cfe6452e4a2464fbfc8f91868204dab8dca28d Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Fri, 3 Nov 2023 16:45:34 +0000 Subject: [PATCH 01/11] Using visibleChatMemberList instead of participants ids --- src/libs/ReportUtils.js | 24 ++++++++++++++++++++++++ src/pages/ReportDetailsPage.js | 2 +- src/pages/ReportParticipantsPage.js | 2 +- src/pages/ShareCodePage.js | 2 +- src/pages/reportPropTypes.js | 3 +++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 1ab715b66aeb..8c93f8b778ff 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4048,6 +4048,29 @@ function getParticipantsIDs(report) { return participants; } +/** + * Returns an array of the visible member Ids of a report + * + * @param {Object} report + * @returns {Array} + */ +function getVisibleMembersIDs(report) { + if (!report) { + return []; + } + + const visibleChatMembers = report.visibleChatMemberList || []; + + // Build visibleChatMembers list for IOU/expense reports + if (isMoneyRequestReport(report)) { + return _.chain([report.managerID, report.ownerAccountID, ...visibleChatMembers]) + .compact() + .uniq() + .value(); + } + return visibleChatMembers; +} + /** * Return iou report action display message * @@ -4280,6 +4303,7 @@ export { getTransactionDetails, getTaskAssigneeChatOnyxData, getParticipantsIDs, + getVisibleMembersIDs, canEditMoneyRequest, canEditFieldOfMoneyRequest, buildTransactionThread, diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index ef28102cc144..a0fe8d6a35b7 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -74,7 +74,7 @@ function ReportDetailsPage(props) { const chatRoomSubtitle = useMemo(() => ReportUtils.getChatRoomSubtitle(props.report), [props.report, policy]); const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(props.report); const canLeaveRoom = useMemo(() => ReportUtils.canLeaveRoom(props.report, !_.isEmpty(policy)), [policy, props.report]); - const participants = useMemo(() => ReportUtils.getParticipantsIDs(props.report), [props.report]); + const participants = useMemo(() => ReportUtils.getVisibleMembersIDs(props.report), [props.report]); const isGroupDMChat = useMemo(() => ReportUtils.isDM(props.report) && participants.length > 1, [props.report, participants.length]); diff --git a/src/pages/ReportParticipantsPage.js b/src/pages/ReportParticipantsPage.js index c2179c53126b..9601375f8cc3 100755 --- a/src/pages/ReportParticipantsPage.js +++ b/src/pages/ReportParticipantsPage.js @@ -55,7 +55,7 @@ const defaultProps = { * @return {Array} */ const getAllParticipants = (report, personalDetails, translate) => - _.chain(ReportUtils.getParticipantsIDs(report)) + _.chain(ReportUtils.getVisibleMembersIDs(report)) .map((accountID, index) => { const userPersonalDetail = lodashGet(personalDetails, accountID, {displayName: personalDetails.displayName || translate('common.hidden'), avatar: ''}); const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login || '') || translate('common.hidden'); diff --git a/src/pages/ShareCodePage.js b/src/pages/ShareCodePage.js index b2bc32b381ce..64629cdfd956 100644 --- a/src/pages/ShareCodePage.js +++ b/src/pages/ShareCodePage.js @@ -54,7 +54,7 @@ class ShareCodePage extends React.Component { } if (ReportUtils.isMoneyRequestReport(this.props.report)) { // generate subtitle from participants - return _.map(ReportUtils.getParticipantsIDs(this.props.report), (accountID) => ReportUtils.getDisplayNameForParticipant(accountID)).join(' & '); + return _.map(ReportUtils.getVisibleMembersIDs(this.props.report), (accountID) => ReportUtils.getDisplayNameForParticipant(accountID)).join(' & '); } if (isReport) { diff --git a/src/pages/reportPropTypes.js b/src/pages/reportPropTypes.js index a3bbbda5c0bf..e0e03d26bbf6 100644 --- a/src/pages/reportPropTypes.js +++ b/src/pages/reportPropTypes.js @@ -50,6 +50,9 @@ export default PropTypes.shape({ /** List of accountIDs of participants of the report */ participantAccountIDs: PropTypes.arrayOf(PropTypes.number), + /** List of accountIDs of visible members of the report */ + visibleChatMemberList: PropTypes.arrayOf(PropTypes.number), + /** Linked policy's ID */ policyID: PropTypes.string, From 9f42a57a6e6e91f521195f173e0c3caa9ec28342 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Mon, 13 Nov 2023 12:14:44 +0000 Subject: [PATCH 02/11] Removing getParticipantsIDs since it is not being used anymore. --- src/libs/ReportUtils.js | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index c700827b5eb7..0feb24542e79 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4056,29 +4056,6 @@ function getTaskAssigneeChatOnyxData(accountID, assigneeAccountID, taskReportID, }; } -/** - * Returns an array of the participants Ids of a report - * - * @param {Object} report - * @returns {Array} - */ -function getParticipantsIDs(report) { - if (!report) { - return []; - } - - const participants = report.participantAccountIDs || []; - - // Build participants list for IOU/expense reports - if (isMoneyRequestReport(report)) { - return _.chain([report.managerID, report.ownerAccountID, ...participants]) - .compact() - .uniq() - .value(); - } - return participants; -} - /** * Returns an array of the visible member Ids of a report * @@ -4345,7 +4322,6 @@ export { getTransactionReportName, getTransactionDetails, getTaskAssigneeChatOnyxData, - getParticipantsIDs, getVisibleMembersIDs, canEditMoneyRequest, canEditFieldOfMoneyRequest, From b493348bb12dfb9813a97cb986acded6770cacf7 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Sat, 18 Nov 2023 16:02:10 +0000 Subject: [PATCH 03/11] renaming visibleChatMembers variable --- src/libs/ReportUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index dfcb97ab1469..18de01af288a 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4107,16 +4107,16 @@ function getVisibleMembersIDs(report) { return []; } - const visibleChatMembers = report.visibleChatMemberList || []; + const visibleChatMembersIDs = report.visibleChatMemberList || []; // Build visibleChatMembers list for IOU/expense reports if (isMoneyRequestReport(report)) { - return _.chain([report.managerID, report.ownerAccountID, ...visibleChatMembers]) + return _.chain([report.managerID, report.ownerAccountID, ...visibleChatMembersIDs]) .compact() .uniq() .value(); } - return visibleChatMembers; + return visibleChatMembersIDs; } /** From 6ea03da8d0bdc10dce31b8e4caef7a8682170f16 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa <5201282+rlinoz@users.noreply.github.com> Date: Wed, 22 Nov 2023 10:10:08 -0300 Subject: [PATCH 04/11] more explicit comment Co-authored-by: Marc Glasser --- 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 18de01af288a..c616f2935c11 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4097,7 +4097,7 @@ function getTaskAssigneeChatOnyxData(accountID, assigneeAccountID, taskReportID, } /** - * Returns an array of the visible member Ids of a report + * Returns an array of the visible member accountIDs for a report * * @param {Object} report * @returns {Array} From 0c92a82b896fe53541ab8ba167d71440166f11e6 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Wed, 22 Nov 2023 11:40:56 -0300 Subject: [PATCH 05/11] renaming visibleChatMemberList --- src/libs/ReportUtils.js | 10 +++++----- src/pages/ReportDetailsPage.js | 2 +- src/pages/ReportParticipantsPage.js | 2 +- src/pages/ShareCodePage.js | 2 +- src/pages/reportPropTypes.js | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index bd6a5b94c8a3..dd227dc43ab5 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4103,21 +4103,21 @@ function getTaskAssigneeChatOnyxData(accountID, assigneeAccountID, taskReportID, * @param {Object} report * @returns {Array} */ -function getVisibleMembersIDs(report) { +function getVisibleMemberIDs(report) { if (!report) { return []; } - const visibleChatMembersIDs = report.visibleChatMemberList || []; + const visibleChatMemberAccountIDs = report.visibleChatMemberAccountIDs || []; // Build visibleChatMembers list for IOU/expense reports if (isMoneyRequestReport(report)) { - return _.chain([report.managerID, report.ownerAccountID, ...visibleChatMembersIDs]) + return _.chain([report.managerID, report.ownerAccountID, ...visibleChatMemberAccountIDs]) .compact() .uniq() .value(); } - return visibleChatMembersIDs; + return visibleChatMemberAccountIDs; } /** @@ -4418,7 +4418,7 @@ export { getTransactionReportName, getTransactionDetails, getTaskAssigneeChatOnyxData, - getVisibleMembersIDs, + getVisibleMemberIDs, canEditMoneyRequest, canEditFieldOfMoneyRequest, buildTransactionThread, diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 9b0c5f9a08e9..284f32a88aad 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -73,7 +73,7 @@ function ReportDetailsPage(props) { // eslint-disable-next-line react-hooks/exhaustive-deps -- policy is a dependency because `getChatRoomSubtitle` calls `getPolicyName` which in turn retrieves the value from the `policy` value stored in Onyx const chatRoomSubtitle = useMemo(() => ReportUtils.getChatRoomSubtitle(props.report), [props.report, policy]); const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(props.report); - const participants = useMemo(() => ReportUtils.getVisibleMembersIDs(props.report), [props.report]); + const participants = useMemo(() => ReportUtils.getVisibleMemberIDs(props.report), [props.report]); const isGroupDMChat = useMemo(() => ReportUtils.isDM(props.report) && participants.length > 1, [props.report, participants.length]); diff --git a/src/pages/ReportParticipantsPage.js b/src/pages/ReportParticipantsPage.js index ec40783fc394..aa49140020a9 100755 --- a/src/pages/ReportParticipantsPage.js +++ b/src/pages/ReportParticipantsPage.js @@ -55,7 +55,7 @@ const defaultProps = { * @return {Array} */ const getAllParticipants = (report, personalDetails, translate) => - _.chain(ReportUtils.getVisibleMembersIDs(report)) + _.chain(ReportUtils.getVisibleMemberIDs(report)) .map((accountID, index) => { const userPersonalDetail = lodashGet(personalDetails, accountID, {displayName: personalDetails.displayName || translate('common.hidden'), avatar: ''}); const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login || '') || translate('common.hidden'); diff --git a/src/pages/ShareCodePage.js b/src/pages/ShareCodePage.js index 7039e524f1a6..fee70b464426 100644 --- a/src/pages/ShareCodePage.js +++ b/src/pages/ShareCodePage.js @@ -55,7 +55,7 @@ class ShareCodePage extends React.Component { } if (ReportUtils.isMoneyRequestReport(this.props.report)) { // generate subtitle from participants - return _.map(ReportUtils.getVisibleMembersIDs(this.props.report), (accountID) => ReportUtils.getDisplayNameForParticipant(accountID)).join(' & '); + return _.map(ReportUtils.getVisibleMemberIDs(this.props.report), (accountID) => ReportUtils.getDisplayNameForParticipant(accountID)).join(' & '); } if (isReport) { diff --git a/src/pages/reportPropTypes.js b/src/pages/reportPropTypes.js index e0e03d26bbf6..7a0b588af474 100644 --- a/src/pages/reportPropTypes.js +++ b/src/pages/reportPropTypes.js @@ -51,7 +51,7 @@ export default PropTypes.shape({ participantAccountIDs: PropTypes.arrayOf(PropTypes.number), /** List of accountIDs of visible members of the report */ - visibleChatMemberList: PropTypes.arrayOf(PropTypes.number), + visibleChatMemberAccountIDs: PropTypes.arrayOf(PropTypes.number), /** Linked policy's ID */ policyID: PropTypes.string, From 3abd2963dd40497d8dc477068295df5edceb2e47 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Wed, 22 Nov 2023 14:58:13 -0300 Subject: [PATCH 06/11] adding getParticipantsIDs back since it might break forks/branches, and deprecating it --- src/libs/ReportUtils.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index dd227dc43ab5..1bef28cbc6ba 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4097,6 +4097,31 @@ function getTaskAssigneeChatOnyxData(accountID, assigneeAccountID, taskReportID, }; } +/** + * Returns an array of the participants Ids of a report + * + * @param {Object} report + * @returns {Array} + * + * @deprecated Use getVisibleMemberIDs instead + */ +function getParticipantsIDs(report) { + if (!report) { + return []; + } + + const participants = report.participantAccountIDs || []; + + // Build participants list for IOU/expense reports + if (isMoneyRequestReport(report)) { + return _.chain([report.managerID, report.ownerAccountID, ...participants]) + .compact() + .uniq() + .value(); + } + return participants; +} + /** * Returns an array of the visible member accountIDs for a report * @@ -4418,6 +4443,7 @@ export { getTransactionReportName, getTransactionDetails, getTaskAssigneeChatOnyxData, + getParticipantsIDs, getVisibleMemberIDs, canEditMoneyRequest, canEditFieldOfMoneyRequest, From 4a7cc0b8005c2bf4b4d1d531fe4c2bd1beffda72 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Tue, 28 Nov 2023 14:28:00 -0300 Subject: [PATCH 07/11] fix lint --- src/libs/ReportUtils.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0cf872ab7339..225e67bbaacf 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4087,17 +4087,14 @@ function getParticipantsIDs(report: OnyxEntry): number[] { } /** - * Returns an array of the visible member accountIDs for a report - * - * @param {Object} report - * @returns {Array} + * Returns an array of the visible member accountIDs for a report* */ function getVisibleMemberIDs(report: OnyxEntry): number[] { if (!report) { return []; } - const visibleChatMemberAccountIDs = report.visibleChatMemberAccountIDs || []; + const visibleChatMemberAccountIDs = report.visibleChatMemberAccountIDs ?? []; // Build participants list for IOU/expense reports if (isMoneyRequestReport(report)) { From 329f4bed262b00671b58ec92479ed4de2896cb31 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Wed, 29 Nov 2023 09:09:25 -0300 Subject: [PATCH 08/11] prettier --- src/libs/ReportUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 225e67bbaacf..4c508bb9798e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4105,7 +4105,6 @@ function getVisibleMemberIDs(report: OnyxEntry): number[] { return visibleChatMemberAccountIDs; } - /** * Return iou report action display message */ From 4952bc3a830b799196d1e2354e4668524c1ac2cb Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Fri, 8 Dec 2023 17:01:35 -0300 Subject: [PATCH 09/11] Updated optimistic data for actions that change participantAccountIDs to update visibleChatMemberAccountIDs as well; Changed a few places that should rely on visibleChatMemberAccountIDs instead of participants. --- src/libs/GroupChatUtils.ts | 2 +- src/libs/OptionsListUtils.js | 4 ++-- src/libs/ReportUtils.ts | 19 +++++++++++++++++-- src/libs/SidebarUtils.ts | 6 +++--- src/libs/actions/Policy.js | 9 ++++++++- src/libs/actions/Report.js | 11 +++++++++-- src/libs/actions/Task.js | 4 +++- src/pages/RoomInvitePage.js | 2 +- src/pages/RoomMembersPage.js | 2 +- 9 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/libs/GroupChatUtils.ts b/src/libs/GroupChatUtils.ts index db64f6574824..9e09ec9a062d 100644 --- a/src/libs/GroupChatUtils.ts +++ b/src/libs/GroupChatUtils.ts @@ -14,7 +14,7 @@ Onyx.connect({ * Returns the report name if the report is a group chat */ function getGroupChatName(report: Report): string | undefined { - const participants = report.participantAccountIDs ?? []; + const participants = report.visibleChatMemberAccountIDs ?? []; const isMultipleParticipantReport = participants.length > 1; const participantPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(participants, allPersonalDetails ?? {}); // @ts-expect-error Error will gone when OptionsListUtils will be migrated to Typescript diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 13586b6c5d2e..220bbeb825c8 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -499,7 +499,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { result.isPinned = report.isPinned; result.iouReportID = report.iouReportID; result.keyForList = String(report.reportID); - result.tooltipText = ReportUtils.getReportParticipantsTitle(report.participantAccountIDs || []); + result.tooltipText = ReportUtils.getReportParticipantsTitle(report.visibleChatMemberAccountIDs || []); result.hasOutstandingIOU = report.hasOutstandingIOU; result.isWaitingOnBankAccount = report.isWaitingOnBankAccount; result.policyID = report.policyID; @@ -1154,7 +1154,7 @@ function getOptions( const isTaskReport = ReportUtils.isTaskReport(report); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); - const accountIDs = report.participantAccountIDs || []; + const accountIDs = report.visibleChatMemberAccountIDs || []; if (isPolicyExpenseChat && report.isOwnPolicyExpenseChat && !includeOwnedWorkspaceChats) { return; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ccf4ece986df..b0ed3571b99a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -211,6 +211,7 @@ type OptimisticChatReport = Pick< | 'parentReportActionID' | 'parentReportID' | 'participantAccountIDs' + | 'visibleChatMemberAccountIDs' | 'policyID' | 'reportID' | 'reportName' @@ -265,6 +266,7 @@ type OptimisticTaskReport = Pick< | 'description' | 'ownerAccountID' | 'participantAccountIDs' + | 'visibleChatMemberAccountIDs' | 'managerID' | 'type' | 'parentReportID' @@ -303,6 +305,7 @@ type OptimisticIOUReport = Pick< | 'managerID' | 'ownerAccountID' | 'participantAccountIDs' + | 'visibleChatMemberAccountIDs' | 'reportID' | 'state' | 'stateNum' @@ -2551,6 +2554,10 @@ function buildOptimisticIOUReport(payeeAccountID: number, payerAccountID: number const formattedTotal = CurrencyUtils.convertToDisplayString(total, currency); const personalDetails = getPersonalDetailsForAccountID(payerAccountID); const payerEmail = 'login' in personalDetails ? personalDetails.login : ''; + + // When creating a report the participantsAccountIDs and visibleChatMemberAccountIDs are the same + const participantsAccountIDs = [payeeAccountID, payerAccountID] + return { // If we're sending money, hasOutstandingIOU should be false hasOutstandingIOU: !isSendingMoney, @@ -2560,7 +2567,8 @@ function buildOptimisticIOUReport(payeeAccountID: number, payerAccountID: number currency, managerID: payerAccountID, ownerAccountID: payeeAccountID, - participantAccountIDs: [payeeAccountID, payerAccountID], + participantAccountIDs: participantsAccountIDs, + visibleChatMemberAccountIDs: participantsAccountIDs, reportID: generateReportID(), state: CONST.REPORT.STATE.SUBMITTED, stateNum: isSendingMoney ? CONST.REPORT.STATE_NUM.SUBMITTED : CONST.REPORT.STATE_NUM.PROCESSING, @@ -3093,7 +3101,9 @@ function buildOptimisticChatReport( ownerAccountID: ownerAccountID || CONST.REPORT.OWNER_ACCOUNT_ID_FAKE, parentReportActionID, parentReportID, + // When creating a report the participantsAccountIDs and visibleChatMemberAccountIDs are the same participantAccountIDs: participantList, + visibleChatMemberAccountIDs: participantList, policyID, reportID: generateReportID(), reportName, @@ -3295,12 +3305,17 @@ function buildOptimisticTaskReport( description?: string, policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE, ): OptimisticTaskReport { + + // When creating a report the participantsAccountIDs and visibleChatMemberAccountIDs are the same + const participantsAccountIDs = assigneeAccountID && assigneeAccountID !== ownerAccountID ? [assigneeAccountID] : []; + return { reportID: generateReportID(), reportName: title, description, ownerAccountID, - participantAccountIDs: assigneeAccountID && assigneeAccountID !== ownerAccountID ? [assigneeAccountID] : [], + participantAccountIDs: participantsAccountIDs, + visibleChatMemberAccountIDs: participantsAccountIDs, managerID: assigneeAccountID, type: CONST.REPORT.TYPE.TASK, parentReportID, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 8657a695c7e5..a8368f18b902 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -125,10 +125,10 @@ function getOrderedReportIDs( [currentReportId, allReports, betas, policies, priorityMode, allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentReportId}`]?.length || 1], (key, value: unknown) => { /** - * Exclude 'participantAccountIDs', 'participants' and 'lastMessageText' not to overwhelm a cached key value with huge data, + * Exclude some properties not to overwhelm a cached key value with huge data, * which we don't need to store in a cacheKey */ - if (key === 'participantAccountIDs' || key === 'participants' || key === 'lastMessageText') { + if (key === 'participantAccountIDs' || key === 'participants' || key === 'lastMessageText' || key === 'visibleChatMemberAccountIDs') { return undefined; } @@ -300,7 +300,7 @@ function getOptionData( result.isPinned = report.isPinned; result.iouReportID = report.iouReportID; result.keyForList = String(report.reportID); - result.tooltipText = ReportUtils.getReportParticipantsTitle(report.participantAccountIDs ?? []); + result.tooltipText = ReportUtils.getReportParticipantsTitle(report.visibleChatMemberAccountIDs ?? []); result.hasOutstandingIOU = report.hasOutstandingIOU; result.hasOutstandingChildRequest = report.hasOutstandingChildRequest; result.parentReportID = report.parentReportID ?? ''; diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 04f62ab0c393..a4a3ef3557a4 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -277,11 +277,15 @@ function buildAnnounceRoomMembersOnyxData(policyID, accountIDs) { onyxFailureData: [], }; + // Everyone in special policy rooms is visible + const participantAccountIDs = [...announceReport.participantAccountIDs, ...accountIDs] + announceRoomMembers.onyxOptimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, value: { - participantAccountIDs: [...announceReport.participantAccountIDs, ...accountIDs], + participantAccountIDs: participantAccountIDs, + visibleChatMemberAccountIDs: participantAccountIDs, }, }); @@ -290,6 +294,7 @@ function buildAnnounceRoomMembersOnyxData(policyID, accountIDs) { key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, value: { participantAccountIDs: announceReport.participantAccountIDs, + visibleChatMemberAccountIDs: announceReport.visibleChatMemberAccountIDs, }, }); return announceRoomMembers; @@ -314,6 +319,7 @@ function removeOptimisticAnnounceRoomMembers(policyID, accountIDs) { key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, value: { participantAccountIDs: [...remainUsers], + visibleChatMemberAccountIDs: [...remainUsers], }, }); @@ -322,6 +328,7 @@ function removeOptimisticAnnounceRoomMembers(policyID, accountIDs) { key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, value: { participantAccountIDs: announceReport.participantAccountIDs, + visibleChatMemberAccountIDs: announceReport.visibleChatMemberAccountIDs, }, }); return announceRoomMembers; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index ec34cfca0b62..ddf47570256e 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -2106,8 +2106,9 @@ function inviteToRoom(reportID, inviteeEmailsToAccountIDs) { const inviteeEmails = _.keys(inviteeEmailsToAccountIDs); const inviteeAccountIDs = _.values(inviteeEmailsToAccountIDs); - const {participantAccountIDs} = report; + const {participantAccountIDs, visibleChatMemberAccountIDs} = report; const participantAccountIDsAfterInvitation = _.uniq([...participantAccountIDs, ...inviteeAccountIDs]); + const visibleChatMemberAccountIDsAfterInvitation = _.uniq([...visibleChatMemberAccountIDs, ...inviteeAccountIDs]); API.write( 'InviteToRoom', @@ -2122,6 +2123,7 @@ function inviteToRoom(reportID, inviteeEmailsToAccountIDs) { key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { participantAccountIDs: participantAccountIDsAfterInvitation, + visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterInvitation, }, }, ], @@ -2131,6 +2133,7 @@ function inviteToRoom(reportID, inviteeEmailsToAccountIDs) { key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { participantAccountIDs, + visibleChatMemberAccountIDs, }, }, ], @@ -2147,8 +2150,9 @@ function inviteToRoom(reportID, inviteeEmailsToAccountIDs) { function removeFromRoom(reportID, targetAccountIDs) { const report = lodashGet(allReports, [reportID], {}); - const {participantAccountIDs} = report; + const {participantAccountIDs, visibleChatMemberAccountIDs} = report; const participantAccountIDsAfterRemoval = _.difference(participantAccountIDs, targetAccountIDs); + const visibleChatMemberAccountIDsAfterRemoval = _.difference(visibleChatMemberAccountIDs, targetAccountIDs); API.write( 'RemoveFromRoom', @@ -2163,6 +2167,7 @@ function removeFromRoom(reportID, targetAccountIDs) { key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { participantAccountIDs: participantAccountIDsAfterRemoval, + visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterRemoval, }, }, ], @@ -2172,6 +2177,7 @@ function removeFromRoom(reportID, targetAccountIDs) { key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { participantAccountIDs, + visibleChatMemberAccountIDs, }, }, ], @@ -2184,6 +2190,7 @@ function removeFromRoom(reportID, targetAccountIDs) { key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { participantAccountIDs: participantAccountIDsAfterRemoval, + visibleChatMemberAccountIDs: visibleChatMemberAccountIDsAfterRemoval, }, }, ], diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index bf816d0a62a7..f2b08873c308 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -489,8 +489,10 @@ function editTaskAssignee(report, ownerAccountID, assigneeEmail, assigneeAccount // Check if the assignee actually changed if (assigneeAccountID && assigneeAccountID !== report.managerID && assigneeAccountID !== ownerAccountID && assigneeChatReport) { const participants = lodashGet(report, 'participantAccountIDs', []); - if (!participants.includes(assigneeAccountID)) { + const visibleMembers = lodashGet(report, 'visibleChatMemberAccountIDs', []); + if (!visibleMembers.includes(assigneeAccountID)) { optimisticReport.participantAccountIDs = [...participants, assigneeAccountID]; + optimisticReport.visibleChatMemberAccountIDs = [...visibleMembers, assigneeAccountID]; } assigneeChatReportOnyxData = ReportUtils.getTaskAssigneeChatOnyxData( diff --git a/src/pages/RoomInvitePage.js b/src/pages/RoomInvitePage.js index 9b5b4f461652..c57d02432edf 100644 --- a/src/pages/RoomInvitePage.js +++ b/src/pages/RoomInvitePage.js @@ -70,7 +70,7 @@ function RoomInvitePage(props) { const [userToInvite, setUserToInvite] = useState(null); // Any existing participants and Expensify emails should not be eligible for invitation - const excludedUsers = useMemo(() => [...PersonalDetailsUtils.getLoginsByAccountIDs(lodashGet(props.report, 'participantAccountIDs', [])), ...CONST.EXPENSIFY_EMAILS], [props.report]); + const excludedUsers = useMemo(() => [...PersonalDetailsUtils.getLoginsByAccountIDs(lodashGet(props.report, 'visibleChatMemberAccountIDs', [])), ...CONST.EXPENSIFY_EMAILS], [props.report]); useEffect(() => { const inviteOptions = OptionsListUtils.getMemberInviteOptions(props.personalDetails, props.betas, searchTerm, excludedUsers); diff --git a/src/pages/RoomMembersPage.js b/src/pages/RoomMembersPage.js index 23722625b961..b6c747e98c1d 100644 --- a/src/pages/RoomMembersPage.js +++ b/src/pages/RoomMembersPage.js @@ -173,7 +173,7 @@ function RoomMembersPage(props) { const getMemberOptions = () => { let result = []; - _.each(props.report.participantAccountIDs, (accountID) => { + _.each(props.report.visibleChatMemberAccountIDs, (accountID) => { const details = personalDetails[accountID]; if (!details) { From 63e403968fa41f431d2be0be043d93636be611f0 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Fri, 8 Dec 2023 18:15:44 -0300 Subject: [PATCH 10/11] prettier and lint --- src/libs/ReportUtils.ts | 3 +-- src/libs/actions/Policy.js | 4 ++-- src/pages/RoomInvitePage.js | 5 ++++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b0ed3571b99a..8b9ce9fdb385 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2556,7 +2556,7 @@ function buildOptimisticIOUReport(payeeAccountID: number, payerAccountID: number const payerEmail = 'login' in personalDetails ? personalDetails.login : ''; // When creating a report the participantsAccountIDs and visibleChatMemberAccountIDs are the same - const participantsAccountIDs = [payeeAccountID, payerAccountID] + const participantsAccountIDs = [payeeAccountID, payerAccountID]; return { // If we're sending money, hasOutstandingIOU should be false @@ -3305,7 +3305,6 @@ function buildOptimisticTaskReport( description?: string, policyID: string = CONST.POLICY.OWNER_EMAIL_FAKE, ): OptimisticTaskReport { - // When creating a report the participantsAccountIDs and visibleChatMemberAccountIDs are the same const participantsAccountIDs = assigneeAccountID && assigneeAccountID !== ownerAccountID ? [assigneeAccountID] : []; diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index a4a3ef3557a4..6680c06dfc5b 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -278,13 +278,13 @@ function buildAnnounceRoomMembersOnyxData(policyID, accountIDs) { }; // Everyone in special policy rooms is visible - const participantAccountIDs = [...announceReport.participantAccountIDs, ...accountIDs] + const participantAccountIDs = [...announceReport.participantAccountIDs, ...accountIDs]; announceRoomMembers.onyxOptimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport.reportID}`, value: { - participantAccountIDs: participantAccountIDs, + participantAccountIDs, visibleChatMemberAccountIDs: participantAccountIDs, }, }); diff --git a/src/pages/RoomInvitePage.js b/src/pages/RoomInvitePage.js index c57d02432edf..189f229b5584 100644 --- a/src/pages/RoomInvitePage.js +++ b/src/pages/RoomInvitePage.js @@ -70,7 +70,10 @@ function RoomInvitePage(props) { const [userToInvite, setUserToInvite] = useState(null); // Any existing participants and Expensify emails should not be eligible for invitation - const excludedUsers = useMemo(() => [...PersonalDetailsUtils.getLoginsByAccountIDs(lodashGet(props.report, 'visibleChatMemberAccountIDs', [])), ...CONST.EXPENSIFY_EMAILS], [props.report]); + const excludedUsers = useMemo( + () => [...PersonalDetailsUtils.getLoginsByAccountIDs(lodashGet(props.report, 'visibleChatMemberAccountIDs', [])), ...CONST.EXPENSIFY_EMAILS], + [props.report], + ); useEffect(() => { const inviteOptions = OptionsListUtils.getMemberInviteOptions(props.personalDetails, props.betas, searchTerm, excludedUsers); From 0cf688dbc4203fefb665728a1466580fa73ec8e6 Mon Sep 17 00:00:00 2001 From: Rodrigo Lino da Costa Date: Tue, 26 Dec 2023 20:31:49 -0300 Subject: [PATCH 11/11] fixing OptinoListUtilsTest --- src/libs/GroupChatUtils.ts | 2 +- src/libs/OptionsListUtils.js | 8 ++++---- tests/unit/OptionsListUtilsTest.js | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/libs/GroupChatUtils.ts b/src/libs/GroupChatUtils.ts index 82a2977ff4af..862c50700c0c 100644 --- a/src/libs/GroupChatUtils.ts +++ b/src/libs/GroupChatUtils.ts @@ -14,7 +14,7 @@ Onyx.connect({ * Returns the report name if the report is a group chat */ function getGroupChatName(report: Report): string | undefined { - const participants = report.visibleChatMemberAccountIDs ?? []; + const participants = report.participantAccountIDs ?? []; const isMultipleParticipantReport = participants.length > 1; const participantPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(participants, allPersonalDetails ?? {}); // @ts-expect-error Error will gone when OptionsListUtils will be migrated to Typescript diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index ad0aa1836249..55a9c5a2f8e7 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -318,9 +318,9 @@ function getSearchText(report, reportName, personalDetailList, isChatRoomOrPolic Array.prototype.push.apply(searchTerms, chatRoomSubtitle.split(/[,\s]/)); } else { - const participantAccountIDs = report.participantAccountIDs || []; - for (let i = 0; i < participantAccountIDs.length; i++) { - const accountID = participantAccountIDs[i]; + const visibleChatMemberAccountIDs = report.visibleChatMemberAccountIDs || []; + for (let i = 0; i < visibleChatMemberAccountIDs.length; i++) { + const accountID = visibleChatMemberAccountIDs[i]; if (allPersonalDetails[accountID] && allPersonalDetails[accountID].login) { searchTerms = searchTerms.concat(allPersonalDetails[accountID].login); @@ -566,7 +566,7 @@ function getPolicyExpenseReportOption(report) { const expenseReport = policyExpenseReports[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]; const option = createOption( - expenseReport.participantAccountIDs, + expenseReport.visibleChatMemberAccountIDs, allPersonalDetails, expenseReport, {}, diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 999107f0b3ae..ecb5718db23e 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -16,6 +16,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 1, participantAccountIDs: [2, 1], + visibleChatMemberAccountIDs: [2, 1], reportName: 'Iron Man, Mister Fantastic', hasDraft: true, type: CONST.REPORT.TYPE.CHAT, @@ -26,6 +27,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 2, participantAccountIDs: [3], + visibleChatMemberAccountIDs: [3], reportName: 'Spider-Man', type: CONST.REPORT.TYPE.CHAT, }, @@ -37,6 +39,7 @@ describe('OptionsListUtils', () => { isPinned: true, reportID: 3, participantAccountIDs: [1], + visibleChatMemberAccountIDs: [1], reportName: 'Mister Fantastic', type: CONST.REPORT.TYPE.CHAT, }, @@ -46,6 +49,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 4, participantAccountIDs: [4], + visibleChatMemberAccountIDs: [4], reportName: 'Black Panther', type: CONST.REPORT.TYPE.CHAT, }, @@ -55,6 +59,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 5, participantAccountIDs: [5], + visibleChatMemberAccountIDs: [5], reportName: 'Invisible Woman', type: CONST.REPORT.TYPE.CHAT, }, @@ -64,6 +69,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 6, participantAccountIDs: [6], + visibleChatMemberAccountIDs: [6], reportName: 'Thor', type: CONST.REPORT.TYPE.CHAT, }, @@ -75,6 +81,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 7, participantAccountIDs: [7], + visibleChatMemberAccountIDs: [7], reportName: 'Captain America', type: CONST.REPORT.TYPE.CHAT, }, @@ -86,6 +93,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 8, participantAccountIDs: [12], + visibleChatMemberAccountIDs: [12], reportName: 'Silver Surfer', type: CONST.REPORT.TYPE.CHAT, }, @@ -97,6 +105,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 9, participantAccountIDs: [8], + visibleChatMemberAccountIDs: [8], reportName: 'Mister Sinister', iouReportID: 100, type: CONST.REPORT.TYPE.CHAT, @@ -109,6 +118,7 @@ describe('OptionsListUtils', () => { reportID: 10, isPinned: false, participantAccountIDs: [2, 7], + visibleChatMemberAccountIDs: [2, 7], reportName: '', oldPolicyName: "SHIELD's workspace", chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, @@ -187,6 +197,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 11, participantAccountIDs: [999], + visibleChatMemberAccountIDs: [999], reportName: 'Concierge', type: CONST.REPORT.TYPE.CHAT, }, @@ -200,6 +211,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 12, participantAccountIDs: [1000], + visibleChatMemberAccountIDs: [1000], reportName: 'Chronos', type: CONST.REPORT.TYPE.CHAT, }, @@ -213,6 +225,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 13, participantAccountIDs: [1001], + visibleChatMemberAccountIDs: [1001], reportName: 'Receipts', type: CONST.REPORT.TYPE.CHAT, }, @@ -226,6 +239,7 @@ describe('OptionsListUtils', () => { isPinned: false, reportID: 14, participantAccountIDs: [1, 10, 3], + visibleChatMemberAccountIDs: [1, 10, 3], reportName: '', oldPolicyName: 'Avengers Room', isArchivedRoom: false,