From 9f2d5a2574eb5cbf61dd4a3ebd06d1fa6b5b946d Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 27 Jun 2024 16:22:53 +0700 Subject: [PATCH 01/15] display begining chat history message in LHN --- src/libs/ReportUtils.ts | 78 +++++++++++++++++++++++++++++++++++++++- src/libs/SidebarUtils.ts | 2 +- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index cca52ac37c9d..c89beace4724 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -21,6 +21,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; +import * as OptionsListUtils from '@libs/OptionsListUtils'; import type { Beta, OnyxInputOrEntry, @@ -79,7 +80,7 @@ import * as UserUtils from './UserUtils'; type AvatarRange = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18; -type WelcomeMessage = {showReportName: boolean; phrase1?: string; phrase2?: string}; +type WelcomeMessage = {showReportName: boolean; phrase1?: string; phrase2?: string; phrase3?: string}; type SpendBreakdown = { nonReimbursableSpend: number; @@ -1609,6 +1610,80 @@ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { return welcomeMessage; } +function getWelcomMessage(report: OnyxEntry): WelcomeMessage { + const welcomeMessage: WelcomeMessage = {showReportName: true}; + if (isChatRoom(report)) { + return getRoomWelcomeMessage(report); + } + + if (isPolicyExpenseChat(report)) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne'); + welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo'); + welcomeMessage.phrase3 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree'); + return welcomeMessage; + } + + if (isSelfDM(report)) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistorySelfDM'); + return welcomeMessage; + } + + if (isSystemChat(report)) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistorySystemDM'); + return welcomeMessage; + } + + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistory'); + return welcomeMessage; +} + +function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): string { + if (isThread(report)) { + return Localize.translateLocal('report.noActivityYet'); + } + + const welcomeMessage = getWelcomMessage(report); + if (isPolicyExpenseChat(report)) { + if (report?.description) { + return parseHtmlToText(report.description); + } + return `${welcomeMessage.phrase1} ${getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${getPolicyName(report)} ${welcomeMessage.phrase3}`; + } + + if (isChatRoom(report)) { + if (report?.description) { + return parseHtmlToText(report.description); + } + return `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; + } + + if (isSelfDM(report) || isSystemChat(report)) { + return `${welcomeMessage.phrase1}`; + } + + const participantAccountIDs = getParticipantsAccountIDsForDisplay(report); + const isMultipleParticipant = participantAccountIDs.length > 1; + const displayNamesWithTooltips = getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, allPersonalDetails), isMultipleParticipant); + const displayNamesWithTooltipsText = displayNamesWithTooltips + .map(({displayName, pronouns}, index) => { + const formattedText = !pronouns ? displayName : `${displayName} (${pronouns})`; + + if (index === displayNamesWithTooltips.length - 1) { + return `${formattedText}.`; + } + if (index === displayNamesWithTooltips.length - 2) { + return `${formattedText} ${Localize.translateLocal('common.and')}`; + } + if (index < displayNamesWithTooltips.length - 2) { + return `${formattedText},`; + } + + return ''; + }) + .join(' '); + return `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`; +} + /** * Returns true if Concierge is one of the chat participants (1:1 as well as group chats) */ @@ -7144,6 +7219,7 @@ export { getPolicyExpenseChat, getPolicyName, getPolicyType, + getReportBeginningOfChatHistoryMessage, getReimbursementDeQueuedActionMessage, getReimbursementQueuedActionMessage, getReportActionActorAccountID, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index ee2807a94c7c..081e70df4be8 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -367,7 +367,7 @@ function getOptionData({ } else { result.alternateText = lastMessageTextFromReport.length > 0 ? lastMessageText : ReportActionsUtils.getLastVisibleMessage(report.reportID, {}, lastAction)?.lastMessageText; if (!result.alternateText) { - result.alternateText = Localize.translate(preferredLocale, 'report.noActivityYet'); + result.alternateText = ReportUtils.formatReportLastMessageText(ReportUtils.getReportBeginningOfChatHistoryMessage(report)) || Localize.translate(preferredLocale, 'report.noActivityYet');; } } } else { From e32567e76c635b081fce45c0bb1f6a0101cf1917 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 1 Jul 2024 11:02:18 +0700 Subject: [PATCH 02/15] fix lint --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 65a93c5c4491..13fd4b533453 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -21,7 +21,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {Route} from '@src/ROUTES'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; -import * as OptionsListUtils from '@libs/OptionsListUtils'; import type { Beta, OnyxInputOrEntry, @@ -48,6 +47,7 @@ import type {Message, ReportActions} from '@src/types/onyx/ReportAction'; import type {Comment, Receipt, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type IconAsset from '@src/types/utils/IconAsset'; +import * as OptionsListUtils from './OptionsListUtils'; import AccountUtils from './AccountUtils'; import * as IOU from './actions/IOU'; import * as PolicyActions from './actions/Policy/Policy'; From 0051894593f3578c9058fa78048b4918050cedaa Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 1 Jul 2024 11:20:44 +0700 Subject: [PATCH 03/15] fix lint --- src/libs/ReportUtils.ts | 50 +-------------------------------- src/libs/SidebarUtils.ts | 60 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 50 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 13fd4b533453..e083ba9634dd 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -47,7 +47,6 @@ import type {Message, ReportActions} from '@src/types/onyx/ReportAction'; import type {Comment, Receipt, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type IconAsset from '@src/types/utils/IconAsset'; -import * as OptionsListUtils from './OptionsListUtils'; import AccountUtils from './AccountUtils'; import * as IOU from './actions/IOU'; import * as PolicyActions from './actions/Policy/Policy'; @@ -1637,53 +1636,6 @@ function getWelcomMessage(report: OnyxEntry): WelcomeMessage { return welcomeMessage; } -function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): string { - if (isThread(report)) { - return Localize.translateLocal('report.noActivityYet'); - } - - const welcomeMessage = getWelcomMessage(report); - if (isPolicyExpenseChat(report)) { - if (report?.description) { - return parseHtmlToText(report.description); - } - return `${welcomeMessage.phrase1} ${getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${getPolicyName(report)} ${welcomeMessage.phrase3}`; - } - - if (isChatRoom(report)) { - if (report?.description) { - return parseHtmlToText(report.description); - } - return `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; - } - - if (isSelfDM(report) || isSystemChat(report)) { - return `${welcomeMessage.phrase1}`; - } - - const participantAccountIDs = getParticipantsAccountIDsForDisplay(report); - const isMultipleParticipant = participantAccountIDs.length > 1; - const displayNamesWithTooltips = getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, allPersonalDetails), isMultipleParticipant); - const displayNamesWithTooltipsText = displayNamesWithTooltips - .map(({displayName, pronouns}, index) => { - const formattedText = !pronouns ? displayName : `${displayName} (${pronouns})`; - - if (index === displayNamesWithTooltips.length - 1) { - return `${formattedText}.`; - } - if (index === displayNamesWithTooltips.length - 2) { - return `${formattedText} ${Localize.translateLocal('common.and')}`; - } - if (index < displayNamesWithTooltips.length - 2) { - return `${formattedText},`; - } - - return ''; - }) - .join(' '); - return `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`; -} - /** * Returns true if Concierge is one of the chat participants (1:1 as well as group chats) */ @@ -7226,7 +7178,7 @@ export { getPolicyExpenseChat, getPolicyName, getPolicyType, - getReportBeginningOfChatHistoryMessage, + getWelcomMessage, getReimbursementDeQueuedActionMessage, getReimbursementQueuedActionMessage, getReportActionActorAccountID, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 7cd60edeca14..1f6fc9a52c74 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -21,8 +21,16 @@ import * as PolicyUtils from './PolicyUtils'; import * as ReportActionsUtils from './ReportActionsUtils'; import * as ReportUtils from './ReportUtils'; import * as TaskUtils from './TaskUtils'; +import {parseHtmlToText} from './OnyxAwareParser'; const visibleReportActionItems: ReportActions = {}; +let allPersonalDetails: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + callback: (value) => { + allPersonalDetails = value ?? {}; + }, +}); Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, callback: (actions, key) => { @@ -381,7 +389,7 @@ function getOptionData({ } else { result.alternateText = lastMessageTextFromReport.length > 0 ? lastMessageText : ReportActionsUtils.getLastVisibleMessage(report.reportID, {}, lastAction)?.lastMessageText; if (!result.alternateText) { - result.alternateText = ReportUtils.formatReportLastMessageText(ReportUtils.getReportBeginningOfChatHistoryMessage(report)) || Localize.translate(preferredLocale, 'report.noActivityYet');; + result.alternateText = ReportUtils.formatReportLastMessageText(getReportBeginningOfChatHistoryMessage(report)) || Localize.translate(preferredLocale, 'report.noActivityYet'); } } } else { @@ -447,8 +455,58 @@ function getOptionData({ return result; } +function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): string { + if (ReportUtils.isThread(report)) { + return Localize.translateLocal('report.noActivityYet'); + } + + const welcomeMessage = ReportUtils.getWelcomMessage(report); + if (ReportUtils.isPolicyExpenseChat(report)) { + if (report?.description) { + return parseHtmlToText(report.description); + } + return `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName(report)} ${welcomeMessage.phrase3}`; + } + + if (ReportUtils.isChatRoom(report)) { + if (report?.description) { + return parseHtmlToText(report.description); + } + return `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; + } + + if (ReportUtils.isSelfDM(report) || ReportUtils.isSystemChat(report)) { + return `${welcomeMessage.phrase1}`; + } + + const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); + const isMultipleParticipant = participantAccountIDs.length > 1; + const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips( + OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, allPersonalDetails), + isMultipleParticipant, + ); + const displayNamesWithTooltipsText = displayNamesWithTooltips + .map(({displayName, pronouns}, index) => { + const formattedText = !pronouns ? displayName : `${displayName} (${pronouns})`; + + if (index === displayNamesWithTooltips.length - 1) { + return `${formattedText}.`; + } + if (index === displayNamesWithTooltips.length - 2) { + return `${formattedText} ${Localize.translateLocal('common.and')}`; + } + if (index < displayNamesWithTooltips.length - 2) { + return `${formattedText},`; + } + + return ''; + }) + .join(' '); + return `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`; +} export default { getOptionData, getOrderedReportIDs, + getReportBeginningOfChatHistoryMessage, }; From b23327b13f1d025ba93caa396757af4d58fede34 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 1 Jul 2024 15:21:12 +0700 Subject: [PATCH 04/15] run prettier --- src/libs/SidebarUtils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 1f6fc9a52c74..1cedf7573506 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -16,12 +16,12 @@ import {hasValidDraftComment} from './DraftCommentUtils'; import localeCompare from './LocaleCompare'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; +import {parseHtmlToText} from './OnyxAwareParser'; import * as OptionsListUtils from './OptionsListUtils'; import * as PolicyUtils from './PolicyUtils'; import * as ReportActionsUtils from './ReportActionsUtils'; import * as ReportUtils from './ReportUtils'; import * as TaskUtils from './TaskUtils'; -import {parseHtmlToText} from './OnyxAwareParser'; const visibleReportActionItems: ReportActions = {}; let allPersonalDetails: OnyxEntry; @@ -465,7 +465,9 @@ function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): stri if (report?.description) { return parseHtmlToText(report.description); } - return `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName(report)} ${welcomeMessage.phrase3}`; + return `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName(report)} ${ + welcomeMessage.phrase3 + }`; } if (ReportUtils.isChatRoom(report)) { From 91d090c25387b93223dddfe40e02fe3a0d130117 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Tue, 2 Jul 2024 15:17:07 +0700 Subject: [PATCH 05/15] fix logic get welcome text --- src/components/ReportWelcomeText.tsx | 20 ++++++++++---------- src/libs/ReportUtils.ts | 4 ++-- src/libs/SidebarUtils.ts | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index a5c46b82d94a..9368d0c3e7ca 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -42,7 +42,7 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); const isMultipleParticipant = participantAccountIDs.length > 1; const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails), isMultipleParticipant); - const roomWelcomeMessage = ReportUtils.getRoomWelcomeMessage(report); + const welcomeMessage = ReportUtils.getWelcomeMessage(report); const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, policy, participantAccountIDs); const additionalText = moneyRequestOptions .filter((item): item is Exclude => item !== CONST.IOU.TYPE.INVOICE) @@ -101,11 +101,11 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP ) : ( - {translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne')} + {welcomeMessage.phrase1} {ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} - {translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo')} + {welcomeMessage.phrase2} {ReportUtils.getPolicyName(report)} - {translate('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree')} + {welcomeMessage.phrase3} ))} {isChatRoom && @@ -125,8 +125,8 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP ) : ( - {roomWelcomeMessage.phrase1} - {roomWelcomeMessage.showReportName && ( + {welcomeMessage.phrase1} + {welcomeMessage.showReportName && ( )} - {roomWelcomeMessage.phrase2 !== undefined && {roomWelcomeMessage.phrase2}} + {welcomeMessage.phrase2 !== undefined && {welcomeMessage.phrase2}} ))} {isSelfDM && ( - {translate('reportActionsView.beginningOfChatHistorySelfDM')} + {welcomeMessage.phrase1} )} {isSystemChat && ( - {translate('reportActionsView.beginningOfChatHistorySystemDM')} + {welcomeMessage.phrase1} )} {isDefault && ( - {translate('reportActionsView.beginningOfChatHistory')} + {welcomeMessage.phrase1} {displayNamesWithTooltips.map(({displayName, accountID}, index) => ( // eslint-disable-next-line react/no-array-index-key diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e083ba9634dd..e7ff19008ebf 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1609,7 +1609,7 @@ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { return welcomeMessage; } -function getWelcomMessage(report: OnyxEntry): WelcomeMessage { +function getWelcomeMessage(report: OnyxEntry): WelcomeMessage { const welcomeMessage: WelcomeMessage = {showReportName: true}; if (isChatRoom(report)) { return getRoomWelcomeMessage(report); @@ -7178,7 +7178,7 @@ export { getPolicyExpenseChat, getPolicyName, getPolicyType, - getWelcomMessage, + getWelcomeMessage, getReimbursementDeQueuedActionMessage, getReimbursementQueuedActionMessage, getReportActionActorAccountID, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 1cedf7573506..9776ebda5265 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -460,7 +460,7 @@ function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): stri return Localize.translateLocal('report.noActivityYet'); } - const welcomeMessage = ReportUtils.getWelcomMessage(report); + const welcomeMessage = ReportUtils.getWelcomeMessage(report); if (ReportUtils.isPolicyExpenseChat(report)) { if (report?.description) { return parseHtmlToText(report.description); From d3c7f1318a8d1d9be1d9d0496bf3d220c5a8f13b Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Wed, 3 Jul 2024 15:52:21 +0700 Subject: [PATCH 06/15] Update src/libs/SidebarUtils.ts Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/libs/SidebarUtils.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 9776ebda5265..86ca3ab0c604 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -456,9 +456,6 @@ function getOptionData({ return result; } function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): string { - if (ReportUtils.isThread(report)) { - return Localize.translateLocal('report.noActivityYet'); - } const welcomeMessage = ReportUtils.getWelcomeMessage(report); if (ReportUtils.isPolicyExpenseChat(report)) { From d949ba064d4c53d071be38e9a66a9dd37b1d63c3 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 3 Jul 2024 16:08:12 +0700 Subject: [PATCH 07/15] fix: logic get begin of chat history --- src/libs/SidebarUtils.ts | 63 ++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 86ca3ab0c604..866a06896681 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -389,7 +389,7 @@ function getOptionData({ } else { result.alternateText = lastMessageTextFromReport.length > 0 ? lastMessageText : ReportActionsUtils.getLastVisibleMessage(report.reportID, {}, lastAction)?.lastMessageText; if (!result.alternateText) { - result.alternateText = ReportUtils.formatReportLastMessageText(getReportBeginningOfChatHistoryMessage(report)) || Localize.translate(preferredLocale, 'report.noActivityYet'); + result.alternateText = ReportUtils.formatReportLastMessageText(getReportBeginningOfChatHistoryMessage(report) ?? ''); } } } else { @@ -455,8 +455,7 @@ function getOptionData({ return result; } -function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): string { - +function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): string | undefined { const welcomeMessage = ReportUtils.getWelcomeMessage(report); if (ReportUtils.isPolicyExpenseChat(report)) { if (report?.description) { @@ -477,31 +476,39 @@ function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): stri if (ReportUtils.isSelfDM(report) || ReportUtils.isSystemChat(report)) { return `${welcomeMessage.phrase1}`; } - - const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); - const isMultipleParticipant = participantAccountIDs.length > 1; - const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips( - OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, allPersonalDetails), - isMultipleParticipant, - ); - const displayNamesWithTooltipsText = displayNamesWithTooltips - .map(({displayName, pronouns}, index) => { - const formattedText = !pronouns ? displayName : `${displayName} (${pronouns})`; - - if (index === displayNamesWithTooltips.length - 1) { - return `${formattedText}.`; - } - if (index === displayNamesWithTooltips.length - 2) { - return `${formattedText} ${Localize.translateLocal('common.and')}`; - } - if (index < displayNamesWithTooltips.length - 2) { - return `${formattedText},`; - } - - return ''; - }) - .join(' '); - return `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`; + const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); + const isChatRoom = ReportUtils.isChatRoom(report); + const isSelfDM = ReportUtils.isSelfDM(report); + const isInvoiceRoom = ReportUtils.isInvoiceRoom(report); + const isSystemChat = ReportUtils.isSystemChat(report); + const isDefault = !(isChatRoom || isPolicyExpenseChat || isSelfDM || isInvoiceRoom || isSystemChat); + + if (isDefault) { + const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); + const isMultipleParticipant = participantAccountIDs.length > 1; + const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips( + OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, allPersonalDetails), + isMultipleParticipant, + ); + const displayNamesWithTooltipsText = displayNamesWithTooltips + .map(({displayName, pronouns}, index) => { + const formattedText = !pronouns ? displayName : `${displayName} (${pronouns})`; + + if (index === displayNamesWithTooltips.length - 1) { + return `${formattedText}.`; + } + if (index === displayNamesWithTooltips.length - 2) { + return `${formattedText} ${Localize.translateLocal('common.and')}`; + } + if (index < displayNamesWithTooltips.length - 2) { + return `${formattedText},`; + } + + return ''; + }) + .join(' '); + return `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`; + } } export default { From 208bd883f93399e5b9a9c4d6608b9ec6b9a17fea Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 5 Jul 2024 11:36:55 +0700 Subject: [PATCH 08/15] consistent logic --- src/libs/ReportUtils.ts | 5 ++++- src/libs/SidebarUtils.ts | 28 ++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 901ccd0a78f5..bf0daf198a07 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1680,7 +1680,10 @@ function getWelcomeMessage(report: OnyxEntry): WelcomeMessage { return welcomeMessage; } - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistory'); + if (!(isChatRoom(report) || isPolicyExpenseChat(report) || isSelfDM(report) || isInvoiceRoom(report) || isSystemChat(report))) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistory'); + } + return welcomeMessage; } diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index bcb9d7ac392d..d88b7ec048df 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -393,7 +393,8 @@ function getOptionData({ } else { result.alternateText = lastMessageTextFromReport.length > 0 ? lastMessageText : ReportActionsUtils.getLastVisibleMessage(report.reportID, {}, lastAction)?.lastMessageText; if (!result.alternateText) { - result.alternateText = ReportUtils.formatReportLastMessageText(getReportBeginningOfChatHistoryMessage(report) ?? ''); + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + result.alternateText = ReportUtils.formatReportLastMessageText(getReportBeginningOfChatHistoryMessage(report) || Localize.translateLocal('report.noActivityYet')); } } } else { @@ -461,7 +462,18 @@ function getOptionData({ } function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): string | undefined { const welcomeMessage = ReportUtils.getWelcomeMessage(report); - if (ReportUtils.isPolicyExpenseChat(report)) { + const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); + const isChatRoom = ReportUtils.isChatRoom(report); + const isSelfDM = ReportUtils.isSelfDM(report); + const isInvoiceRoom = ReportUtils.isInvoiceRoom(report); + const isSystemChat = ReportUtils.isSystemChat(report); + const isDefault = !(isChatRoom || isPolicyExpenseChat || isSelfDM || isInvoiceRoom || isSystemChat); + + if (ReportUtils.isChatThread(report)) { + return ''; + } + + if (isPolicyExpenseChat) { if (report?.description) { return parseHtmlToText(report.description); } @@ -470,22 +482,16 @@ function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): stri }`; } - if (ReportUtils.isChatRoom(report)) { + if (isChatRoom) { if (report?.description) { return parseHtmlToText(report.description); } return `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; } - if (ReportUtils.isSelfDM(report) || ReportUtils.isSystemChat(report)) { + if (isSelfDM || isSystemChat) { return `${welcomeMessage.phrase1}`; } - const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); - const isChatRoom = ReportUtils.isChatRoom(report); - const isSelfDM = ReportUtils.isSelfDM(report); - const isInvoiceRoom = ReportUtils.isInvoiceRoom(report); - const isSystemChat = ReportUtils.isSystemChat(report); - const isDefault = !(isChatRoom || isPolicyExpenseChat || isSelfDM || isInvoiceRoom || isSystemChat); if (isDefault) { const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); @@ -513,6 +519,8 @@ function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): stri .join(' '); return `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`; } + + return ''; } export default { From 3cf84832248318419e23116a19157661bbbd0c7e Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 8 Jul 2024 21:30:03 +0700 Subject: [PATCH 09/15] fix lint --- src/libs/ReportUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d520982385dc..8e30349da8ef 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1673,8 +1673,9 @@ function getWelcomeMessage(report: OnyxEntry): WelcomeMessage { if (!(isChatRoom(report) || isPolicyExpenseChat(report) || isSelfDM(report) || isInvoiceRoom(report) || isSystemChat(report))) { welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistory'); + return welcomeMessage; } - + return welcomeMessage; } From 15ad9f44ce0497776a84fb659710563b2b278c6e Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 8 Jul 2024 23:26:36 +0700 Subject: [PATCH 10/15] fix: remove useless function --- src/components/ReportWelcomeText.tsx | 3 +- src/libs/ReportUtils.ts | 67 +------------- src/libs/SidebarUtils.ts | 125 +++++++++++++++------------ 3 files changed, 73 insertions(+), 122 deletions(-) diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index 9368d0c3e7ca..e73f00e81393 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -7,6 +7,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportUtils from '@libs/ReportUtils'; +import SidebarUtils from '@libs/SidebarUtils'; import CONST from '@src/CONST'; import type {IOUType} from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -42,7 +43,7 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); const isMultipleParticipant = participantAccountIDs.length > 1; const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails), isMultipleParticipant); - const welcomeMessage = ReportUtils.getWelcomeMessage(report); + const welcomeMessage = SidebarUtils.getWelcomeMessage(report); const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, policy, participantAccountIDs); const additionalText = moneyRequestOptions .filter((item): item is Exclude => item !== CONST.IOU.TYPE.INVOICE) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8e30349da8ef..611ab0e117a4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -79,8 +79,6 @@ import * as UserUtils from './UserUtils'; type AvatarRange = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18; -type WelcomeMessage = {showReportName: boolean; phrase1?: string; phrase2?: string; phrase3?: string}; - type SpendBreakdown = { nonReimbursableSpend: number; reimbursableSpend: number; @@ -1617,68 +1615,6 @@ function canDeleteReportAction(reportAction: OnyxInputOrEntry, rep return isActionOwner || isAdmin; } -/** - * Get welcome message based on room type - */ -function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { - const welcomeMessage: WelcomeMessage = {showReportName: true}; - const workspaceName = getPolicyName(report); - - if (isArchivedRoom(report)) { - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartOne'); - welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartTwo'); - } else if (isDomainRoom(report)) { - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryDomainRoomPartOne', {domainRoom: report?.reportName ?? ''}); - welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryDomainRoomPartTwo'); - } else if (isAdminRoom(report)) { - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartOne', {workspaceName}); - welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartTwo'); - } else if (isAnnounceRoom(report)) { - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoomPartOne', {workspaceName}); - welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoomPartTwo', {workspaceName}); - } else if (isInvoiceRoom(report)) { - welcomeMessage.showReportName = false; - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryInvoiceRoom'); - } else { - // Message for user created rooms or other room types. - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartOne'); - welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartTwo'); - } - - return welcomeMessage; -} - -function getWelcomeMessage(report: OnyxEntry): WelcomeMessage { - const welcomeMessage: WelcomeMessage = {showReportName: true}; - if (isChatRoom(report)) { - return getRoomWelcomeMessage(report); - } - - if (isPolicyExpenseChat(report)) { - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne'); - welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo'); - welcomeMessage.phrase3 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree'); - return welcomeMessage; - } - - if (isSelfDM(report)) { - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistorySelfDM'); - return welcomeMessage; - } - - if (isSystemChat(report)) { - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistorySystemDM'); - return welcomeMessage; - } - - if (!(isChatRoom(report) || isPolicyExpenseChat(report) || isSelfDM(report) || isInvoiceRoom(report) || isSystemChat(report))) { - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistory'); - return welcomeMessage; - } - - return welcomeMessage; -} - /** * Returns true if Concierge is one of the chat participants (1:1 as well as group chats) */ @@ -7177,7 +7113,6 @@ export { getPolicyExpenseChat, getPolicyName, getPolicyType, - getWelcomeMessage, getReimbursementDeQueuedActionMessage, getReimbursementQueuedActionMessage, getReportActionActorAccountID, @@ -7191,7 +7126,6 @@ export { getReportPreviewMessage, getReportRecipientAccountIDs, getRoom, - getRoomWelcomeMessage, getRootParentReport, getRouteFromLink, getSystemChat, @@ -7264,6 +7198,7 @@ export { isIOUReport, isIOUReportUsingReport, isJoinRequestInAdminRoom, + isDomainRoom, isMoneyRequest, isMoneyRequestReport, isMoneyRequestReportPendingDeletion, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 817393bf08f4..57e6d1a8ffb2 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -23,6 +23,8 @@ import * as ReportActionsUtils from './ReportActionsUtils'; import * as ReportUtils from './ReportUtils'; import * as TaskUtils from './TaskUtils'; +type WelcomeMessage = {showReportName: boolean; phrase1?: string; phrase2?: string; phrase3?: string; concatMessage?: string}; + const visibleReportActionItems: ReportActions = {}; let allPersonalDetails: OnyxEntry; Onyx.connect({ @@ -394,38 +396,13 @@ function getOptionData({ result.alternateText = lastMessageTextFromReport.length > 0 ? lastMessageText : ReportActionsUtils.getLastVisibleMessage(report.reportID, {}, lastAction)?.lastMessageText; if (!result.alternateText) { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - result.alternateText = ReportUtils.formatReportLastMessageText(getReportBeginningOfChatHistoryMessage(report) || Localize.translateLocal('report.noActivityYet')); + result.alternateText = ReportUtils.formatReportLastMessageText(getWelcomeMessage(report).concatMessage || Localize.translateLocal('report.noActivityYet')); } } } else { if (!lastMessageText) { - if (ReportUtils.isSystemChat(report)) { - lastMessageText = Localize.translate(preferredLocale, 'reportActionsView.beginningOfChatHistorySystemDM'); - } else if (ReportUtils.isSelfDM(report)) { - lastMessageText = Localize.translate(preferredLocale, 'reportActionsView.beginningOfChatHistorySelfDM'); - } else { - // Here we get the beginning of chat history message and append the display name for each user, adding pronouns if there are any. - // We also add a fullstop after the final name, the word "and" before the final name and commas between all previous names. - lastMessageText = - Localize.translate(preferredLocale, 'reportActionsView.beginningOfChatHistory') + - displayNamesWithTooltips - .map(({displayName, pronouns}, index) => { - const formattedText = !pronouns ? displayName : `${displayName} (${pronouns})`; - - if (index === displayNamesWithTooltips.length - 1) { - return `${formattedText}.`; - } - if (index === displayNamesWithTooltips.length - 2) { - return `${formattedText} ${Localize.translate(preferredLocale, 'common.and')}`; - } - if (index < displayNamesWithTooltips.length - 2) { - return `${formattedText},`; - } - - return ''; - }) - .join(' '); - } + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + result.alternateText = ReportUtils.formatReportLastMessageText(getWelcomeMessage(report).concatMessage || Localize.translateLocal('report.noActivityYet')); } result.alternateText = @@ -465,40 +442,42 @@ function getOptionData({ return result; } -function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): string | undefined { - const welcomeMessage = ReportUtils.getWelcomeMessage(report); - const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report); - const isChatRoom = ReportUtils.isChatRoom(report); - const isSelfDM = ReportUtils.isSelfDM(report); - const isInvoiceRoom = ReportUtils.isInvoiceRoom(report); - const isSystemChat = ReportUtils.isSystemChat(report); - const isDefault = !(isChatRoom || isPolicyExpenseChat || isSelfDM || isInvoiceRoom || isSystemChat); - - if (ReportUtils.isChatThread(report)) { - return ''; + +function getWelcomeMessage(report: OnyxEntry): WelcomeMessage { + const welcomeMessage: WelcomeMessage = {showReportName: true}; + if (ReportUtils.isChatRoom(report)) { + return getRoomWelcomeMessage(report); } - if (isPolicyExpenseChat) { + if (ReportUtils.isPolicyExpenseChat(report)) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne'); + welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo'); + welcomeMessage.phrase3 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree'); if (report?.description) { - return parseHtmlToText(report.description); + welcomeMessage.concatMessage = parseHtmlToText(report.description); } - return `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName(report)} ${ - welcomeMessage.phrase3 - }`; + welcomeMessage.concatMessage = `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName( + report, + )} ${welcomeMessage.phrase3}`; + return welcomeMessage; } - if (isChatRoom) { - if (report?.description) { - return parseHtmlToText(report.description); - } - return `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; + if (ReportUtils.isSelfDM(report)) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistorySelfDM'); + welcomeMessage.concatMessage = welcomeMessage.phrase1; + return welcomeMessage; } - if (isSelfDM || isSystemChat) { - return `${welcomeMessage.phrase1}`; + if (ReportUtils.isSystemChat(report)) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistorySystemDM'); + welcomeMessage.concatMessage = welcomeMessage.phrase1; + return welcomeMessage; } - if (isDefault) { + if ( + !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report) || ReportUtils.isSelfDM(report) || ReportUtils.isInvoiceRoom(report) || ReportUtils.isSystemChat(report)) + ) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistory'); const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); const isMultipleParticipant = participantAccountIDs.length > 1; const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips( @@ -522,14 +501,50 @@ function getReportBeginningOfChatHistoryMessage(report: OnyxEntry): stri return ''; }) .join(' '); - return `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`; + welcomeMessage.concatMessage = `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`; + return welcomeMessage; + } + + return welcomeMessage; +} + +/** + * Get welcome message based on room type + */ +function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { + const welcomeMessage: WelcomeMessage = {showReportName: true}; + const workspaceName = ReportUtils.getPolicyName(report); + + if (ReportUtils.isArchivedRoom(report)) { + welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartTwo'); + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartOne'); + } else if (ReportUtils.isDomainRoom(report)) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryDomainRoomPartOne', {domainRoom: report?.reportName ?? ''}); + welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryDomainRoomPartTwo'); + } else if (ReportUtils.isAdminRoom(report)) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartOne', {workspaceName}); + welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAdminRoomPartTwo'); + } else if (ReportUtils.isAnnounceRoom(report)) { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoomPartOne', {workspaceName}); + welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryAnnounceRoomPartTwo', {workspaceName}); + } else if (ReportUtils.isInvoiceRoom(report)) { + welcomeMessage.showReportName = false; + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryInvoiceRoom'); + } else { + // Message for user created rooms or other room types. + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartOne'); + welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartTwo'); + } + if (report?.description) { + welcomeMessage.concatMessage = parseHtmlToText(report.description); } + welcomeMessage.concatMessage = `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; - return ''; + return welcomeMessage; } export default { getOptionData, getOrderedReportIDs, - getReportBeginningOfChatHistoryMessage, + getWelcomeMessage, }; From 8270b2369377d74d9f2ae8e6272100b05de62472 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 8 Jul 2024 23:36:14 +0700 Subject: [PATCH 11/15] fix lint --- src/libs/SidebarUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 57e6d1a8ffb2..292a1ae519d0 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -347,7 +347,7 @@ function getOptionData({ const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, lastActorDetails, policy); // We need to remove sms domain in case the last message text has a phone number mention with sms domain. - let lastMessageText = Str.removeSMSDomain(lastMessageTextFromReport); + const lastMessageText = Str.removeSMSDomain(lastMessageTextFromReport); const lastAction = visibleReportActionItems[report.reportID]; From f4ea209c8291b7959c997d5747ac9ff5635e1f4c Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 10 Jul 2024 22:25:09 +0700 Subject: [PATCH 12/15] refactor: cleanup function --- src/components/ReportWelcomeText.tsx | 2 +- src/libs/SidebarUtils.ts | 107 ++++++++++++++------------- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index e73f00e81393..74ea38112e04 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -43,7 +43,7 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); const isMultipleParticipant = participantAccountIDs.length > 1; const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails), isMultipleParticipant); - const welcomeMessage = SidebarUtils.getWelcomeMessage(report); + const welcomeMessage = SidebarUtils.getWelcomeMessage(report, policy); const moneyRequestOptions = ReportUtils.temporary_getMoneyRequestOptions(report, policy, participantAccountIDs); const additionalText = moneyRequestOptions .filter((item): item is Exclude => item !== CONST.IOU.TYPE.INVOICE) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 758ad1fded76..40ec66f523fd 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -16,14 +16,14 @@ import {hasValidDraftComment} from './DraftCommentUtils'; import localeCompare from './LocaleCompare'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; -import {parseHtmlToText} from './OnyxAwareParser'; import * as OptionsListUtils from './OptionsListUtils'; +import Parser from './Parser'; import * as PolicyUtils from './PolicyUtils'; import * as ReportActionsUtils from './ReportActionsUtils'; import * as ReportUtils from './ReportUtils'; import * as TaskUtils from './TaskUtils'; -type WelcomeMessage = {showReportName: boolean; phrase1?: string; phrase2?: string; phrase3?: string; concatMessage?: string}; +type WelcomeMessage = {showReportName: boolean; phrase1?: string; phrase2?: string; phrase3?: string; messageText?: string; messageHtml?: string}; const visibleReportActionItems: ReportActions = {}; let allPersonalDetails: OnyxEntry; @@ -348,7 +348,7 @@ function getOptionData({ const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, lastActorDetails, policy); // We need to remove sms domain in case the last message text has a phone number mention with sms domain. - const lastMessageText = Str.removeSMSDomain(lastMessageTextFromReport); + let lastMessageText = Str.removeSMSDomain(lastMessageTextFromReport); const lastAction = visibleReportActionItems[report.reportID]; @@ -396,14 +396,12 @@ function getOptionData({ } else { result.alternateText = lastMessageTextFromReport.length > 0 ? lastMessageText : ReportActionsUtils.getLastVisibleMessage(report.reportID, {}, lastAction)?.lastMessageText; if (!result.alternateText) { - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - result.alternateText = ReportUtils.formatReportLastMessageText(getWelcomeMessage(report).concatMessage || Localize.translateLocal('report.noActivityYet')); + result.alternateText = ReportUtils.formatReportLastMessageText(getWelcomeMessage(report, policy).messageText ?? Localize.translateLocal('report.noActivityYet')); } } } else { if (!lastMessageText) { - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - result.alternateText = ReportUtils.formatReportLastMessageText(getWelcomeMessage(report).concatMessage || Localize.translateLocal('report.noActivityYet')); + lastMessageText = ReportUtils.formatReportLastMessageText(getWelcomeMessage(report, policy).messageText ?? Localize.translateLocal('report.noActivityYet')); } result.alternateText = @@ -444,68 +442,69 @@ function getOptionData({ return result; } -function getWelcomeMessage(report: OnyxEntry): WelcomeMessage { +function getWelcomeMessage(report: OnyxEntry, policy: OnyxEntry): WelcomeMessage { const welcomeMessage: WelcomeMessage = {showReportName: true}; + if (ReportUtils.isChatThread(report) || ReportUtils.isTaskReport(report)) { + return welcomeMessage; + } + if (ReportUtils.isChatRoom(report)) { return getRoomWelcomeMessage(report); } if (ReportUtils.isPolicyExpenseChat(report)) { - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne'); - welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo'); - welcomeMessage.phrase3 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree'); - if (report?.description) { - welcomeMessage.concatMessage = parseHtmlToText(report.description); + if (policy?.description) { + welcomeMessage.messageText = Parser.htmlToText(policy.description); + welcomeMessage.messageHtml = policy.description; + } else { + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne'); + welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo'); + welcomeMessage.phrase3 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartThree'); + welcomeMessage.messageText = `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName( + report, + )} ${welcomeMessage.phrase3}`; } - welcomeMessage.concatMessage = `${welcomeMessage.phrase1} ${ReportUtils.getDisplayNameForParticipant(report?.ownerAccountID)} ${welcomeMessage.phrase2} ${ReportUtils.getPolicyName( - report, - )} ${welcomeMessage.phrase3}`; return welcomeMessage; } if (ReportUtils.isSelfDM(report)) { welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistorySelfDM'); - welcomeMessage.concatMessage = welcomeMessage.phrase1; + welcomeMessage.messageText = welcomeMessage.phrase1; return welcomeMessage; } if (ReportUtils.isSystemChat(report)) { welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistorySystemDM'); - welcomeMessage.concatMessage = welcomeMessage.phrase1; + welcomeMessage.messageText = welcomeMessage.phrase1; return welcomeMessage; } - if ( - !(ReportUtils.isChatRoom(report) || ReportUtils.isPolicyExpenseChat(report) || ReportUtils.isSelfDM(report) || ReportUtils.isInvoiceRoom(report) || ReportUtils.isSystemChat(report)) - ) { - welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistory'); - const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); - const isMultipleParticipant = participantAccountIDs.length > 1; - const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips( - OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, allPersonalDetails), - isMultipleParticipant, - ); - const displayNamesWithTooltipsText = displayNamesWithTooltips - .map(({displayName, pronouns}, index) => { - const formattedText = !pronouns ? displayName : `${displayName} (${pronouns})`; - - if (index === displayNamesWithTooltips.length - 1) { - return `${formattedText}.`; - } - if (index === displayNamesWithTooltips.length - 2) { - return `${formattedText} ${Localize.translateLocal('common.and')}`; - } - if (index < displayNamesWithTooltips.length - 2) { - return `${formattedText},`; - } - - return ''; - }) - .join(' '); - welcomeMessage.concatMessage = `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`; - return welcomeMessage; - } + welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistory'); + const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report); + const isMultipleParticipant = participantAccountIDs.length > 1; + const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips( + OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, allPersonalDetails), + isMultipleParticipant, + ); + const displayNamesWithTooltipsText = displayNamesWithTooltips + .map(({displayName, pronouns}, index) => { + const formattedText = !pronouns ? displayName : `${displayName} (${pronouns})`; + if (index === displayNamesWithTooltips.length - 1) { + return `${formattedText}.`; + } + if (index === displayNamesWithTooltips.length - 2) { + return `${formattedText} ${Localize.translateLocal('common.and')}`; + } + if (index < displayNamesWithTooltips.length - 2) { + return `${formattedText},`; + } + + return ''; + }) + .join(' '); + + welcomeMessage.messageText = `${welcomeMessage.phrase1} ${displayNamesWithTooltipsText}`; return welcomeMessage; } @@ -516,9 +515,14 @@ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { const welcomeMessage: WelcomeMessage = {showReportName: true}; const workspaceName = ReportUtils.getPolicyName(report); + if (report?.description) { + welcomeMessage.messageText = Parser.htmlToText(report.description); + welcomeMessage.messageHtml = report.description; + return welcomeMessage; + } if (ReportUtils.isArchivedRoom(report)) { - welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartTwo'); welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartOne'); + welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartTwo'); } else if (ReportUtils.isDomainRoom(report)) { welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryDomainRoomPartOne', {domainRoom: report?.reportName ?? ''}); welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryDomainRoomPartTwo'); @@ -536,10 +540,7 @@ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartOne'); welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryUserRoomPartTwo'); } - if (report?.description) { - welcomeMessage.concatMessage = parseHtmlToText(report.description); - } - welcomeMessage.concatMessage = `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; + welcomeMessage.messageText = `${welcomeMessage.phrase1} ${welcomeMessage.showReportName ? ReportUtils.getReportName(report) : ''} ${welcomeMessage.phrase2 ?? ''}`; return welcomeMessage; } From 57e761ec61476e72051e622bb66619fc1b9da4cf Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 10 Jul 2024 23:17:37 +0700 Subject: [PATCH 13/15] use messageHtml field --- src/components/ReportWelcomeText.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/ReportWelcomeText.tsx b/src/components/ReportWelcomeText.tsx index 74ea38112e04..96f705ea2d52 100644 --- a/src/components/ReportWelcomeText.tsx +++ b/src/components/ReportWelcomeText.tsx @@ -87,18 +87,18 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP {isPolicyExpenseChat && - (policy?.description ? ( + (welcomeMessage?.messageHtml ? ( { if (!canEditPolicyDescription) { return; } - Navigation.navigate(ROUTES.WORKSPACE_PROFILE_DESCRIPTION.getRoute(policy.id)); + Navigation.navigate(ROUTES.WORKSPACE_PROFILE_DESCRIPTION.getRoute(policy?.id ?? '-1')); }} style={[styles.renderHTML, canEditPolicyDescription ? styles.cursorPointer : styles.cursorText]} accessibilityLabel={translate('reportDescriptionPage.roomDescription')} > - + ) : ( @@ -110,19 +110,19 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP ))} {isChatRoom && - (report?.description ? ( + (welcomeMessage?.messageHtml ? ( { if (ReportUtils.canEditReportDescription(report, policy)) { - Navigation.navigate(ROUTES.REPORT_DESCRIPTION.getRoute(report.reportID)); + Navigation.navigate(ROUTES.REPORT_DESCRIPTION.getRoute(report?.reportID ?? '-1')); return; } - Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report.reportID)); + Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? '-1')); }} style={styles.renderHTML} accessibilityLabel={translate('reportDescriptionPage.roomDescription')} > - + ) : ( From 229402aabb8b91352139d249dd0b2975478b7bbc Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:44:53 +0700 Subject: [PATCH 14/15] Update src/libs/SidebarUtils.ts Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/libs/SidebarUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 40ec66f523fd..b90b8ef3f5ce 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -454,8 +454,8 @@ function getWelcomeMessage(report: OnyxEntry, policy: OnyxEntry) if (ReportUtils.isPolicyExpenseChat(report)) { if (policy?.description) { - welcomeMessage.messageText = Parser.htmlToText(policy.description); welcomeMessage.messageHtml = policy.description; + welcomeMessage.messageText = Parser.htmlToText(welcomeMessage.messageHtml); } else { welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartOne'); welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfChatHistoryPolicyExpenseChatPartTwo'); From b7c57ec16467ad071353a3caac8a6d0b31a0867a Mon Sep 17 00:00:00 2001 From: nkdengineer <161821005+nkdengineer@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:46:00 +0700 Subject: [PATCH 15/15] Update src/libs/SidebarUtils.ts Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com> --- src/libs/SidebarUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index b90b8ef3f5ce..79ebb27719d3 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -516,8 +516,8 @@ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { const workspaceName = ReportUtils.getPolicyName(report); if (report?.description) { - welcomeMessage.messageText = Parser.htmlToText(report.description); welcomeMessage.messageHtml = report.description; + welcomeMessage.messageText = Parser.htmlToText(welcomeMessage.messageHtml); return welcomeMessage; } if (ReportUtils.isArchivedRoom(report)) {