From 8d0d4cd252609ab02d465131934ce41d4535a06f Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Tue, 9 Jan 2024 11:37:30 +0300 Subject: [PATCH 1/5] update isGroupChat getParticipantIDs getVisibleMemberIDs --- src/libs/ReportUtils.ts | 58 +++++++++++++++++------------ src/pages/ReportParticipantsPage.js | 3 +- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0e159cf69095..9dc6a1465c62 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4132,6 +4132,30 @@ function getTaskAssigneeChatOnyxData( }; } +/** + * Checks if a report is a group chat. + * + * A report is a group chat if it meets the following conditions: + * - Not a chat thread. + * - Not a task report. + * - Not a money request / IOU report. + * - Not an archived room. + * - Not a public / admin / announce chat room (chat type doesn't match any of the specified types). + * - More than 1 participants (note that participantAccountIDs excludes the current user). + * + */ +function isGroupChat(report: OnyxEntry): boolean { + return Boolean( + report && + !isChatThread(report) && + !isTaskReport(report) && + !isMoneyRequestReport(report) && + !isArchivedRoom(report) && + !Object.values(CONST.REPORT.CHAT_TYPE).some((chatType) => chatType === getChatType(report)) && + (report.participantAccountIDs?.length ?? 0) > 1, + ); +} + /** * Returns an array of the participants Ids of a report * @@ -4150,6 +4174,11 @@ function getParticipantsIDs(report: OnyxEntry): number[] { const onlyUnique = [...new Set([...onlyTruthyValues])]; return onlyUnique; } + + if (isGroupChat(report) && currentUserAccountID) { + return [...new Set([...participants, currentUserAccountID])]; + } + return participants; } @@ -4169,6 +4198,11 @@ function getVisibleMemberIDs(report: OnyxEntry): number[] { const onlyUnique = [...new Set([...onlyTruthyValues])]; return onlyUnique; } + + if (isGroupChat(report) && currentUserAccountID) { + return [...new Set([...visibleChatMemberAccountIDs, currentUserAccountID])]; + } + return visibleChatMemberAccountIDs; } @@ -4228,30 +4262,6 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry) }); } -/** - * Checks if a report is a group chat. - * - * A report is a group chat if it meets the following conditions: - * - Not a chat thread. - * - Not a task report. - * - Not a money request / IOU report. - * - Not an archived room. - * - Not a public / admin / announce chat room (chat type doesn't match any of the specified types). - * - More than 2 participants. - * - */ -function isGroupChat(report: OnyxEntry): boolean { - return Boolean( - report && - !isChatThread(report) && - !isTaskReport(report) && - !isMoneyRequestReport(report) && - !isArchivedRoom(report) && - !Object.values(CONST.REPORT.CHAT_TYPE).some((chatType) => chatType === getChatType(report)) && - (report.participantAccountIDs?.length ?? 0) > 2, - ); -} - function shouldUseFullTitleToDisplay(report: OnyxEntry): boolean { return isMoneyRequestReport(report) || isPolicyExpenseChat(report) || isChatRoom(report) || isChatThread(report) || isTaskReport(report); } diff --git a/src/pages/ReportParticipantsPage.js b/src/pages/ReportParticipantsPage.js index 7dbc1c7036c4..65238fd5ea8c 100755 --- a/src/pages/ReportParticipantsPage.js +++ b/src/pages/ReportParticipantsPage.js @@ -100,7 +100,8 @@ function ReportParticipantsPage(props) { Date: Thu, 11 Jan 2024 20:47:24 +0300 Subject: [PATCH 2/5] updated Header view to include current user avatar --- src/libs/ReportUtils.ts | 152 ++++++++++++++++++----------------- src/pages/home/HeaderView.js | 2 +- 2 files changed, 79 insertions(+), 75 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9dc6a1465c62..45c583da3a86 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1336,6 +1336,80 @@ function getWorkspaceIcon(report: OnyxEntry, policy: OnyxEntry = return workspaceIcon; } +/** + * Checks if a report is a group chat. + * + * A report is a group chat if it meets the following conditions: + * - Not a chat thread. + * - Not a task report. + * - Not a money request / IOU report. + * - Not an archived room. + * - Not a public / admin / announce chat room (chat type doesn't match any of the specified types). + * - More than 1 participants (note that participantAccountIDs excludes the current user). + * + */ +function isGroupChat(report: OnyxEntry): boolean { + return Boolean( + report && + !isChatThread(report) && + !isTaskReport(report) && + !isMoneyRequestReport(report) && + !isArchivedRoom(report) && + !Object.values(CONST.REPORT.CHAT_TYPE).some((chatType) => chatType === getChatType(report)) && + (report.participantAccountIDs?.length ?? 0) > 1, + ); +} + +/** + * Returns an array of the participants Ids of a report + * + * @deprecated Use getVisibleMemberIDs instead + */ +function getParticipantsIDs(report: OnyxEntry): number[] { + if (!report) { + return []; + } + + const participants = report.participantAccountIDs ?? []; + + // Build participants list for IOU/expense reports + if (isMoneyRequestReport(report)) { + const onlyTruthyValues = [report.managerID, report.ownerAccountID, ...participants].filter(Boolean) as number[]; + const onlyUnique = [...new Set([...onlyTruthyValues])]; + return onlyUnique; + } + + if (isGroupChat(report) && currentUserAccountID) { + return [...new Set([...participants, currentUserAccountID])]; + } + + return participants; +} + +/** + * Returns an array of the visible member accountIDs for a report* + */ +function getVisibleMemberIDs(report: OnyxEntry): number[] { + if (!report) { + return []; + } + + const visibleChatMemberAccountIDs = report.visibleChatMemberAccountIDs ?? []; + + // Build participants list for IOU/expense reports + if (isMoneyRequestReport(report)) { + const onlyTruthyValues = [report.managerID, report.ownerAccountID, ...visibleChatMemberAccountIDs].filter(Boolean) as number[]; + const onlyUnique = [...new Set([...onlyTruthyValues])]; + return onlyUnique; + } + + if (isGroupChat(report) && currentUserAccountID) { + return [...new Set([...visibleChatMemberAccountIDs, currentUserAccountID])]; + } + + return visibleChatMemberAccountIDs; +} + /** * Returns the appropriate icons for the given chat report using the stored personalDetails. * The Avatar sources can be URLs or Icon components according to the chat type. @@ -1452,6 +1526,10 @@ function getIcons( return isPayer ? [managerIcon, ownerIcon] : [ownerIcon, managerIcon]; } + if (isGroupChat(report)) { + return getIconsForParticipants(getVisibleMemberIDs(report), personalDetails); + } + return getIconsForParticipants(report?.participantAccountIDs ?? [], personalDetails); } @@ -4132,80 +4210,6 @@ function getTaskAssigneeChatOnyxData( }; } -/** - * Checks if a report is a group chat. - * - * A report is a group chat if it meets the following conditions: - * - Not a chat thread. - * - Not a task report. - * - Not a money request / IOU report. - * - Not an archived room. - * - Not a public / admin / announce chat room (chat type doesn't match any of the specified types). - * - More than 1 participants (note that participantAccountIDs excludes the current user). - * - */ -function isGroupChat(report: OnyxEntry): boolean { - return Boolean( - report && - !isChatThread(report) && - !isTaskReport(report) && - !isMoneyRequestReport(report) && - !isArchivedRoom(report) && - !Object.values(CONST.REPORT.CHAT_TYPE).some((chatType) => chatType === getChatType(report)) && - (report.participantAccountIDs?.length ?? 0) > 1, - ); -} - -/** - * Returns an array of the participants Ids of a report - * - * @deprecated Use getVisibleMemberIDs instead - */ -function getParticipantsIDs(report: OnyxEntry): number[] { - if (!report) { - return []; - } - - const participants = report.participantAccountIDs ?? []; - - // Build participants list for IOU/expense reports - if (isMoneyRequestReport(report)) { - const onlyTruthyValues = [report.managerID, report.ownerAccountID, ...participants].filter(Boolean) as number[]; - const onlyUnique = [...new Set([...onlyTruthyValues])]; - return onlyUnique; - } - - if (isGroupChat(report) && currentUserAccountID) { - return [...new Set([...participants, currentUserAccountID])]; - } - - return participants; -} - -/** - * Returns an array of the visible member accountIDs for a report* - */ -function getVisibleMemberIDs(report: OnyxEntry): number[] { - if (!report) { - return []; - } - - const visibleChatMemberAccountIDs = report.visibleChatMemberAccountIDs ?? []; - - // Build participants list for IOU/expense reports - if (isMoneyRequestReport(report)) { - const onlyTruthyValues = [report.managerID, report.ownerAccountID, ...visibleChatMemberAccountIDs].filter(Boolean) as number[]; - const onlyUnique = [...new Set([...onlyTruthyValues])]; - return onlyUnique; - } - - if (isGroupChat(report) && currentUserAccountID) { - return [...new Set([...visibleChatMemberAccountIDs, currentUserAccountID])]; - } - - return visibleChatMemberAccountIDs; -} - /** * Return iou report action display message */ diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index edf6b65b2f4a..1787b33c826c 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -92,7 +92,7 @@ function HeaderView(props) { const {translate} = useLocalize(); const theme = useTheme(); const styles = useThemeStyles(); - const participants = lodashGet(props.report, 'participantAccountIDs', []); + const participants = ReportUtils.isGroupChat(props.report) ? ReportUtils.getVisibleMemberIDs(props.report) : lodashGet(props.report, 'participantAccountIDs', []); const participantPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(participants, props.personalDetails); const isMultipleParticipant = participants.length > 1; const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(participantPersonalDetails, isMultipleParticipant); From acc1527d622541d2d97d4ab97e17466d1b7d0c0f Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Fri, 12 Jan 2024 18:27:14 +0300 Subject: [PATCH 3/5] minor fix --- 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 45c583da3a86..5ac1806356c0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1345,7 +1345,7 @@ function getWorkspaceIcon(report: OnyxEntry, policy: OnyxEntry = * - Not a money request / IOU report. * - Not an archived room. * - Not a public / admin / announce chat room (chat type doesn't match any of the specified types). - * - More than 1 participants (note that participantAccountIDs excludes the current user). + * - More than 1 participant (note that participantAccountIDs excludes the current user). * */ function isGroupChat(report: OnyxEntry): boolean { @@ -1387,7 +1387,7 @@ function getParticipantsIDs(report: OnyxEntry): number[] { } /** - * Returns an array of the visible member accountIDs for a report* + * Returns an array of the visible member accountIDs for a report */ function getVisibleMemberIDs(report: OnyxEntry): number[] { if (!report) { From 0fd9e84898529dbf98a84abd4e59e843becdc66a Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Wed, 17 Jan 2024 23:38:59 +0300 Subject: [PATCH 4/5] created getGroupChatParticipantIDs --- src/libs/ReportUtils.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5ac1806356c0..0cc0d5ffef3f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1360,6 +1360,10 @@ function isGroupChat(report: OnyxEntry): boolean { ); } +function getGroupChatParticipantIDs(participants: number[]): number[] { + return [...new Set([...participants, ...(currentUserAccountID ? [currentUserAccountID] : [])])]; +} + /** * Returns an array of the participants Ids of a report * @@ -1379,8 +1383,8 @@ function getParticipantsIDs(report: OnyxEntry): number[] { return onlyUnique; } - if (isGroupChat(report) && currentUserAccountID) { - return [...new Set([...participants, currentUserAccountID])]; + if (isGroupChat(report)) { + return getGroupChatParticipantIDs(participants); } return participants; @@ -1403,8 +1407,8 @@ function getVisibleMemberIDs(report: OnyxEntry): number[] { return onlyUnique; } - if (isGroupChat(report) && currentUserAccountID) { - return [...new Set([...visibleChatMemberAccountIDs, currentUserAccountID])]; + if (isGroupChat(report)) { + return getGroupChatParticipantIDs(visibleChatMemberAccountIDs); } return visibleChatMemberAccountIDs; From 0fe26e25a02f27b6c68d012caf7fe097540943f3 Mon Sep 17 00:00:00 2001 From: Fitsum Abebe Date: Fri, 19 Jan 2024 21:19:39 +0300 Subject: [PATCH 5/5] updated according to comment --- src/pages/home/HeaderView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index 3f467523ca2a..660d19e8871d 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -92,7 +92,7 @@ function HeaderView(props) { const {translate} = useLocalize(); const theme = useTheme(); const styles = useThemeStyles(); - const participants = ReportUtils.isGroupChat(props.report) ? ReportUtils.getVisibleMemberIDs(props.report) : lodashGet(props.report, 'participantAccountIDs', []); + const participants = ReportUtils.getParticipantsIDs(props.report); const participantPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(participants, props.personalDetails); const isMultipleParticipant = participants.length > 1; const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(participantPersonalDetails, isMultipleParticipant);