From 3eeddaefa95e3d89a567a9c471c4e41f229777d9 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 12 Jun 2024 21:33:09 +0100 Subject: [PATCH 1/9] Use getParticipantsAccountIDsForDisplay. DRY --- src/components/ReportWelcomeText.tsx | 6 +---- src/libs/OptionsListUtils.ts | 35 +++++----------------------- src/libs/ReportUtils.ts | 35 +++++++++++++++++----------- src/libs/SidebarUtils.ts | 13 +++-------- src/libs/actions/Task.ts | 4 +--- src/pages/home/HeaderView.tsx | 8 +------ 6 files changed, 34 insertions(+), 67 deletions(-) diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index ee6520dfa2b7..7972164701e0 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -33,17 +33,13 @@ type ReportWelcomeTextProps = ReportWelcomeTextOnyxProps & { function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); - const [session] = useOnyx(ONYXKEYS.SESSION); const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); const isChatRoom = ReportUtils.isChatRoom(report); const isSelfDM = ReportUtils.isSelfDM(report); const isInvoiceRoom = ReportUtils.isInvoiceRoom(report); - const isOneOnOneChat = ReportUtils.isOneOnOneChat(report); const isSystemChat = ReportUtils.isSystemChat(report); const isDefault = !(isChatRoom || isPolicyExpenseChat || isSelfDM || isInvoiceRoom || isSystemChat); - const participantAccountIDs = Object.keys(report?.participants ?? {}) - .map(Number) - .filter((accountID) => accountID !== session?.accountID || (!isOneOnOneChat && !isSystemChat)); + const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); const isMultipleParticipant = participantAccountIDs.length > 1; const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails), isMultipleParticipant); const roomWelcomeMessage = ReportUtils.getRoomWelcomeMessage(report); diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index d6d9fdda8ebc..96d295399ee4 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -773,15 +773,10 @@ function createOption( result.policyID = report.policyID; result.isSelfDM = ReportUtils.isSelfDM(report); - // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants - const isOneOnOneChat = ReportUtils.isOneOnOneChat(report); - const visibleParticipantAccountIDs = Object.entries(report.participants ?? {}) - .filter(([, participant]) => participant && !participant.hidden) - .map(([accountID]) => Number(accountID)) - .filter((accountID) => accountID !== currentUserAccountID || !isOneOnOneChat); + const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); result.tooltipText = ReportUtils.getReportParticipantsTitle(visibleParticipantAccountIDs); - result.isOneOnOneChat = isOneOnOneChat; + result.isOneOnOneChat = ReportUtils.isOneOnOneChat(report); hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat || ReportUtils.isGroupChat(report); subtitle = ReportUtils.getChatRoomSubtitle(report); @@ -838,13 +833,7 @@ function createOption( */ function getReportOption(participant: Participant): ReportUtils.OptionData { const report = ReportUtils.getReport(participant.reportID); - - // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants - const isOneOnOneChat = ReportUtils.isOneOnOneChat(report); - const visibleParticipantAccountIDs = Object.entries(report?.participants ?? {}) - .filter(([, reportParticipant]) => reportParticipant && !reportParticipant.hidden) - .map(([accountID]) => Number(accountID)) - .filter((accountID) => accountID !== currentUserAccountID || !isOneOnOneChat); + const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); const option = createOption( visibleParticipantAccountIDs, @@ -1553,11 +1542,8 @@ function createOptionList(personalDetails: OnyxEntry, repor return; } - // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants const isOneOnOneChat = ReportUtils.isOneOnOneChat(report); - const accountIDs = Object.keys(report.participants ?? {}) - .map(Number) - .filter((accountID) => accountID !== currentUserAccountID || !isOneOnOneChat); + const accountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); const isChatRoom = ReportUtils.isChatRoom(report); if ((!accountIDs || accountIDs.length === 0) && !isChatRoom) { @@ -1590,11 +1576,7 @@ function createOptionList(personalDetails: OnyxEntry, repor } function createOptionFromReport(report: Report, personalDetails: OnyxEntry) { - // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants - const isOneOnOneChat = ReportUtils.isOneOnOneChat(report); - const accountIDs = Object.keys(report.participants ?? {}) - .map(Number) - .filter((accountID) => accountID !== currentUserAccountID || !isOneOnOneChat); + const accountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); return { item: report, @@ -1863,13 +1845,8 @@ function getOptions( const isPolicyExpenseChat = option.isPolicyExpenseChat; const isMoneyRequestReport = option.isMoneyRequestReport; const isSelfDM = option.isSelfDM; - const isOneOnOneChat = option.isOneOnOneChat; const isChatRoom = option.isChatRoom; - - // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants - const accountIDs = Object.keys(report.participants ?? {}) - .map(Number) - .filter((accountID) => accountID !== currentUserAccountID || !isOneOnOneChat); + const accountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); if (isPolicyExpenseChat && report.isOwnPolicyExpenseChat && !includeOwnedWorkspaceChats) { return; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 33971530ec77..65998c8641f4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1852,6 +1852,24 @@ function getParticipantAccountIDs(reportID: string, includeOnlyActiveMembers = f return accountIDStrings.map((accountID) => Number(accountID)); } +function getParticipantsAccountIDsForDisplay(report: OnyxEntry, shouldExcludeHidden = false): number[] { + // For 1:1 chat, we don't want to include the current user as a participant in order to not mark 1:1 chats as having multiple participants + // For system chat, we want to display Expensify as the only participant + const shouldFilterOutCurrentUser = isOneOnOneChat(report) || isSystemChat(report); + + let accountIDs = shouldExcludeHidden + ? Object.entries(report?.participants ?? {}) + .filter(([, participant]) => participant && !participant.hidden) + .map(([accountID]) => Number(accountID)) + : Object.keys(report?.participants ?? {}).map(Number); + + if (shouldFilterOutCurrentUser) { + accountIDs = accountIDs.filter((accountID) => accountID !== currentUserAccountID); + } + + return accountIDs; +} + function buildParticipantsFromAccountIDs(accountIDs: number[]): Participants { const finalParticipants: Participants = {}; return accountIDs.reduce((participants, accountID) => { @@ -3479,11 +3497,7 @@ function getParentNavigationSubtitle(report: OnyxEntry): ParentNavigatio function navigateToDetailsPage(report: OnyxEntry) { const isSelfDMReport = isSelfDM(report); const isOneOnOneChatReport = isOneOnOneChat(report); - - // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants - const participantAccountID = Object.keys(report?.participants ?? {}) - .map(Number) - .filter((accountID) => accountID !== currentUserAccountID || !isOneOnOneChatReport); + const participantAccountID = getParticipantsAccountIDsForDisplay(report); if (isSelfDMReport || isOneOnOneChatReport) { Navigation.navigate(ROUTES.PROFILE.getRoute(participantAccountID[0])); @@ -3500,11 +3514,7 @@ function navigateToDetailsPage(report: OnyxEntry) { */ function goBackToDetailsPage(report: OnyxEntry) { const isOneOnOneChatReport = isOneOnOneChat(report); - - // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants - const participantAccountID = Object.keys(report?.participants ?? {}) - .map(Number) - .filter((accountID) => accountID !== currentUserAccountID || !isOneOnOneChatReport); + const participantAccountID = getParticipantsAccountIDsForDisplay(report); if (isOneOnOneChatReport) { Navigation.navigate(ROUTES.PROFILE.getRoute(participantAccountID[0])); @@ -3523,9 +3533,7 @@ function goBackFromPrivateNotes(report: OnyxEntry, session: OnyxEntry accountID !== currentUserAccountID || !isOneOnOneChat(report)); + const participantAccountIDs = getParticipantsAccountIDsForDisplay(report); if (isOneOnOneChat(report)) { Navigation.goBack(ROUTES.PROFILE.getRoute(participantAccountIDs[0])); @@ -7044,6 +7052,7 @@ export { getParentNavigationSubtitle, getParsedComment, getParticipantAccountIDs, + getParticipantsAccountIDsForDisplay, getParticipants, getPendingChatMembers, getPersonalDetailsForAccountID, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 119bbc3ba12a..40c9b959a843 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -248,15 +248,8 @@ function getOptionData({ isDeletedParentAction: false, }; - // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants - const isOneOnOneChat = ReportUtils.isOneOnOneChat(report); - const participantAccountIDs = Object.keys(report.participants ?? {}) - .map(Number) - .filter((accountID) => accountID !== currentUserAccountID || !isOneOnOneChat); - const visibleParticipantAccountIDs = Object.entries(report.participants ?? {}) - .filter(([, participant]) => participant && !participant.hidden) - .map(([accountID]) => Number(accountID)) - .filter((accountID) => accountID !== currentUserAccountID || !isOneOnOneChat); + const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); + const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); const participantPersonalDetailList = Object.values(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails)) as PersonalDetails[]; const personalDetail = participantPersonalDetailList[0] ?? {}; @@ -295,7 +288,7 @@ function getOptionData({ result.chatType = report.chatType; result.isDeletedParentAction = report.isDeletedParentAction; result.isSelfDM = ReportUtils.isSelfDM(report); - result.isOneOnOneChat = isOneOnOneChat; + result.isOneOnOneChat = ReportUtils.isOneOnOneChat(report); result.tooltipText = ReportUtils.getReportParticipantsTitle(visibleParticipantAccountIDs); const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat || ReportUtils.isExpenseReport(report); diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 57b551510d58..51aa0c490562 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -774,9 +774,7 @@ function getShareDestination(reportID: string, reports: OnyxCollection accountID !== currentUserAccountID || !isOneOnOneChat); + const participants = ReportUtils.getParticipantsAccountIDsForDisplay(report); const isMultipleParticipant = participants.length > 1; const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participants, personalDetails), isMultipleParticipant); diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index 41ff0c3e7208..3d7e5af2ea90 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -90,14 +90,8 @@ function HeaderView({ const styles = useThemeStyles(); const isSelfDM = ReportUtils.isSelfDM(report); const isGroupChat = ReportUtils.isGroupChat(report) || ReportUtils.isDeprecatedGroupDM(report); - const isOneOnOneChat = ReportUtils.isOneOnOneChat(report); - const isSystemChat = ReportUtils.isSystemChat(report); - // For 1:1 chat, we don't want to include currentUser as participants in order to not mark 1:1 chats as having multiple participants - const participants = Object.keys(report?.participants ?? {}) - .map(Number) - .filter((accountID) => accountID !== session?.accountID || (!isOneOnOneChat && !isSystemChat)) - .slice(0, 5); + const participants = ReportUtils.getParticipantsAccountIDsForDisplay(report).slice(0, 5); const isMultipleParticipant = participants.length > 1; const participantPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(participants, personalDetails); From f24f4c3b76904419fc9433f37bbb8d35ef3db817 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 12 Jun 2024 22:06:42 +0100 Subject: [PATCH 2/9] remove outdated condition + fix lint --- src/components/ReportWelcomeText.tsx | 2 +- src/libs/ReportUtils.ts | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index 7972164701e0..a5c46b82d94a 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -1,7 +1,7 @@ import React, {useMemo} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {useOnyx, withOnyx} from 'react-native-onyx'; +import {withOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 65998c8641f4..d8c2c60682e2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1617,13 +1617,7 @@ function getReportRecipientAccountIDs(report: OnyxEntry, currentLoginAcc } let finalParticipantAccountIDs: number[] = []; - if (isMoneyRequestReport(report)) { - // For money requests i.e the IOU (1:1 person) and Expense (1:* person) reports, use the full `participants` - // and add the `ownerAccountId`. Money request reports don't add `ownerAccountId` in `participants` array - const defaultParticipantAccountIDs = Object.keys(finalReport?.participants ?? {}).map(Number); - const setOfParticipantAccountIDs = new Set(report?.ownerAccountID ? [...defaultParticipantAccountIDs, report.ownerAccountID] : defaultParticipantAccountIDs); - finalParticipantAccountIDs = [...setOfParticipantAccountIDs]; - } else if (isTaskReport(report)) { + if (isTaskReport(report)) { // Task reports `managerID` will change when assignee is changed, in that case the old `managerID` is still present in `participants` // along with the new one. We only need the `managerID` as a participant here. finalParticipantAccountIDs = report?.managerID ? [report?.managerID] : []; From 003f2b4caea2dcf92ce3d0753f24b45cb31f4344 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 12 Jun 2024 23:50:00 +0100 Subject: [PATCH 3/9] better variable name --- src/libs/ReportUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d8c2c60682e2..2e4f5076d025 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1849,7 +1849,7 @@ function getParticipantAccountIDs(reportID: string, includeOnlyActiveMembers = f function getParticipantsAccountIDsForDisplay(report: OnyxEntry, shouldExcludeHidden = false): number[] { // For 1:1 chat, we don't want to include the current user as a participant in order to not mark 1:1 chats as having multiple participants // For system chat, we want to display Expensify as the only participant - const shouldFilterOutCurrentUser = isOneOnOneChat(report) || isSystemChat(report); + const shouldExcludeCurrentUser = isOneOnOneChat(report) || isSystemChat(report); let accountIDs = shouldExcludeHidden ? Object.entries(report?.participants ?? {}) @@ -1857,7 +1857,7 @@ function getParticipantsAccountIDsForDisplay(report: OnyxEntry, shouldEx .map(([accountID]) => Number(accountID)) : Object.keys(report?.participants ?? {}).map(Number); - if (shouldFilterOutCurrentUser) { + if (shouldExcludeCurrentUser) { accountIDs = accountIDs.filter((accountID) => accountID !== currentUserAccountID); } From 74f57adac0e0ab41b4665d6fcfabdc8656d27e55 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Wed, 12 Jun 2024 23:57:34 +0100 Subject: [PATCH 4/9] Remove getVisibleChatMemberAccountIDs --- src/libs/ReportUtils.ts | 15 --------------- src/pages/ReportDetailsPage.tsx | 2 +- src/pages/ReportParticipantsPage.tsx | 2 +- src/pages/RoomMembersPage.tsx | 4 ++-- src/pages/ShareCodePage.tsx | 2 +- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 2e4f5076d025..3434bf3d3858 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1904,20 +1904,6 @@ function getGroupChatName(participantAccountIDs?: number[], shouldApplyLimit = f return Localize.translateLocal('groupChat.defaultReportName', {displayName: getDisplayNameForParticipant(participants[0], false)}); } -function getVisibleChatMemberAccountIDs(reportID: string): number[] { - const report = getReport(reportID); - if (!report || !report.participants) { - return []; - } - const visibleParticipantAccountIDs = Object.entries(report.participants).reduce((accountIDs, [accountID, participant]) => { - if (participant && !participant.hidden) { - accountIDs.push(Number(accountID)); - } - return accountIDs; - }, []); - return visibleParticipantAccountIDs; -} - function getParticipants(reportID: string) { const report = getReport(reportID); if (!report) { @@ -7078,7 +7064,6 @@ export { getTransactionReportName, getTransactionsWithReceipts, getUserDetailTooltipText, - getVisibleChatMemberAccountIDs, getWhisperDisplayNames, getWorkspaceAvatar, getWorkspaceChats, diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 22e2ce618fab..d2079068ea27 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -96,7 +96,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD if (isSystemChat) { return ReportUtils.getParticipantAccountIDs(report.reportID ?? '').filter((accountID) => accountID !== session?.accountID); } - return ReportUtils.getVisibleChatMemberAccountIDs(report.reportID ?? ''); + return ReportUtils.getParticipantsAccountIDsForDisplay(report, true); }, [report, session, isGroupChat, isSystemChat]); // Get the active chat members by filtering out the pending members with delete action diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 8ae960e34892..6dbb9708f661 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -69,7 +69,7 @@ function ReportParticipantsPage({report, personalDetails, session}: ReportPartic const getUsers = useCallback((): MemberOption[] => { let result: MemberOption[] = []; - const chatParticipants = isGroupChat ? ReportUtils.getParticipantAccountIDs(report.reportID) : ReportUtils.getVisibleChatMemberAccountIDs(report.reportID); + const chatParticipants = isGroupChat ? ReportUtils.getParticipantAccountIDs(report.reportID) : ReportUtils.getParticipantsAccountIDsForDisplay(report, true); chatParticipants.forEach((accountID) => { const role = report.participants?.[accountID].role; const details = personalDetails?.[accountID]; diff --git a/src/pages/RoomMembersPage.tsx b/src/pages/RoomMembersPage.tsx index 0e3c098b7907..d0c5926a3eee 100644 --- a/src/pages/RoomMembersPage.tsx +++ b/src/pages/RoomMembersPage.tsx @@ -167,9 +167,9 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) { const getMemberOptions = (): ListItem[] => { let result: ListItem[] = []; - const participants = ReportUtils.getVisibleChatMemberAccountIDs(report.reportID); + const participants = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); - participants?.forEach((accountID) => { + participants.forEach((accountID) => { const details = personalDetails[accountID]; if (!details) { diff --git a/src/pages/ShareCodePage.tsx b/src/pages/ShareCodePage.tsx index 2e2d7b10d758..12b6c41dbcb5 100644 --- a/src/pages/ShareCodePage.tsx +++ b/src/pages/ShareCodePage.tsx @@ -47,7 +47,7 @@ function ShareCodePage({report}: ShareCodePageProps) { } if (ReportUtils.isMoneyRequestReport(report)) { // generate subtitle from participants - return ReportUtils.getVisibleChatMemberAccountIDs(report.reportID) + return ReportUtils.getParticipantsAccountIDsForDisplay(report, true) .map((accountID) => ReportUtils.getDisplayNameForParticipant(accountID)) .join(' & '); } From 2b7342eead678e22368a0fdea6cb01b4a3bd003b Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Thu, 13 Jun 2024 01:12:00 +0100 Subject: [PATCH 5/9] Remove getParticipantAccountIDs --- .../LHNOptionsList/OptionRowLHN.tsx | 2 +- src/libs/ReportUtils.ts | 60 ++++++++----------- src/pages/GroupChatNameEditPage.tsx | 13 ++-- src/pages/InviteReportParticipantsPage.tsx | 4 +- src/pages/ReportDetailsPage.tsx | 15 ++--- src/pages/ReportParticipantsPage.tsx | 3 +- 6 files changed, 40 insertions(+), 57 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN.tsx index 1aa3fe47212d..b9bb0055cbd1 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -127,7 +127,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti const isGroupChat = ReportUtils.isGroupChat(optionItem) || ReportUtils.isDeprecatedGroupDM(optionItem); - const fullTitle = isGroupChat ? ReportUtils.getGroupChatName(undefined, false, optionItem.reportID ?? '') : optionItem.text; + const fullTitle = isGroupChat ? ReportUtils.getGroupChatName(undefined, false, optionItem) : optionItem.text; const subscriptAvatarBorderColor = isFocused ? focusedBackgroundColor : theme.sidebar; return ( { - if (!includeOnlyActiveMembers) { - return true; - } - const pendingMember = report?.pendingChatMembers?.findLast((member) => member.accountID === accountID.toString()); - return !pendingMember || pendingMember.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; - }); - return accountIDStrings.map((accountID) => Number(accountID)); -} +function getParticipantsAccountIDsForDisplay(report: OnyxEntry, shouldExcludeHidden = false, shouldExcludeDeleted = false): number[] { + let participantsEntries = Object.entries(report?.participants ?? {}); -function getParticipantsAccountIDsForDisplay(report: OnyxEntry, shouldExcludeHidden = false): number[] { // For 1:1 chat, we don't want to include the current user as a participant in order to not mark 1:1 chats as having multiple participants // For system chat, we want to display Expensify as the only participant const shouldExcludeCurrentUser = isOneOnOneChat(report) || isSystemChat(report); - let accountIDs = shouldExcludeHidden - ? Object.entries(report?.participants ?? {}) - .filter(([, participant]) => participant && !participant.hidden) - .map(([accountID]) => Number(accountID)) - : Object.keys(report?.participants ?? {}).map(Number); + if (shouldExcludeCurrentUser || shouldExcludeHidden || shouldExcludeDeleted) { + participantsEntries = participantsEntries.filter(([accountID, participant]) => { + if (shouldExcludeCurrentUser && Number(accountID) === currentUserAccountID) { + return false; + } - if (shouldExcludeCurrentUser) { - accountIDs = accountIDs.filter((accountID) => accountID !== currentUserAccountID); + if (shouldExcludeHidden && participant.hidden) { + return false; + } + + if (shouldExcludeDeleted && report?.pendingChatMembers?.findLast((member) => member.accountID === accountID)?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) { + return false; + } + + return true; + }); } - return accountIDs; + return participantsEntries.map(([accountID]) => Number(accountID)); } function buildParticipantsFromAccountIDs(accountIDs: number[]): Participants { @@ -1876,18 +1871,14 @@ function buildParticipantsFromAccountIDs(accountIDs: number[]): Participants { /** * Returns the report name if the report is a group chat */ -function getGroupChatName(participantAccountIDs?: number[], shouldApplyLimit = false, reportID = ''): string | undefined { - // If we have a reportID always try to get the name from the report. - if (reportID) { - const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; - const reportName = allReports?.[reportKey]?.reportName; - if (reportName) { - return reportName; - } +function getGroupChatName(participantAccountIDs?: number[], shouldApplyLimit = false, report?: OnyxEntry): string | undefined { + // If we have a report always try to get the name from the report. + if (report?.reportName) { + return report.reportName; } // Get participantAccountIDs from participants object - let participants = participantAccountIDs ?? getParticipantAccountIDs(reportID); + let participants = participantAccountIDs ?? Object.keys(report?.participants ?? {}).map(Number); if (shouldApplyLimit) { participants = participants.slice(0, 5); } @@ -2060,7 +2051,7 @@ function getIcons( source: report.avatarUrl || getDefaultGroupAvatar(report.reportID), id: -1, type: CONST.ICON_TYPE_AVATAR, - name: getGroupChatName(undefined, true, report.reportID ?? ''), + name: getGroupChatName(undefined, true, report), }; return [groupChatIcon]; } @@ -3345,7 +3336,7 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu } if (isGroupChat(report)) { - return getGroupChatName(undefined, true, report?.reportID) ?? ''; + return getGroupChatName(undefined, true, report) ?? ''; } if (isChatRoom(report) || isTaskReport(report)) { @@ -7031,7 +7022,6 @@ export { getOutstandingChildRequest, getParentNavigationSubtitle, getParsedComment, - getParticipantAccountIDs, getParticipantsAccountIDsForDisplay, getParticipants, getPendingChatMembers, diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx index 3f1ffe760900..c7ad8877b26d 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -43,14 +43,11 @@ function GroupChatNameEditPage({groupChatDraft, report}: GroupChatNameEditPagePr const {inputCallbackRef} = useAutoFocusInput(); // We will try to get the chatName from the report or draft depending on what flow we are in - const participantAccountIDs = useMemo(() => { - if (reportID) { - return ReportUtils.getParticipantAccountIDs(reportID); - } - - return (groupChatDraft?.participants ?? []).map((participant) => participant.accountID); - }, [groupChatDraft, reportID]); - const existingReportName = useMemo(() => ReportUtils.getGroupChatName(participantAccountIDs, false, reportID), [participantAccountIDs, reportID]); + const draftParticipantAccountIDs = useMemo(() => (groupChatDraft?.participants ?? []).map((participant) => participant.accountID), [groupChatDraft?.participants]); + const existingReportName = useMemo( + () => (report ? ReportUtils.getGroupChatName(undefined, false, report) : ReportUtils.getGroupChatName(draftParticipantAccountIDs)), + [draftParticipantAccountIDs, report], + ); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const currentChatName = reportID ? existingReportName : groupChatDraft?.reportName || existingReportName; diff --git a/src/pages/InviteReportParticipantsPage.tsx b/src/pages/InviteReportParticipantsPage.tsx index a8bbedc6d9e3..78cb5dfcd991 100644 --- a/src/pages/InviteReportParticipantsPage.tsx +++ b/src/pages/InviteReportParticipantsPage.tsx @@ -52,7 +52,7 @@ function InviteReportParticipantsPage({betas, personalDetails, report, didScreen // Any existing participants and Expensify emails should not be eligible for invitation const excludedUsers = useMemo( - () => [...PersonalDetailsUtils.getLoginsByAccountIDs(ReportUtils.getParticipantAccountIDs(report?.reportID ?? '', true)), ...CONST.EXPENSIFY_EMAILS], + () => [...PersonalDetailsUtils.getLoginsByAccountIDs(ReportUtils.getParticipantsAccountIDsForDisplay(report, false, true)), ...CONST.EXPENSIFY_EMAILS], [report], ); @@ -152,7 +152,7 @@ function InviteReportParticipantsPage({betas, personalDetails, report, didScreen const reportID = report.reportID; const backRoute = useMemo(() => ROUTES.REPORT_PARTICIPANTS.getRoute(reportID), [reportID]); - const reportName = useMemo(() => ReportUtils.getGroupChatName(undefined, true, report?.reportID ?? ''), [report]); + const reportName = useMemo(() => ReportUtils.getGroupChatName(undefined, true, report), [report]); const inviteUsers = useCallback(() => { if (!validate()) { return; diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index d2079068ea27..514a7aafb6d6 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -90,14 +90,9 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD const isGroupChat = useMemo(() => ReportUtils.isGroupChat(report), [report]); const isThread = useMemo(() => ReportUtils.isThread(report), [report]); const participants = useMemo(() => { - if (isGroupChat) { - return ReportUtils.getParticipantAccountIDs(report.reportID ?? ''); - } - if (isSystemChat) { - return ReportUtils.getParticipantAccountIDs(report.reportID ?? '').filter((accountID) => accountID !== session?.accountID); - } - return ReportUtils.getParticipantsAccountIDsForDisplay(report, true); - }, [report, session, isGroupChat, isSystemChat]); + const shouldExcludeHiddenParticipants = !isGroupChat && !isSystemChat; + return ReportUtils.getParticipantsAccountIDsForDisplay(report, shouldExcludeHiddenParticipants); + }, [report, isGroupChat, isSystemChat]); // Get the active chat members by filtering out the pending members with delete action const activeChatMembers = participants.flatMap((accountID) => { @@ -211,7 +206,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD icon: Expensicons.Exit, isAnonymousAction: true, action: () => { - if (ReportUtils.getParticipantAccountIDs(report.reportID, true).length === 1 && isGroupChat) { + if (ReportUtils.getParticipantsAccountIDsForDisplay(report, false, true).length === 1 && isGroupChat) { setIsLastMemberLeavingGroupModalVisible(true); return; } @@ -306,7 +301,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD ); }, [report, icons, isMoneyRequestReport, isInvoiceReport, isGroupChat, isThread, styles]); - const reportName = ReportUtils.isDeprecatedGroupDM(report) || isGroupChat ? ReportUtils.getGroupChatName(undefined, false, report.reportID ?? '') : ReportUtils.getReportName(report); + const reportName = ReportUtils.isDeprecatedGroupDM(report) || isGroupChat ? ReportUtils.getGroupChatName(undefined, false, report) : ReportUtils.getReportName(report); return ( diff --git a/src/pages/ReportParticipantsPage.tsx b/src/pages/ReportParticipantsPage.tsx index 6dbb9708f661..6fee6077b721 100755 --- a/src/pages/ReportParticipantsPage.tsx +++ b/src/pages/ReportParticipantsPage.tsx @@ -69,7 +69,8 @@ function ReportParticipantsPage({report, personalDetails, session}: ReportPartic const getUsers = useCallback((): MemberOption[] => { let result: MemberOption[] = []; - const chatParticipants = isGroupChat ? ReportUtils.getParticipantAccountIDs(report.reportID) : ReportUtils.getParticipantsAccountIDsForDisplay(report, true); + const shouldExcludeHiddenParticipants = !isGroupChat; + const chatParticipants = ReportUtils.getParticipantsAccountIDsForDisplay(report, shouldExcludeHiddenParticipants); chatParticipants.forEach((accountID) => { const role = report.participants?.[accountID].role; const details = personalDetails?.[accountID]; From 487fd538e5be67696f0e172e8113b3f28fa64f89 Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Thu, 13 Jun 2024 01:36:38 +0100 Subject: [PATCH 6/9] Pass report to getGroupChatName --- src/components/LHNOptionsList/OptionRowLHN.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/LHNOptionsList/OptionRowLHN.tsx b/src/components/LHNOptionsList/OptionRowLHN.tsx index b9bb0055cbd1..3648827e8e55 100644 --- a/src/components/LHNOptionsList/OptionRowLHN.tsx +++ b/src/components/LHNOptionsList/OptionRowLHN.tsx @@ -127,7 +127,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti const isGroupChat = ReportUtils.isGroupChat(optionItem) || ReportUtils.isDeprecatedGroupDM(optionItem); - const fullTitle = isGroupChat ? ReportUtils.getGroupChatName(undefined, false, optionItem) : optionItem.text; + const fullTitle = isGroupChat ? ReportUtils.getGroupChatName(undefined, false, report) : optionItem.text; const subscriptAvatarBorderColor = isFocused ? focusedBackgroundColor : theme.sidebar; return ( Date: Thu, 13 Jun 2024 03:42:45 +0100 Subject: [PATCH 7/9] change popover border radius to 16px --- src/styles/utils/generators/ModalStyleUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/utils/generators/ModalStyleUtils.ts b/src/styles/utils/generators/ModalStyleUtils.ts index bc668ba45670..b7998f6d721e 100644 --- a/src/styles/utils/generators/ModalStyleUtils.ts +++ b/src/styles/utils/generators/ModalStyleUtils.ts @@ -197,7 +197,7 @@ const createModalStyleUtils: StyleUtilGenerator = ({the }, }; modalContainerStyle = { - borderRadius: 12, + borderRadius: variables.componentBorderRadiusLarge, borderWidth: 1, borderColor: theme.border, justifyContent: 'center', From 4f9bb56e23f72e13da8eaecc0840a50cdd5607ca Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Thu, 13 Jun 2024 03:46:14 +0100 Subject: [PATCH 8/9] Revert "change popover border radius to 16px" This reverts commit f12e385453f2854119db1d90dcc2e8cb30dafe48. --- src/styles/utils/generators/ModalStyleUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/styles/utils/generators/ModalStyleUtils.ts b/src/styles/utils/generators/ModalStyleUtils.ts index b7998f6d721e..bc668ba45670 100644 --- a/src/styles/utils/generators/ModalStyleUtils.ts +++ b/src/styles/utils/generators/ModalStyleUtils.ts @@ -197,7 +197,7 @@ const createModalStyleUtils: StyleUtilGenerator = ({the }, }; modalContainerStyle = { - borderRadius: variables.componentBorderRadiusLarge, + borderRadius: 12, borderWidth: 1, borderColor: theme.border, justifyContent: 'center', From 7213c4b9e87a5431f0be6c934697770900c49fed Mon Sep 17 00:00:00 2001 From: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> Date: Thu, 13 Jun 2024 18:30:30 +0100 Subject: [PATCH 9/9] Remove unused isOneOnOneChat field --- src/libs/OptionsListUtils.ts | 1 - src/libs/SidebarUtils.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index efb4af2899ef..d8c17d831544 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -777,7 +777,6 @@ function createOption( const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); result.tooltipText = ReportUtils.getReportParticipantsTitle(visibleParticipantAccountIDs); - result.isOneOnOneChat = ReportUtils.isOneOnOneChat(report); hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat || ReportUtils.isGroupChat(report); subtitle = ReportUtils.getChatRoomSubtitle(report); diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 9f7717df46fa..1cb12d99e0ed 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -297,7 +297,6 @@ function getOptionData({ result.chatType = report.chatType; result.isDeletedParentAction = report.isDeletedParentAction; result.isSelfDM = ReportUtils.isSelfDM(report); - result.isOneOnOneChat = ReportUtils.isOneOnOneChat(report); result.tooltipText = ReportUtils.getReportParticipantsTitle(visibleParticipantAccountIDs); const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat || ReportUtils.isExpenseReport(report);