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);