From e57cfbc2118ed4045044a539653506374586c42e Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 7 Nov 2023 01:41:22 +0700 Subject: [PATCH 01/32] translate invite member to room --- src/languages/en.ts | 4 +++ src/languages/es.ts | 4 +++ src/libs/ReportActionsUtils.ts | 11 +++++++ src/libs/SidebarUtils.ts | 10 +++--- src/libs/actions/ReportActions.ts | 31 ++++++++++++++++++- .../home/report/ReportActionItemMessage.js | 10 +++++- 6 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index c186a1fffedf..16adcc08e41a 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -266,6 +266,10 @@ export default { tbd: 'TBD', selectCurrency: 'Select a currency', card: 'Card', + user: 'user', + users: 'users', + invited: 'invited', + removed: 'removed', }, location: { useCurrent: 'Use current location', diff --git a/src/languages/es.ts b/src/languages/es.ts index a0a30bcf4141..e3d0482d5cfa 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -256,6 +256,10 @@ export default { tbd: 'Por determinar', selectCurrency: 'Selecciona una moneda', card: 'Tarjeta', + user: 'usuario', + users: 'usuarias', + invited: 'invitada', + removed: 'eliminado', }, location: { useCurrent: 'Usar ubicación actual', diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 11e11f549682..cef6265ad6fe 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -616,6 +616,15 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea return actions.includes(reportAction.actionName); } +function isMemberRoomChangeLog(reportAction: OnyxEntry): boolean { + if (!reportAction) { + return false; + } + + const actions: ActionName[] = [CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM, CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.REMOVE_FROM_ROOM]; + return actions.includes(reportAction.actionName); +} + export { extractLinksFromMessageHtml, getAllReportActions, @@ -657,4 +666,6 @@ export { shouldReportActionBeVisible, shouldReportActionBeVisibleAsLastAction, getFirstVisibleReportActionID, + isMemberRoomChangeLog, + isMemberPolicyChangeLog, }; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 80ed96d25d65..871b0ef6c9a8 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -437,17 +437,17 @@ function getOptionData( const targetAccountIDs = lastAction?.originalMessage?.targetAccountIDs ?? []; const verb = lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? 'invited' - : 'removed'; - const users = targetAccountIDs.length > 1 ? 'users' : 'user'; + ? Localize.translate(preferredLocale, 'common.invited') + : Localize.translate(preferredLocale, 'common.removed'); + const users = Localize.translate(preferredLocale, targetAccountIDs.length > 1 ? 'common.users' : 'common.user'); result.alternateText = `${verb} ${targetAccountIDs.length} ${users}`; const roomName = lastAction?.originalMessage?.roomName ?? ''; if (roomName) { const preposition = lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? ' to' - : ' from'; + ? ` ${Localize.translate(preferredLocale, 'common.to')}` + : ` ${Localize.translate(preferredLocale, 'common.from')}`; result.alternateText += `${preposition} ${roomName}`; } } else if (lastAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lastActorDisplayName && lastMessageTextFromReport) { diff --git a/src/libs/actions/ReportActions.ts b/src/libs/actions/ReportActions.ts index b9cea498a3fa..c95a6f80057d 100644 --- a/src/libs/actions/ReportActions.ts +++ b/src/libs/actions/ReportActions.ts @@ -1,9 +1,10 @@ import Onyx from 'react-native-onyx'; +import * as Localize from '@libs/Localize'; import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import ReportAction from '@src/types/onyx/ReportAction'; +import ReportAction, {Message} from '@src/types/onyx/ReportAction'; function clearReportActionErrors(reportID: string, reportAction: ReportAction) { const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); @@ -34,7 +35,35 @@ function clearReportActionErrors(reportID: string, reportAction: ReportAction) { }); } +/** + * @param originalMessage + * @param targetAccountIDs + * @returns + */ +function getReportActionMessageRoomChange(originalMessage: Message, targetAccountIDs: number[]) { + if (targetAccountIDs.length === 0) { + return originalMessage; + } + + const mentionTags = targetAccountIDs.map((accountID, index) => { + if (index === targetAccountIDs.length - 1 && index !== 0) { + return `${Localize.translateLocal('common.and')} `; + } + return `${targetAccountIDs.length > 1 ? ', ' : ''}`; + }); + + const html = `${Localize.translateLocal('common.invited')} ${mentionTags.join('')} `; + + const message: Message = { + ...originalMessage, + html, + }; + + return message; +} + export { // eslint-disable-next-line import/prefer-default-export clearReportActionErrors, + getReportActionMessageRoomChange, }; diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index 4c6603c052a3..f3222adc0829 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -7,6 +7,7 @@ import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import styles from '@styles/styles'; +import * as ReportActions from '@userActions/ReportActions'; import CONST from '@src/CONST'; import ReportActionItemFragment from './ReportActionItemFragment'; import reportActionPropTypes from './reportActionPropTypes'; @@ -37,9 +38,16 @@ const defaultProps = { }; function ReportActionItemMessage(props) { - const messages = _.compact(props.action.previousMessage || props.action.message); + let messages = _.compact(props.action.previousMessage || props.action.message); const isAttachment = ReportUtils.isReportMessageAttachment(_.last(messages)); const isIOUReport = ReportActionsUtils.isMoneyRequestAction(props.action); + + const isMemberChangeLog = ReportActionsUtils.isMemberRoomChangeLog(props.action); + if (isMemberChangeLog) { + const targetAccountIDs = props.action.originalMessage.targetAccountIDs; + messages = [ReportActions.getReportActionMessageRoomChange(messages[0], targetAccountIDs)]; + } + let iouMessage; if (isIOUReport) { const iouReportID = lodashGet(props.action, 'originalMessage.IOUReportID'); From 2cf8aefb931d69c9ae0ad47d97ff910a6d92a348 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 7 Nov 2023 09:01:42 +0700 Subject: [PATCH 02/32] fix test --- src/libs/ReportActionsUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index cef6265ad6fe..3cd7abfdb682 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -667,5 +667,4 @@ export { shouldReportActionBeVisibleAsLastAction, getFirstVisibleReportActionID, isMemberRoomChangeLog, - isMemberPolicyChangeLog, }; From a31bdd1af55ee0a617699e5bdf788a93940b96b7 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 7 Nov 2023 17:39:25 +0700 Subject: [PATCH 03/32] move translate --- src/languages/en.ts | 10 ++++++---- src/languages/es.ts | 10 ++++++---- src/libs/SidebarUtils.ts | 12 ++++++------ src/libs/actions/ReportActions.ts | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 16adcc08e41a..a1f054f0100c 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -266,10 +266,6 @@ export default { tbd: 'TBD', selectCurrency: 'Select a currency', card: 'Card', - user: 'user', - users: 'users', - invited: 'invited', - removed: 'removed', }, location: { useCurrent: 'Use current location', @@ -1511,6 +1507,12 @@ export default { invitePeople: 'Invite new members', genericFailureMessage: 'An error occurred inviting the user to the workspace, please try again.', pleaseEnterValidLogin: `Please ensure the email or phone number is valid (e.g. ${CONST.EXAMPLE_PHONE_NUMBER}).`, + user: 'user', + users: 'users', + invited: 'invited', + removed: 'removed', + to: 'to', + from: 'from', }, inviteMessage: { inviteMessageTitle: 'Add message', diff --git a/src/languages/es.ts b/src/languages/es.ts index e3d0482d5cfa..cd5d6a7d435d 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -256,10 +256,6 @@ export default { tbd: 'Por determinar', selectCurrency: 'Selecciona una moneda', card: 'Tarjeta', - user: 'usuario', - users: 'usuarias', - invited: 'invitada', - removed: 'eliminado', }, location: { useCurrent: 'Usar ubicación actual', @@ -1532,6 +1528,12 @@ export default { invitePeople: 'Invitar nuevos miembros', genericFailureMessage: 'Se produjo un error al invitar al usuario al espacio de trabajo. Vuelva a intentarlo..', pleaseEnterValidLogin: `Asegúrese de que el correo electrónico o el número de teléfono sean válidos (p. ej. ${CONST.EXAMPLE_PHONE_NUMBER}).`, + user: 'usuario', + users: 'usuarias', + invited: 'invitada', + removed: 'eliminado', + to: 'a', + from: 'de' }, inviteMessage: { inviteMessageTitle: 'Añadir un mensaje', diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 871b0ef6c9a8..ee5916b66b4c 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -437,17 +437,17 @@ function getOptionData( const targetAccountIDs = lastAction?.originalMessage?.targetAccountIDs ?? []; const verb = lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? Localize.translate(preferredLocale, 'common.invited') - : Localize.translate(preferredLocale, 'common.removed'); - const users = Localize.translate(preferredLocale, targetAccountIDs.length > 1 ? 'common.users' : 'common.user'); + ? Localize.translate(preferredLocale, 'workspace.invite.invited') + : Localize.translate(preferredLocale, 'workspace.invite.removed'); + const users = Localize.translate(preferredLocale, targetAccountIDs.length > 1 ? 'workspace.invite.users' : 'workspace.invite.user'); result.alternateText = `${verb} ${targetAccountIDs.length} ${users}`; const roomName = lastAction?.originalMessage?.roomName ?? ''; if (roomName) { const preposition = lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? ` ${Localize.translate(preferredLocale, 'common.to')}` - : ` ${Localize.translate(preferredLocale, 'common.from')}`; + ? ` ${Localize.translate(preferredLocale, 'workspace.invite.to')}` + : ` ${Localize.translate(preferredLocale, 'workspace.invite.from')}`; result.alternateText += `${preposition} ${roomName}`; } } else if (lastAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lastActorDisplayName && lastMessageTextFromReport) { @@ -469,7 +469,7 @@ function getOptionData( return `${formattedText}.`; } if (index === displayNamesWithTooltips.length - 2) { - return `${formattedText} ${Localize.translate(preferredLocale, 'common.and')}`; + return `${formattedText} ${Localize.translate(preferredLocale, 'workspace.common.and')}`; } if (index < displayNamesWithTooltips.length - 2) { return `${formattedText},`; diff --git a/src/libs/actions/ReportActions.ts b/src/libs/actions/ReportActions.ts index c95a6f80057d..d0a276032ebe 100644 --- a/src/libs/actions/ReportActions.ts +++ b/src/libs/actions/ReportActions.ts @@ -52,7 +52,7 @@ function getReportActionMessageRoomChange(originalMessage: Message, targetAccoun return `${targetAccountIDs.length > 1 ? ', ' : ''}`; }); - const html = `${Localize.translateLocal('common.invited')} ${mentionTags.join('')} `; + const html = `${Localize.translateLocal('workspace.invite.invited')} ${mentionTags.join('')} `; const message: Message = { ...originalMessage, From 8c28a446b8274ce24395f3aeb424ffa56508820d Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 7 Nov 2023 17:46:21 +0700 Subject: [PATCH 04/32] fix translate key --- 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 e7fca8ef9971..ecea8776ac7a 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -480,7 +480,7 @@ function getOptionData( return `${formattedText}.`; } if (index === displayNamesWithTooltips.length - 2) { - return `${formattedText} ${Localize.translate(preferredLocale, 'workspace.common.and')}`; + return `${formattedText} ${Localize.translate(preferredLocale, 'common.and')}`; } if (index < displayNamesWithTooltips.length - 2) { return `${formattedText},`; From 5296fa5c0864fc6c2108164c5990fd8ab4fe7f76 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 7 Nov 2023 17:52:44 +0700 Subject: [PATCH 05/32] fix lint --- src/languages/es.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/es.ts b/src/languages/es.ts index bde5195cd4c7..3606adfeafeb 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1532,7 +1532,7 @@ export default { invited: 'invitada', removed: 'eliminado', to: 'a', - from: 'de' + from: 'de', }, inviteMessage: { inviteMessageTitle: 'Añadir un mensaje', From 201e78dacda49941780a9094fe84390bff9c5cd3 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Mon, 20 Nov 2023 21:37:35 +0700 Subject: [PATCH 06/32] update new change translate --- src/libs/ReportActionsUtils.ts | 10 ------ src/libs/ReportUtils.js | 12 +++---- src/libs/actions/ReportActions.ts | 33 ++++++++++++++----- .../home/report/ReportActionItemMessage.js | 6 ++-- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 41af659e4f1a..4615cac245ea 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -628,15 +628,6 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea return actions.includes(reportAction.actionName); } -function isMemberRoomChangeLog(reportAction: OnyxEntry): boolean { - if (!reportAction) { - return false; - } - - const actions: ActionName[] = [CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM, CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.REMOVE_FROM_ROOM]; - return actions.includes(reportAction.actionName); -} - export { extractLinksFromMessageHtml, getAllReportActions, @@ -678,6 +669,5 @@ export { shouldReportActionBeVisible, shouldReportActionBeVisibleAsLastAction, getFirstVisibleReportActionID, - isMemberRoomChangeLog, isChannelLogMemberAction, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 673cb09232de..808f6088d9c7 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4179,8 +4179,8 @@ function getIOUReportActionDisplayMessage(reportAction) { function getChannelLogMemberMessage(reportAction) { const verb = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? 'invited' - : 'removed'; + ? Localize.translateLocal('workspace.invite.invited') + : Localize.translateLocal('workspace.invite.removed'); const mentions = _.map(reportAction.originalMessage.targetAccountIDs, (accountID) => { const personalDetail = lodashGet(allPersonalDetails, accountID); @@ -4195,17 +4195,17 @@ function getChannelLogMemberMessage(reportAction) { if (mentions.length === 0) { message = `${verb} ${lastMention}`; } else if (mentions.length === 1) { - message = `${verb} ${mentions[0]} and ${lastMention}`; + message = `${verb} ${mentions[0]} ${Localize.translateLocal('common.and')} ${lastMention}`; } else { - message = `${verb} ${mentions.join(', ')}, and ${lastMention}`; + message = `${verb} ${mentions.join(', ')}, ${Localize.translateLocal('common.and')} ${lastMention}`; } const roomName = lodashGet(reportAction, 'originalMessage.roomName', ''); if (roomName) { const preposition = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? ' to' - : ' from'; + ? ` ${Localize.translateLocal('workspace.invite.to')}` + : ` ${Localize.translateLocal('workspace.invite.from')}` message += `${preposition} ${roomName}`; } diff --git a/src/libs/actions/ReportActions.ts b/src/libs/actions/ReportActions.ts index 768e596c0f4e..7ee1076e6fcd 100644 --- a/src/libs/actions/ReportActions.ts +++ b/src/libs/actions/ReportActions.ts @@ -4,9 +4,11 @@ import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import ReportAction, {Message} from '@src/types/onyx/ReportAction'; +import ReportAction, { Message } from '@src/types/onyx/ReportAction'; +import OriginalMessage from '@src/types/onyx/OriginalMessage'; import * as Report from './Report'; + function clearReportActionErrors(reportID: string, reportAction: ReportAction) { const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); @@ -46,9 +48,10 @@ function clearReportActionErrors(reportID: string, reportAction: ReportAction) { * @param targetAccountIDs * @returns */ -function getReportActionMessageRoomChange(originalMessage: Message, targetAccountIDs: number[]) { +function getReportActionMessageRoomChange(message: Message, originalMessage: OriginalMessage) { + const targetAccountIDs = 'targetAccountIDs' in originalMessage ? (originalMessage.targetAccountIDs as number[]) : []; if (targetAccountIDs.length === 0) { - return originalMessage; + return message; } const mentionTags = targetAccountIDs.map((accountID, index) => { @@ -58,18 +61,30 @@ function getReportActionMessageRoomChange(originalMessage: Message, targetAccoun return `${targetAccountIDs.length > 1 ? ', ' : ''}`; }); - const html = `${Localize.translateLocal('workspace.invite.invited')} ${mentionTags.join('')} `; + let html = `${Localize.translateLocal('workspace.invite.invited')} ${mentionTags.join('')}`; + + const preposition = + originalMessage.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || originalMessage.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM + ? ` ${Localize.translateLocal('workspace.invite.to')}` + : ` ${Localize.translateLocal('workspace.invite.from')}`; + + const regex = /]*>(.*?)<\/a>/; + const match = message.html ? message.html.match(regex) : ''; + if (match) { + const extractedATag = match[0]; + html += `${preposition} ${extractedATag}`; + } + + html += ``; - const message: Message = { - ...originalMessage, + return { + ...message, html, }; - - return message; } export { // eslint-disable-next-line import/prefer-default-export clearReportActionErrors, getReportActionMessageRoomChange, -}; +}; \ No newline at end of file diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index eee39bdb7b09..9626c2477274 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -42,10 +42,8 @@ function ReportActionItemMessage(props) { let fragments = _.compact(props.action.previousMessage || props.action.message); const isIOUReport = ReportActionsUtils.isMoneyRequestAction(props.action); - const isMemberChangeLog = ReportActionsUtils.isMemberRoomChangeLog(props.action); - if (isMemberChangeLog) { - const targetAccountIDs = props.action.originalMessage.targetAccountIDs; - fragments = [ReportActions.getReportActionMessageRoomChange(fragments[0], targetAccountIDs)]; + if (ReportActionsUtils.isChannelLogMemberAction(props.action)) { + fragments = [ReportActions.getReportActionMessageRoomChange(fragments[0], props.action.originalMessage)]; } let iouMessage; From f7c36f8eef7fa02c1727565059f8e6e200ce9b68 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Mon, 20 Nov 2023 21:38:20 +0700 Subject: [PATCH 07/32] fix prettier --- src/libs/ReportUtils.js | 2 +- src/libs/actions/ReportActions.ts | 5 ++--- src/pages/home/report/ReportActionItemMessage.js | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 808f6088d9c7..2848f69ad2a5 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4205,7 +4205,7 @@ function getChannelLogMemberMessage(reportAction) { const preposition = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM ? ` ${Localize.translateLocal('workspace.invite.to')}` - : ` ${Localize.translateLocal('workspace.invite.from')}` + : ` ${Localize.translateLocal('workspace.invite.from')}`; message += `${preposition} ${roomName}`; } diff --git a/src/libs/actions/ReportActions.ts b/src/libs/actions/ReportActions.ts index 7ee1076e6fcd..17aa442a4a7a 100644 --- a/src/libs/actions/ReportActions.ts +++ b/src/libs/actions/ReportActions.ts @@ -4,11 +4,10 @@ import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import ReportAction, { Message } from '@src/types/onyx/ReportAction'; import OriginalMessage from '@src/types/onyx/OriginalMessage'; +import ReportAction, {Message} from '@src/types/onyx/ReportAction'; import * as Report from './Report'; - function clearReportActionErrors(reportID: string, reportAction: ReportAction) { const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); @@ -87,4 +86,4 @@ export { // eslint-disable-next-line import/prefer-default-export clearReportActionErrors, getReportActionMessageRoomChange, -}; \ No newline at end of file +}; diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index 9626c2477274..064e70070bb9 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -6,8 +6,8 @@ import _ from 'underscore'; import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; -import * as ReportActions from '@userActions/ReportActions'; import useThemeStyles from '@styles/useThemeStyles'; +import * as ReportActions from '@userActions/ReportActions'; import CONST from '@src/CONST'; import ReportActionItemFragment from './ReportActionItemFragment'; import reportActionPropTypes from './reportActionPropTypes'; From 794dd7af543189aaae5bcb6465582b25c7196d81 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Mon, 20 Nov 2023 21:40:28 +0700 Subject: [PATCH 08/32] remove space --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 2848f69ad2a5..983f23ec602f 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4197,7 +4197,7 @@ function getChannelLogMemberMessage(reportAction) { } else if (mentions.length === 1) { message = `${verb} ${mentions[0]} ${Localize.translateLocal('common.and')} ${lastMention}`; } else { - message = `${verb} ${mentions.join(', ')}, ${Localize.translateLocal('common.and')} ${lastMention}`; + message = `${verb} ${mentions.join(', ')}, ${Localize.translateLocal('common.and')} ${lastMention}`; } const roomName = lodashGet(reportAction, 'originalMessage.roomName', ''); From 5a356071bc6f039986e35ac7e0d27df051dc0af9 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Mon, 20 Nov 2023 23:12:01 +0700 Subject: [PATCH 09/32] fix reuse get message --- src/libs/ReportUtils.js | 17 +++++-- src/libs/actions/ReportActions.ts | 45 +------------------ .../home/report/ReportActionItemMessage.js | 6 +-- 3 files changed, 17 insertions(+), 51 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 983f23ec602f..ca22ee50d00d 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4174,15 +4174,19 @@ function getIOUReportActionDisplayMessage(reportAction) { * Return room channel log display message * * @param {Object} reportAction + * @param {Boolean} isHtml * @returns {String} */ -function getChannelLogMemberMessage(reportAction) { +function getChannelLogMemberMessage(reportAction, isHtml) { const verb = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); const mentions = _.map(reportAction.originalMessage.targetAccountIDs, (accountID) => { + if (isHtml) { + return ``; + } const personalDetail = lodashGet(allPersonalDetails, accountID); const displayNameOrLogin = LocalePhoneNumber.formatPhoneNumber(lodashGet(personalDetail, 'login', '')) || lodashGet(personalDetail, 'displayName', '') || Localize.translateLocal('common.hidden'); @@ -4190,7 +4194,7 @@ function getChannelLogMemberMessage(reportAction) { }); const lastMention = mentions.pop(); - let message = ''; + let message = isHtml ? '' : ''; if (mentions.length === 0) { message = `${verb} ${lastMention}`; @@ -4206,9 +4210,16 @@ function getChannelLogMemberMessage(reportAction) { reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM ? ` ${Localize.translateLocal('workspace.invite.to')}` : ` ${Localize.translateLocal('workspace.invite.from')}`; - message += `${preposition} ${roomName}`; + + const messageHtml = lodashGet(reportAction, ['message', 0, 'html']); + const match = messageHtml && messageHtml.match(/]*>(.*?)<\/a>/); + const extractedATag = match ? match[0] : ''; + + message += `${preposition} ${isHtml ? extractedATag : roomName}`; } + message += isHtml ? '' : ''; + return message; } diff --git a/src/libs/actions/ReportActions.ts b/src/libs/actions/ReportActions.ts index 17aa442a4a7a..d7ff96fc6c2e 100644 --- a/src/libs/actions/ReportActions.ts +++ b/src/libs/actions/ReportActions.ts @@ -1,11 +1,9 @@ import Onyx from 'react-native-onyx'; -import * as Localize from '@libs/Localize'; import * as ReportActionUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import OriginalMessage from '@src/types/onyx/OriginalMessage'; -import ReportAction, {Message} from '@src/types/onyx/ReportAction'; +import ReportAction from '@src/types/onyx/ReportAction'; import * as Report from './Report'; function clearReportActionErrors(reportID: string, reportAction: ReportAction) { @@ -42,48 +40,7 @@ function clearReportActionErrors(reportID: string, reportAction: ReportAction) { }); } -/** - * @param originalMessage - * @param targetAccountIDs - * @returns - */ -function getReportActionMessageRoomChange(message: Message, originalMessage: OriginalMessage) { - const targetAccountIDs = 'targetAccountIDs' in originalMessage ? (originalMessage.targetAccountIDs as number[]) : []; - if (targetAccountIDs.length === 0) { - return message; - } - - const mentionTags = targetAccountIDs.map((accountID, index) => { - if (index === targetAccountIDs.length - 1 && index !== 0) { - return `${Localize.translateLocal('common.and')} `; - } - return `${targetAccountIDs.length > 1 ? ', ' : ''}`; - }); - - let html = `${Localize.translateLocal('workspace.invite.invited')} ${mentionTags.join('')}`; - - const preposition = - originalMessage.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || originalMessage.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? ` ${Localize.translateLocal('workspace.invite.to')}` - : ` ${Localize.translateLocal('workspace.invite.from')}`; - - const regex = /]*>(.*?)<\/a>/; - const match = message.html ? message.html.match(regex) : ''; - if (match) { - const extractedATag = match[0]; - html += `${preposition} ${extractedATag}`; - } - - html += ``; - - return { - ...message, - html, - }; -} - export { // eslint-disable-next-line import/prefer-default-export clearReportActionErrors, - getReportActionMessageRoomChange, }; diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index 064e70070bb9..d5108ff5e6d7 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -7,7 +7,6 @@ import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import useThemeStyles from '@styles/useThemeStyles'; -import * as ReportActions from '@userActions/ReportActions'; import CONST from '@src/CONST'; import ReportActionItemFragment from './ReportActionItemFragment'; import reportActionPropTypes from './reportActionPropTypes'; @@ -39,11 +38,10 @@ const defaultProps = { function ReportActionItemMessage(props) { const styles = useThemeStyles(); - let fragments = _.compact(props.action.previousMessage || props.action.message); + const fragments = _.compact(props.action.previousMessage || props.action.message); const isIOUReport = ReportActionsUtils.isMoneyRequestAction(props.action); - if (ReportActionsUtils.isChannelLogMemberAction(props.action)) { - fragments = [ReportActions.getReportActionMessageRoomChange(fragments[0], props.action.originalMessage)]; + fragments[0].html = ReportUtils.getChannelLogMemberMessage(props.action, true); } let iouMessage; From 3a957938df06555f48833dd3f8fe6e8dd15f3654 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Thu, 23 Nov 2023 00:08:38 +0700 Subject: [PATCH 10/32] refactor, build link room --- src/libs/ReportActionsUtils.ts | 140 +++++++++++++++++- src/libs/ReportUtils.js | 52 +------ .../report/ContextMenu/ContextMenuActions.js | 2 +- .../home/report/ReportActionItemMessage.js | 13 +- src/types/onyx/OriginalMessage.ts | 18 +-- 5 files changed, 166 insertions(+), 59 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 4615cac245ea..d961aa87172f 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -5,12 +5,15 @@ import OnyxUtils from 'react-native-onyx/lib/utils'; import {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import {ActionName} from '@src/types/onyx/OriginalMessage'; +import {ActionName, CommonOriginalMessage} from '@src/types/onyx/OriginalMessage'; +import PersonalDetails from '@src/types/onyx/PersonalDetails'; import Report from '@src/types/onyx/Report'; import ReportAction, {ReportActions} from '@src/types/onyx/ReportAction'; import * as CollectionUtils from './CollectionUtils'; import * as Environment from './Environment/Environment'; import isReportMessageAttachment from './isReportMessageAttachment'; +import * as LocalePhoneNumber from './LocalePhoneNumber'; +import * as Localize from './Localize'; import Log from './Log'; type LastVisibleMessage = { @@ -19,6 +22,15 @@ type LastVisibleMessage = { lastMessageHtml?: string; }; +type MessageActionItemChanelLog = { + kind: string; + content?: string; + accountID?: number; + isComma?: boolean; + roomName?: string; + roomID?: number; +}; + const allReports: OnyxCollection = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, @@ -45,6 +57,12 @@ Onyx.connect({ }, }); +let allPersonalDetails: OnyxEntry> = null; +Onyx.connect({ + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + callback: (val) => (allPersonalDetails = val), +}); + let isNetworkOffline = false; Onyx.connect({ key: ONYXKEYS.NETWORK, @@ -628,6 +646,124 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea return actions.includes(reportAction.actionName); } +function getChannelLogMemberAction(reportAction: OnyxEntry) { + const messageItems: MessageActionItemChanelLog[] = []; + const verb = + reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM + ? Localize.translateLocal('workspace.invite.invited') + : Localize.translateLocal('workspace.invite.removed'); + + messageItems.push({ + kind: 'text', + content: `${verb} `, + }); + + const originalMessage = reportAction?.originalMessage as CommonOriginalMessage; + const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? []; + const mentions = targetAccountIDs.map((accountID) => { + const personalDetail = allPersonalDetails?.[accountID]; + + if (personalDetail) { + const displayNameOrLogin = + LocalePhoneNumber.formatPhoneNumber(personalDetail.login ?? '') || personalDetail?.displayName ? personalDetail?.displayName : Localize.translateLocal('common.hidden'); + return {content: `@${displayNameOrLogin}`, accountID}; + } + return {content: '', accountID: 0}; + }); + + const lastMention = mentions.pop(); + + if (mentions.length === 0) { + messageItems.push({ + kind: 'userMention', + ...lastMention, + }); + } else if (mentions.length === 1) { + messageItems.push( + { + kind: 'userMention', + ...mentions[0], + }, + { + kind: 'text', + content: ` ${Localize.translateLocal('common.and')} `, + }, + { + kind: 'userMention', + ...lastMention, + }, + ); + } else { + mentions.forEach((mention) => { + messageItems.push({ + kind: 'userMention', + ...mention, + content: `${mention.content}, `, + isComma: true, + }); + }); + + messageItems.push( + { + kind: 'text', + content: `${Localize.translateLocal('common.and')} `, + }, + { + kind: 'userMention', + ...lastMention, + }, + ); + } + + const roomName = originalMessage?.roomName; + if (roomName) { + const preposition = + reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM + ? ` ${Localize.translateLocal('workspace.invite.to')} ` + : ` ${Localize.translateLocal('workspace.invite.from')} `; + + messageItems.push( + { + kind: 'text', + content: preposition, + }, + { + kind: 'roomReference', + roomName, + roomID: originalMessage?.reportID, + content: roomName, + }, + ); + } + + return messageItems; +} + +function getActionItemFragmentChanelLog(reportAction: OnyxEntry) { + const messageItems: MessageActionItemChanelLog[] = getChannelLogMemberAction(reportAction); + let html = ''; + messageItems.forEach((messageItem) => { + switch (messageItem.kind) { + case 'userMention': + html += `${messageItem.isComma ? ', ' : ''}`; + break; + case 'roomReference': + html += `${messageItem.roomName}`; + break; + default: + html += messageItem.content; + } + }); + + html += ''; + + return { + html, + text: reportAction?.message ? reportAction?.message[0].text : '', + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + }; +} + export { extractLinksFromMessageHtml, getAllReportActions, @@ -670,4 +806,6 @@ export { shouldReportActionBeVisibleAsLastAction, getFirstVisibleReportActionID, isChannelLogMemberAction, + getChannelLogMemberAction, + getActionItemFragmentChanelLog, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index ca22ee50d00d..1d018e1a7075 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4171,56 +4171,14 @@ function getIOUReportActionDisplayMessage(reportAction) { } /** - * Return room channel log display message + * Return room channel log message * * @param {Object} reportAction - * @param {Boolean} isHtml * @returns {String} */ -function getChannelLogMemberMessage(reportAction, isHtml) { - const verb = - reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? Localize.translateLocal('workspace.invite.invited') - : Localize.translateLocal('workspace.invite.removed'); - - const mentions = _.map(reportAction.originalMessage.targetAccountIDs, (accountID) => { - if (isHtml) { - return ``; - } - const personalDetail = lodashGet(allPersonalDetails, accountID); - const displayNameOrLogin = - LocalePhoneNumber.formatPhoneNumber(lodashGet(personalDetail, 'login', '')) || lodashGet(personalDetail, 'displayName', '') || Localize.translateLocal('common.hidden'); - return `@${displayNameOrLogin}`; - }); - - const lastMention = mentions.pop(); - let message = isHtml ? '' : ''; - - if (mentions.length === 0) { - message = `${verb} ${lastMention}`; - } else if (mentions.length === 1) { - message = `${verb} ${mentions[0]} ${Localize.translateLocal('common.and')} ${lastMention}`; - } else { - message = `${verb} ${mentions.join(', ')}, ${Localize.translateLocal('common.and')} ${lastMention}`; - } - - const roomName = lodashGet(reportAction, 'originalMessage.roomName', ''); - if (roomName) { - const preposition = - reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? ` ${Localize.translateLocal('workspace.invite.to')}` - : ` ${Localize.translateLocal('workspace.invite.from')}`; - - const messageHtml = lodashGet(reportAction, ['message', 0, 'html']); - const match = messageHtml && messageHtml.match(/]*>(.*?)<\/a>/); - const extractedATag = match ? match[0] : ''; - - message += `${preposition} ${isHtml ? extractedATag : roomName}`; - } - - message += isHtml ? '' : ''; - - return message; +function getChannelLogMemberMessagePlainText(reportAction) { + const messageItems = ReportActionsUtils.getChannelLogMemberAction(reportAction); + return _.map(messageItems, (item) => item.content).join(''); } /** @@ -4286,6 +4244,7 @@ function shouldDisableWelcomeMessage(report, policy) { } export { + getChannelLogMemberMessagePlainText, getReportParticipantsTitle, isReportMessageAttachment, findLastAccessedReport, @@ -4445,7 +4404,6 @@ export { parseReportRouteParams, getReimbursementQueuedActionMessage, getPersonalDetailsForAccountID, - getChannelLogMemberMessage, getRoom, shouldDisableWelcomeMessage, }; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 4f35926c5957..d5a5ea17608d 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -282,7 +282,7 @@ export default [ const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction); Clipboard.setString(displayMessage); } else if (ReportActionsUtils.isChannelLogMemberAction(reportAction)) { - const logMessage = ReportUtils.getChannelLogMemberMessage(reportAction); + const logMessage = ReportUtils.getChannelLogMemberMessagePlainText(reportAction); Clipboard.setString(logMessage); } else if (content) { const parser = new ExpensiMark(); diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index d5108ff5e6d7..af9b5265ffc2 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -8,6 +8,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import useThemeStyles from '@styles/useThemeStyles'; import CONST from '@src/CONST'; +import TextCommentFragment from './comment/TextCommentFragment'; import ReportActionItemFragment from './ReportActionItemFragment'; import reportActionPropTypes from './reportActionPropTypes'; @@ -41,7 +42,17 @@ function ReportActionItemMessage(props) { const fragments = _.compact(props.action.previousMessage || props.action.message); const isIOUReport = ReportActionsUtils.isMoneyRequestAction(props.action); if (ReportActionsUtils.isChannelLogMemberAction(props.action)) { - fragments[0].html = ReportUtils.getChannelLogMemberMessage(props.action, true); + const fragment = ReportActionsUtils.getActionItemFragmentChanelLog(props.action); + + return ( + + ); } let iouMessage; diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index b5e4b25a6508..33d0c7061915 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -144,20 +144,20 @@ type OriginalMessageReportPreview = { }; }; +type CommonOriginalMessage = { + targetAccountIDs?: number[]; + roomName?: string; + reportID?: number; +}; + type OriginalMessagePolicyChangeLog = { actionName: ValueOf; - originalMessage: { - targetAccountIDs?: number[]; - roomName?: string; - }; + originalMessage?: CommonOriginalMessage; }; type OriginalMessageRoomChangeLog = { actionName: ValueOf; - originalMessage: { - targetAccountIDs?: number[]; - roomName?: string; - }; + originalMessage?: CommonOriginalMessage; }; type OriginalMessagePolicyTask = { @@ -196,4 +196,4 @@ type OriginalMessage = | OriginalMessageReimbursementQueued; export default OriginalMessage; -export type {ChronosOOOEvent, Decision, Reaction, ActionName}; +export type {ChronosOOOEvent, Decision, Reaction, ActionName, CommonOriginalMessage}; From b8326c76f39f5440999b9f832ab162edec162d06 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Thu, 23 Nov 2023 01:11:14 +0700 Subject: [PATCH 11/32] refactor --- src/libs/ReportActionsUtils.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index d961aa87172f..66b5f0e05000 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -123,6 +123,10 @@ function isChannelLogMemberAction(reportAction: OnyxEntry) { ); } +function isInvitedRoom(reportAction: OnyxEntry) { + return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM; +} + /** * Returns whether the comment is a thread parent message/the first message in a thread */ @@ -648,10 +652,9 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea function getChannelLogMemberAction(reportAction: OnyxEntry) { const messageItems: MessageActionItemChanelLog[] = []; - const verb = - reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? Localize.translateLocal('workspace.invite.invited') - : Localize.translateLocal('workspace.invite.removed'); + const isInviteRoom = isInvitedRoom(reportAction); + + const verb = isInviteRoom ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); messageItems.push({ kind: 'text', @@ -717,10 +720,7 @@ function getChannelLogMemberAction(reportAction: OnyxEntry) { const roomName = originalMessage?.roomName; if (roomName) { - const preposition = - reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM - ? ` ${Localize.translateLocal('workspace.invite.to')} ` - : ` ${Localize.translateLocal('workspace.invite.from')} `; + const preposition = isInviteRoom ? ` ${Localize.translateLocal('workspace.invite.to')} ` : ` ${Localize.translateLocal('workspace.invite.from')} `; messageItems.push( { @@ -808,4 +808,5 @@ export { isChannelLogMemberAction, getChannelLogMemberAction, getActionItemFragmentChanelLog, + isInvitedRoom, }; From dd0e9c31d71657941347c4b9cdad50dbd43baeac Mon Sep 17 00:00:00 2001 From: Nam Le Date: Thu, 23 Nov 2023 09:16:14 +0700 Subject: [PATCH 12/32] add target for link --- src/libs/ReportActionsUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 8d627dd2224e..0da36c86daf7 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -745,13 +745,14 @@ function getChannelLogMemberAction(reportAction: OnyxEntry) { function getActionItemFragmentChanelLog(reportAction: OnyxEntry) { const messageItems: MessageActionItemChanelLog[] = getChannelLogMemberAction(reportAction); let html = ''; + messageItems.forEach((messageItem) => { switch (messageItem.kind) { case 'userMention': html += `${messageItem.isComma ? ', ' : ''}`; break; case 'roomReference': - html += `${messageItem.roomName}`; + html += `${messageItem.roomName}`; break; default: html += messageItem.content; From a6693d060862cff853adf5129117fd6ec059edc7 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Thu, 23 Nov 2023 19:31:58 +0700 Subject: [PATCH 13/32] fix: some convetion and refactor --- src/libs/ReportActionsUtils.ts | 49 +++++++++++-------- .../home/report/ReportActionItemMessage.js | 2 +- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 0da36c86daf7..5c04de1e0854 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -6,15 +6,15 @@ import {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import {ActionName, CommonOriginalMessage} from '@src/types/onyx/OriginalMessage'; -import PersonalDetails from '@src/types/onyx/PersonalDetails'; import Report from '@src/types/onyx/Report'; -import ReportAction, {ReportActions} from '@src/types/onyx/ReportAction'; +import ReportAction, {Message, ReportActions} from '@src/types/onyx/ReportAction'; import * as CollectionUtils from './CollectionUtils'; import * as Environment from './Environment/Environment'; import isReportMessageAttachment from './isReportMessageAttachment'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import Log from './Log'; +import * as PersonalDetailsUtils from './PersonalDetailsUtils'; type LastVisibleMessage = { lastMessageTranslationKey?: string; @@ -22,14 +22,29 @@ type LastVisibleMessage = { lastMessageHtml?: string; }; -type MessageActionItemChanelLog = { - kind: string; +type MessageActionItemChanelLogBase = { + readonly kind: string; content?: string; +}; + +type MessageActionItemChanelLogText = { + readonly kind: 'text'; + content?: string; +}; + +type MessageActionItemChanelLogUserMention = { + readonly kind: 'userMention'; accountID?: number; isComma?: boolean; +} & MessageActionItemChanelLogBase; + +type MessageActionItemChanelLogRoomReference = { + readonly kind: 'roomReference'; roomName?: string; roomID?: number; -}; +} & MessageActionItemChanelLogBase; + +type MessageActionItemChanelLog = MessageActionItemChanelLogText | MessageActionItemChanelLogUserMention | MessageActionItemChanelLogRoomReference; const allReports: OnyxCollection = {}; Onyx.connect({ @@ -57,12 +72,6 @@ Onyx.connect({ }, }); -let allPersonalDetails: OnyxEntry> = null; -Onyx.connect({ - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - callback: (val) => (allPersonalDetails = val), -}); - let isNetworkOffline = false; Onyx.connect({ key: ONYXKEYS.NETWORK, @@ -653,7 +662,7 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea return actions.includes(reportAction.actionName); } -function getChannelLogMemberAction(reportAction: OnyxEntry) { +function getChannelLogMemberAction(reportAction: OnyxEntry): MessageActionItemChanelLog[] { const messageItems: MessageActionItemChanelLog[] = []; const isInviteRoom = isInvitedRoom(reportAction); @@ -666,12 +675,14 @@ function getChannelLogMemberAction(reportAction: OnyxEntry) { const originalMessage = reportAction?.originalMessage as CommonOriginalMessage; const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? []; + const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0); + const mentions = targetAccountIDs.map((accountID) => { - const personalDetail = allPersonalDetails?.[accountID]; + const personalDetail = personalDetails.find((personal) => personal.accountID === accountID); if (personalDetail) { const displayNameOrLogin = - LocalePhoneNumber.formatPhoneNumber(personalDetail.login ?? '') || personalDetail?.displayName ? personalDetail?.displayName : Localize.translateLocal('common.hidden'); + LocalePhoneNumber.formatPhoneNumber(personalDetail.login ?? '') || (personalDetail?.displayName ? personalDetail?.displayName : Localize.translateLocal('common.hidden')); return {content: `@${displayNameOrLogin}`, accountID}; } return {content: '', accountID: 0}; @@ -742,9 +753,9 @@ function getChannelLogMemberAction(reportAction: OnyxEntry) { return messageItems; } -function getActionItemFragmentChanelLog(reportAction: OnyxEntry) { +function getActionItemFragmentChanelLogFragment(reportAction: OnyxEntry): Message { const messageItems: MessageActionItemChanelLog[] = getChannelLogMemberAction(reportAction); - let html = ''; + let html = ''; messageItems.forEach((messageItem) => { switch (messageItem.kind) { @@ -759,10 +770,8 @@ function getActionItemFragmentChanelLog(reportAction: OnyxEntry) { } }); - html += ''; - return { - html, + html: `${html}`, text: reportAction?.message ? reportAction?.message[0].text : '', type: CONST.REPORT.MESSAGE.TYPE.COMMENT, }; @@ -832,6 +841,6 @@ export { getFirstVisibleReportActionID, isChannelLogMemberAction, getChannelLogMemberAction, - getActionItemFragmentChanelLog, + getActionItemFragmentChanelLogFragment, isInvitedRoom, }; diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index af9b5265ffc2..dcc2bcf70ae2 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -42,7 +42,7 @@ function ReportActionItemMessage(props) { const fragments = _.compact(props.action.previousMessage || props.action.message); const isIOUReport = ReportActionsUtils.isMoneyRequestAction(props.action); if (ReportActionsUtils.isChannelLogMemberAction(props.action)) { - const fragment = ReportActionsUtils.getActionItemFragmentChanelLog(props.action); + const fragment = ReportActionsUtils.getActionItemFragmentChanelLogFragment(props.action); return ( Date: Fri, 24 Nov 2023 17:16:33 +0700 Subject: [PATCH 14/32] fix: handle comma --- src/libs/ReportActionsUtils.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 5c04de1e0854..ee04ca214c33 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -35,7 +35,6 @@ type MessageActionItemChanelLogText = { type MessageActionItemChanelLogUserMention = { readonly kind: 'userMention'; accountID?: number; - isComma?: boolean; } & MessageActionItemChanelLogBase; type MessageActionItemChanelLogRoomReference = { @@ -712,12 +711,17 @@ function getChannelLogMemberAction(reportAction: OnyxEntry): Messa ); } else { mentions.forEach((mention) => { - messageItems.push({ - kind: 'userMention', - ...mention, - content: `${mention.content}, `, - isComma: true, - }); + messageItems.push( + { + kind: 'userMention', + ...mention, + content: `${mention.content}`, + }, + { + kind: 'text', + content: `, `, + }, + ); }); messageItems.push( @@ -760,7 +764,7 @@ function getActionItemFragmentChanelLogFragment(reportAction: OnyxEntry { switch (messageItem.kind) { case 'userMention': - html += `${messageItem.isComma ? ', ' : ''}`; + html += ``; break; case 'roomReference': html += `${messageItem.roomName}`; From 65015263049259290d1ceeb6c0b36049139642cb Mon Sep 17 00:00:00 2001 From: Nam Le Date: Mon, 27 Nov 2023 19:11:49 +0700 Subject: [PATCH 15/32] fix: type and logic mention --- src/libs/ReportActionsUtils.ts | 64 +++++++++++-------- .../home/report/ReportActionItemMessage.js | 2 +- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index ee04ca214c33..e4e8eaa3d104 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -24,23 +24,23 @@ type LastVisibleMessage = { type MessageActionItemChanelLogBase = { readonly kind: string; - content?: string; + readonly content: string; }; type MessageActionItemChanelLogText = { readonly kind: 'text'; - content?: string; + readonly content: string; }; type MessageActionItemChanelLogUserMention = { readonly kind: 'userMention'; - accountID?: number; + readonly accountID: number; } & MessageActionItemChanelLogBase; type MessageActionItemChanelLogRoomReference = { readonly kind: 'roomReference'; - roomName?: string; - roomID?: number; + readonly roomName: string; + readonly roomID: number; } & MessageActionItemChanelLogBase; type MessageActionItemChanelLog = MessageActionItemChanelLogText | MessageActionItemChanelLogUserMention | MessageActionItemChanelLogRoomReference; @@ -676,29 +676,34 @@ function getChannelLogMemberAction(reportAction: OnyxEntry): Messa const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? []; const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0); - const mentions = targetAccountIDs.map((accountID) => { + const mentions: MessageActionItemChanelLogUserMention[] = targetAccountIDs.map((accountID) => { const personalDetail = personalDetails.find((personal) => personal.accountID === accountID); if (personalDetail) { const displayNameOrLogin = LocalePhoneNumber.formatPhoneNumber(personalDetail.login ?? '') || (personalDetail?.displayName ? personalDetail?.displayName : Localize.translateLocal('common.hidden')); - return {content: `@${displayNameOrLogin}`, accountID}; + return {content: `@${displayNameOrLogin}`, accountID} as MessageActionItemChanelLogUserMention; } - return {content: '', accountID: 0}; + return {content: `@${Localize.translateLocal('common.hidden')}`, accountID} as MessageActionItemChanelLogUserMention; }); const lastMention = mentions.pop(); + if (!lastMention) { + return []; + } if (mentions.length === 0) { messageItems.push({ kind: 'userMention', - ...lastMention, + content: lastMention.content, + accountID: lastMention.accountID, }); } else if (mentions.length === 1) { messageItems.push( { kind: 'userMention', - ...mentions[0], + content: mentions[0].content, + accountID: mentions[0].accountID, }, { kind: 'text', @@ -706,7 +711,8 @@ function getChannelLogMemberAction(reportAction: OnyxEntry): Messa }, { kind: 'userMention', - ...lastMention, + content: lastMention.content, + accountID: lastMention.accountID, }, ); } else { @@ -714,7 +720,7 @@ function getChannelLogMemberAction(reportAction: OnyxEntry): Messa messageItems.push( { kind: 'userMention', - ...mention, + accountID: mention.accountID, content: `${mention.content}`, }, { @@ -731,7 +737,8 @@ function getChannelLogMemberAction(reportAction: OnyxEntry): Messa }, { kind: 'userMention', - ...lastMention, + content: lastMention.content, + accountID: lastMention.accountID, }, ); } @@ -740,24 +747,26 @@ function getChannelLogMemberAction(reportAction: OnyxEntry): Messa if (roomName) { const preposition = isInviteRoom ? ` ${Localize.translateLocal('workspace.invite.to')} ` : ` ${Localize.translateLocal('workspace.invite.from')} `; - messageItems.push( - { - kind: 'text', - content: preposition, - }, - { - kind: 'roomReference', - roomName, - roomID: originalMessage?.reportID, - content: roomName, - }, - ); + if (originalMessage.reportID) { + messageItems.push( + { + kind: 'text', + content: preposition, + }, + { + kind: 'roomReference', + roomName, + roomID: originalMessage.reportID, + content: roomName, + }, + ); + } } return messageItems; } -function getActionItemFragmentChanelLogFragment(reportAction: OnyxEntry): Message { +function getActionItemFragmentChannelLogFragment(reportAction: OnyxEntry): Message { const messageItems: MessageActionItemChanelLog[] = getChannelLogMemberAction(reportAction); let html = ''; @@ -845,6 +854,5 @@ export { getFirstVisibleReportActionID, isChannelLogMemberAction, getChannelLogMemberAction, - getActionItemFragmentChanelLogFragment, - isInvitedRoom, + getActionItemFragmentChannelLogFragment, }; diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index dcc2bcf70ae2..977a25fa4284 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -42,7 +42,7 @@ function ReportActionItemMessage(props) { const fragments = _.compact(props.action.previousMessage || props.action.message); const isIOUReport = ReportActionsUtils.isMoneyRequestAction(props.action); if (ReportActionsUtils.isChannelLogMemberAction(props.action)) { - const fragment = ReportActionsUtils.getActionItemFragmentChanelLogFragment(props.action); + const fragment = ReportActionsUtils.getActionItemFragmentChannelLogFragment(props.action); return ( Date: Mon, 27 Nov 2023 19:20:50 +0700 Subject: [PATCH 16/32] fix: typo --- src/libs/ReportActionsUtils.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index e4e8eaa3d104..29360e6ac7ea 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -22,28 +22,28 @@ type LastVisibleMessage = { lastMessageHtml?: string; }; -type MessageActionItemChanelLogBase = { +type MessageActionItemChannelLogBase = { readonly kind: string; readonly content: string; }; -type MessageActionItemChanelLogText = { +type MessageActionItemChannelLogText = { readonly kind: 'text'; readonly content: string; }; -type MessageActionItemChanelLogUserMention = { +type MessageActionItemChannelLogUserMention = { readonly kind: 'userMention'; readonly accountID: number; -} & MessageActionItemChanelLogBase; +} & MessageActionItemChannelLogBase; -type MessageActionItemChanelLogRoomReference = { +type MessageActionItemChannelLogRoomReference = { readonly kind: 'roomReference'; readonly roomName: string; readonly roomID: number; -} & MessageActionItemChanelLogBase; +} & MessageActionItemChannelLogBase; -type MessageActionItemChanelLog = MessageActionItemChanelLogText | MessageActionItemChanelLogUserMention | MessageActionItemChanelLogRoomReference; +type MessageActionItemChannelLog = MessageActionItemChannelLogText | MessageActionItemChannelLogUserMention | MessageActionItemChannelLogRoomReference; const allReports: OnyxCollection = {}; Onyx.connect({ @@ -661,8 +661,8 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea return actions.includes(reportAction.actionName); } -function getChannelLogMemberAction(reportAction: OnyxEntry): MessageActionItemChanelLog[] { - const messageItems: MessageActionItemChanelLog[] = []; +function getChannelLogMemberAction(reportAction: OnyxEntry): MessageActionItemChannelLog[] { + const messageItems: MessageActionItemChannelLog[] = []; const isInviteRoom = isInvitedRoom(reportAction); const verb = isInviteRoom ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); @@ -676,15 +676,15 @@ function getChannelLogMemberAction(reportAction: OnyxEntry): Messa const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? []; const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0); - const mentions: MessageActionItemChanelLogUserMention[] = targetAccountIDs.map((accountID) => { + const mentions: MessageActionItemChannelLogUserMention[] = targetAccountIDs.map((accountID) => { const personalDetail = personalDetails.find((personal) => personal.accountID === accountID); if (personalDetail) { const displayNameOrLogin = LocalePhoneNumber.formatPhoneNumber(personalDetail.login ?? '') || (personalDetail?.displayName ? personalDetail?.displayName : Localize.translateLocal('common.hidden')); - return {content: `@${displayNameOrLogin}`, accountID} as MessageActionItemChanelLogUserMention; + return {content: `@${displayNameOrLogin}`, accountID} as MessageActionItemChannelLogUserMention; } - return {content: `@${Localize.translateLocal('common.hidden')}`, accountID} as MessageActionItemChanelLogUserMention; + return {content: `@${Localize.translateLocal('common.hidden')}`, accountID} as MessageActionItemChannelLogUserMention; }); const lastMention = mentions.pop(); @@ -767,7 +767,7 @@ function getChannelLogMemberAction(reportAction: OnyxEntry): Messa } function getActionItemFragmentChannelLogFragment(reportAction: OnyxEntry): Message { - const messageItems: MessageActionItemChanelLog[] = getChannelLogMemberAction(reportAction); + const messageItems: MessageActionItemChannelLog[] = getChannelLogMemberAction(reportAction); let html = ''; messageItems.forEach((messageItem) => { From 1dcc21693d3b2db11f8992e954b9cfad5b822e0f Mon Sep 17 00:00:00 2001 From: Nam Le Date: Mon, 27 Nov 2023 23:36:03 +0700 Subject: [PATCH 17/32] fix: name convention --- src/libs/ReportActionsUtils.ts | 54 +++++++++++-------- src/libs/ReportUtils.js | 12 ----- .../report/ContextMenu/ContextMenuActions.js | 2 +- .../home/report/ReportActionItemMessage.js | 2 +- src/types/onyx/OriginalMessage.ts | 8 +-- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 29360e6ac7ea..e5411b6e997e 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -5,7 +5,7 @@ import OnyxUtils from 'react-native-onyx/lib/utils'; import {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import {ActionName, CommonOriginalMessage} from '@src/types/onyx/OriginalMessage'; +import {ActionName, ChangeLogOriginalMessage} from '@src/types/onyx/OriginalMessage'; import Report from '@src/types/onyx/Report'; import ReportAction, {Message, ReportActions} from '@src/types/onyx/ReportAction'; import * as CollectionUtils from './CollectionUtils'; @@ -22,28 +22,28 @@ type LastVisibleMessage = { lastMessageHtml?: string; }; -type MessageActionItemChannelLogBase = { +type MemberChangeMessageElementBase = { readonly kind: string; readonly content: string; }; -type MessageActionItemChannelLogText = { +type MemberChangeMessageTextElement = { readonly kind: 'text'; readonly content: string; }; -type MessageActionItemChannelLogUserMention = { +type MemberChangeMessageUserMentionElement = { readonly kind: 'userMention'; readonly accountID: number; -} & MessageActionItemChannelLogBase; +} & MemberChangeMessageElementBase; -type MessageActionItemChannelLogRoomReference = { +type MemberChangeMessageRoomReferenceElement = { readonly kind: 'roomReference'; readonly roomName: string; readonly roomID: number; -} & MessageActionItemChannelLogBase; +} & MemberChangeMessageElementBase; -type MessageActionItemChannelLog = MessageActionItemChannelLogText | MessageActionItemChannelLogUserMention | MessageActionItemChannelLogRoomReference; +type MessageActionItemChannelLog = MemberChangeMessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement; const allReports: OnyxCollection = {}; Onyx.connect({ @@ -131,7 +131,7 @@ function isChannelLogMemberAction(reportAction: OnyxEntry) { ); } -function isInvitedRoom(reportAction: OnyxEntry) { +function isInviteMemberAction(reportAction: OnyxEntry) { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM; } @@ -661,30 +661,30 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea return actions.includes(reportAction.actionName); } -function getChannelLogMemberAction(reportAction: OnyxEntry): MessageActionItemChannelLog[] { +function getMemberChangeMessageElements(reportAction: OnyxEntry): MessageActionItemChannelLog[] { const messageItems: MessageActionItemChannelLog[] = []; - const isInviteRoom = isInvitedRoom(reportAction); + const isInviteAction = isInviteMemberAction(reportAction); - const verb = isInviteRoom ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); + const verb = isInviteAction ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); messageItems.push({ kind: 'text', content: `${verb} `, }); - const originalMessage = reportAction?.originalMessage as CommonOriginalMessage; + const originalMessage = reportAction?.originalMessage as ChangeLogOriginalMessage; const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? []; const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0); - const mentions: MessageActionItemChannelLogUserMention[] = targetAccountIDs.map((accountID) => { + const mentions: MemberChangeMessageUserMentionElement[] = targetAccountIDs.map((accountID) => { const personalDetail = personalDetails.find((personal) => personal.accountID === accountID); if (personalDetail) { const displayNameOrLogin = LocalePhoneNumber.formatPhoneNumber(personalDetail.login ?? '') || (personalDetail?.displayName ? personalDetail?.displayName : Localize.translateLocal('common.hidden')); - return {content: `@${displayNameOrLogin}`, accountID} as MessageActionItemChannelLogUserMention; + return {content: `@${displayNameOrLogin}`, accountID} as MemberChangeMessageUserMentionElement; } - return {content: `@${Localize.translateLocal('common.hidden')}`, accountID} as MessageActionItemChannelLogUserMention; + return {content: `@${Localize.translateLocal('common.hidden')}`, accountID} as MemberChangeMessageUserMentionElement; }); const lastMention = mentions.pop(); @@ -745,7 +745,7 @@ function getChannelLogMemberAction(reportAction: OnyxEntry): Messa const roomName = originalMessage?.roomName; if (roomName) { - const preposition = isInviteRoom ? ` ${Localize.translateLocal('workspace.invite.to')} ` : ` ${Localize.translateLocal('workspace.invite.from')} `; + const preposition = isInviteAction ? ` ${Localize.translateLocal('workspace.invite.to')} ` : ` ${Localize.translateLocal('workspace.invite.from')} `; if (originalMessage.reportID) { messageItems.push( @@ -766,8 +766,8 @@ function getChannelLogMemberAction(reportAction: OnyxEntry): Messa return messageItems; } -function getActionItemFragmentChannelLogFragment(reportAction: OnyxEntry): Message { - const messageItems: MessageActionItemChannelLog[] = getChannelLogMemberAction(reportAction); +function getMemberChangeMessageFragment(reportAction: OnyxEntry): Message { + const messageItems: MessageActionItemChannelLog[] = getMemberChangeMessageElements(reportAction); let html = ''; messageItems.forEach((messageItem) => { @@ -790,6 +790,18 @@ function getActionItemFragmentChannelLogFragment(reportAction: OnyxEntry): string { + const messageItems = getMemberChangeMessageElements(reportAction); + return messageItems.map((item) => item.content).join(''); +} + /** * Helper method to determine if the provided accountID has made a request on the specified report. * @@ -853,6 +865,6 @@ export { hasRequestFromCurrentAccount, getFirstVisibleReportActionID, isChannelLogMemberAction, - getChannelLogMemberAction, - getActionItemFragmentChannelLogFragment, + getMemberChangeMessageFragment, + getMemberChangeMessagePlainText, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 8a16c4f9751b..14a9e5afbe9d 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4263,17 +4263,6 @@ function getIOUReportActionDisplayMessage(reportAction) { }); } -/** - * Return room channel log message - * - * @param {Object} reportAction - * @returns {String} - */ -function getChannelLogMemberMessagePlainText(reportAction) { - const messageItems = ReportActionsUtils.getChannelLogMemberAction(reportAction); - return _.map(messageItems, (item) => item.content).join(''); -} - /** * Checks if a report is a group chat. * @@ -4337,7 +4326,6 @@ function shouldDisableWelcomeMessage(report, policy) { } export { - getChannelLogMemberMessagePlainText, getReportParticipantsTitle, isReportMessageAttachment, findLastAccessedReport, diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index bea87494b5eb..e6afcb489935 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -282,7 +282,7 @@ export default [ const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction); Clipboard.setString(displayMessage); } else if (ReportActionsUtils.isChannelLogMemberAction(reportAction)) { - const logMessage = ReportUtils.getChannelLogMemberMessagePlainText(reportAction); + const logMessage = ReportActionsUtils.getMemberChangeMessagePlainText(reportAction); Clipboard.setString(logMessage); } else if (content) { const parser = new ExpensiMark(); diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index 977a25fa4284..b658988ac3bc 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -42,7 +42,7 @@ function ReportActionItemMessage(props) { const fragments = _.compact(props.action.previousMessage || props.action.message); const isIOUReport = ReportActionsUtils.isMoneyRequestAction(props.action); if (ReportActionsUtils.isChannelLogMemberAction(props.action)) { - const fragment = ReportActionsUtils.getActionItemFragmentChannelLogFragment(props.action); + const fragment = ReportActionsUtils.getMemberChangeMessageFragment(props.action); return ( ; - originalMessage?: CommonOriginalMessage; + originalMessage?: ChangeLogOriginalMessage; }; type OriginalMessageRoomChangeLog = { actionName: ValueOf; - originalMessage?: CommonOriginalMessage; + originalMessage?: ChangeLogOriginalMessage; }; type OriginalMessagePolicyTask = { @@ -196,4 +196,4 @@ type OriginalMessage = | OriginalMessageReimbursementQueued; export default OriginalMessage; -export type {ChronosOOOEvent, Decision, Reaction, ActionName, CommonOriginalMessage}; +export type {ChronosOOOEvent, Decision, Reaction, ActionName, ChangeLogOriginalMessage}; From a2e6fe9fe492c82e86a69c73f49ae7f1f6f1c359 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 28 Nov 2023 00:02:19 +0700 Subject: [PATCH 18/32] update minor --- src/libs/ReportActionsUtils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index cad4f8390747..bdc68abb18c0 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -44,7 +44,7 @@ type MemberChangeMessageRoomReferenceElement = { readonly roomID: number; } & MemberChangeMessageElementBase; -type MessageActionItemChannelLog = MemberChangeMessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement; +type MemberChangeMessageElement = MemberChangeMessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement; const allReports: OnyxCollection = {}; Onyx.connect({ @@ -665,8 +665,8 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea return actions.includes(reportAction.actionName); } -function getMemberChangeMessageElements(reportAction: OnyxEntry): MessageActionItemChannelLog[] { - const messageItems: MessageActionItemChannelLog[] = []; +function getMemberChangeMessageElements(reportAction: OnyxEntry): MemberChangeMessageElement[] { + const messageItems: MemberChangeMessageElement[] = []; const isInviteAction = isInviteMemberAction(reportAction); const verb = isInviteAction ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); @@ -771,7 +771,7 @@ function getMemberChangeMessageElements(reportAction: OnyxEntry): } function getMemberChangeMessageFragment(reportAction: OnyxEntry): Message { - const messageItems: MessageActionItemChannelLog[] = getMemberChangeMessageElements(reportAction); + const messageItems: MemberChangeMessageElement[] = getMemberChangeMessageElements(reportAction); let html = ''; messageItems.forEach((messageItem) => { @@ -803,7 +803,7 @@ function getMemberChangeMessageFragment(reportAction: OnyxEntry): function getMemberChangeMessagePlainText(reportAction: OnyxEntry): string { const messageItems = getMemberChangeMessageElements(reportAction); - return messageItems.map((item) => item.content).join(''); + return messageItems.map((element) => element.content).join(''); } /** From 7013b0a42ebb7af29a7dcc41c944cbabd118bf56 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 28 Nov 2023 00:13:40 +0700 Subject: [PATCH 19/32] fix minor --- src/libs/ReportActionsUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index bdc68abb18c0..07c6cfafb5e4 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -802,8 +802,8 @@ function getMemberChangeMessageFragment(reportAction: OnyxEntry): */ function getMemberChangeMessagePlainText(reportAction: OnyxEntry): string { - const messageItems = getMemberChangeMessageElements(reportAction); - return messageItems.map((element) => element.content).join(''); + const messageElements = getMemberChangeMessageElements(reportAction); + return messageElements.map((element) => element.content).join(''); } /** From 001917264b662b818f221b49433385e843455c97 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 28 Nov 2023 17:25:40 +0700 Subject: [PATCH 20/32] fix: update name fuc and remove type --- src/libs/ReportActionsUtils.ts | 10 +++++----- .../home/report/ContextMenu/ContextMenuActions.js | 2 +- src/pages/home/report/ReportActionItemMessage.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 07c6cfafb5e4..7942315c6419 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -126,7 +126,7 @@ function isReimbursementQueuedAction(reportAction: OnyxEntry) { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED; } -function isChannelLogMemberAction(reportAction: OnyxEntry) { +function isMemberChangeAction(reportAction: OnyxEntry) { return ( reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.REMOVE_FROM_ROOM || @@ -680,15 +680,15 @@ function getMemberChangeMessageElements(reportAction: OnyxEntry): const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? []; const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0); - const mentions: MemberChangeMessageUserMentionElement[] = targetAccountIDs.map((accountID) => { + const mentions = targetAccountIDs.map((accountID) => { const personalDetail = personalDetails.find((personal) => personal.accountID === accountID); if (personalDetail) { const displayNameOrLogin = LocalePhoneNumber.formatPhoneNumber(personalDetail.login ?? '') || (personalDetail?.displayName ? personalDetail?.displayName : Localize.translateLocal('common.hidden')); - return {content: `@${displayNameOrLogin}`, accountID} as MemberChangeMessageUserMentionElement; + return {content: `@${displayNameOrLogin}`, accountID}; } - return {content: `@${Localize.translateLocal('common.hidden')}`, accountID} as MemberChangeMessageUserMentionElement; + return {content: `@${Localize.translateLocal('common.hidden')}`, accountID}; }); const lastMention = mentions.pop(); @@ -868,7 +868,7 @@ export { shouldReportActionBeVisibleAsLastAction, hasRequestFromCurrentAccount, getFirstVisibleReportActionID, - isChannelLogMemberAction, + isMemberChangeAction, getMemberChangeMessageFragment, getMemberChangeMessagePlainText, }; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 7e46d00e1182..6c645bc87486 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -281,7 +281,7 @@ export default [ } else if (ReportActionsUtils.isMoneyRequestAction(reportAction)) { const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction); Clipboard.setString(displayMessage); - } else if (ReportActionsUtils.isChannelLogMemberAction(reportAction)) { + } else if (ReportActionsUtils.isMemberChangeAction(reportAction)) { const logMessage = ReportActionsUtils.getMemberChangeMessagePlainText(reportAction); Clipboard.setString(logMessage); } else if (content) { diff --git a/src/pages/home/report/ReportActionItemMessage.js b/src/pages/home/report/ReportActionItemMessage.js index b658988ac3bc..46e0438f250a 100644 --- a/src/pages/home/report/ReportActionItemMessage.js +++ b/src/pages/home/report/ReportActionItemMessage.js @@ -41,7 +41,7 @@ function ReportActionItemMessage(props) { const styles = useThemeStyles(); const fragments = _.compact(props.action.previousMessage || props.action.message); const isIOUReport = ReportActionsUtils.isMoneyRequestAction(props.action); - if (ReportActionsUtils.isChannelLogMemberAction(props.action)) { + if (ReportActionsUtils.isMemberChangeAction(props.action)) { const fragment = ReportActionsUtils.getMemberChangeMessageFragment(props.action); return ( From bce6a22f03b00714f217cbc8d1ed2a25d7d89a85 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 28 Nov 2023 19:03:00 +0700 Subject: [PATCH 21/32] refactor --- src/libs/ReportActionsUtils.ts | 44 ++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 7942315c6419..76eb5b6126a0 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -666,12 +666,12 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea } function getMemberChangeMessageElements(reportAction: OnyxEntry): MemberChangeMessageElement[] { - const messageItems: MemberChangeMessageElement[] = []; + const messageElements: MemberChangeMessageElement[] = []; const isInviteAction = isInviteMemberAction(reportAction); const verb = isInviteAction ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); - messageItems.push({ + messageElements.push({ kind: 'text', content: `${verb} `, }); @@ -697,13 +697,13 @@ function getMemberChangeMessageElements(reportAction: OnyxEntry): } if (mentions.length === 0) { - messageItems.push({ + messageElements.push({ kind: 'userMention', content: lastMention.content, accountID: lastMention.accountID, }); } else if (mentions.length === 1) { - messageItems.push( + messageElements.push( { kind: 'userMention', content: mentions[0].content, @@ -721,7 +721,7 @@ function getMemberChangeMessageElements(reportAction: OnyxEntry): ); } else { mentions.forEach((mention) => { - messageItems.push( + messageElements.push( { kind: 'userMention', accountID: mention.accountID, @@ -734,7 +734,7 @@ function getMemberChangeMessageElements(reportAction: OnyxEntry): ); }); - messageItems.push( + messageElements.push( { kind: 'text', content: `${Localize.translateLocal('common.and')} `, @@ -752,7 +752,7 @@ function getMemberChangeMessageElements(reportAction: OnyxEntry): const preposition = isInviteAction ? ` ${Localize.translateLocal('workspace.invite.to')} ` : ` ${Localize.translateLocal('workspace.invite.from')} `; if (originalMessage.reportID) { - messageItems.push( + messageElements.push( { kind: 'text', content: preposition, @@ -767,25 +767,23 @@ function getMemberChangeMessageElements(reportAction: OnyxEntry): } } - return messageItems; + return messageElements; } function getMemberChangeMessageFragment(reportAction: OnyxEntry): Message { - const messageItems: MemberChangeMessageElement[] = getMemberChangeMessageElements(reportAction); - let html = ''; - - messageItems.forEach((messageItem) => { - switch (messageItem.kind) { - case 'userMention': - html += ``; - break; - case 'roomReference': - html += `${messageItem.roomName}`; - break; - default: - html += messageItem.content; - } - }); + const messageElements: MemberChangeMessageElement[] = getMemberChangeMessageElements(reportAction); + const html = messageElements + .map((messageElement) => { + switch (messageElement.kind) { + case 'userMention': + return ``; + case 'roomReference': + return `${messageElement.roomName}`; + default: + return messageElement.content; + } + }) + .join(''); return { html: `${html}`, From 00fb67c50e1cebf982d689e0d167efaa77c5e04c Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 28 Nov 2023 20:46:55 +0700 Subject: [PATCH 22/32] remove comment and keep changelog --- src/libs/ReportActionsUtils.ts | 23 ++++++++--------------- src/types/onyx/OriginalMessage.ts | 18 +++++++++--------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 76eb5b6126a0..1531d0321be0 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -5,7 +5,7 @@ import OnyxUtils from 'react-native-onyx/lib/utils'; import {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import {ActionName, ChangeLogOriginalMessage} from '@src/types/onyx/OriginalMessage'; +import {ActionName, ChangeLog} from '@src/types/onyx/OriginalMessage'; import Report from '@src/types/onyx/Report'; import ReportAction, {Message, ReportActions} from '@src/types/onyx/ReportAction'; import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; @@ -666,17 +666,17 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea } function getMemberChangeMessageElements(reportAction: OnyxEntry): MemberChangeMessageElement[] { - const messageElements: MemberChangeMessageElement[] = []; const isInviteAction = isInviteMemberAction(reportAction); - const verb = isInviteAction ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); - messageElements.push({ - kind: 'text', - content: `${verb} `, - }); + const messageElements: MemberChangeMessageElement[] = [ + { + kind: 'text', + content: `${verb} `, + }, + ]; - const originalMessage = reportAction?.originalMessage as ChangeLogOriginalMessage; + const originalMessage = reportAction?.originalMessage as ChangeLog; const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? []; const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0); @@ -792,13 +792,6 @@ function getMemberChangeMessageFragment(reportAction: OnyxEntry): }; } -/** - * Return room channel log message - * - * @param {Object} reportAction - * @returns {String} - */ - function getMemberChangeMessagePlainText(reportAction: OnyxEntry): string { const messageElements = getMemberChangeMessageElements(reportAction); return messageElements.map((element) => element.content).join(''); diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 6172afb8b414..11efcdebaf28 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -135,6 +135,12 @@ type ChronosOOOTimestamp = { timezone_type: number; }; +type ChangeLog = { + targetAccountIDs?: number[]; + roomName?: string; + reportID?: number; +}; + type ChronosOOOEvent = { id: string; lengthInDays: number; @@ -161,20 +167,14 @@ type OriginalMessageReportPreview = { }; }; -type ChangeLogOriginalMessage = { - targetAccountIDs?: number[]; - roomName?: string; - reportID?: number; -}; - type OriginalMessagePolicyChangeLog = { actionName: ValueOf; - originalMessage?: ChangeLogOriginalMessage; + originalMessage?: ChangeLog; }; type OriginalMessageRoomChangeLog = { actionName: ValueOf; - originalMessage?: ChangeLogOriginalMessage; + originalMessage?: ChangeLog; }; type OriginalMessagePolicyTask = { @@ -224,4 +224,4 @@ type OriginalMessage = | OriginalMessageMoved; export default OriginalMessage; -export type {ChronosOOOEvent, Decision, Reaction, ActionName, IOUMessage, Closed, OriginalMessageActionName, ChangeLogOriginalMessage}; +export type {ChronosOOOEvent, Decision, Reaction, ActionName, IOUMessage, Closed, OriginalMessageActionName, ChangeLog}; From 162670f6233521677ae14010354c8b8de45031d5 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 28 Nov 2023 20:48:40 +0700 Subject: [PATCH 23/32] refactor --- src/types/onyx/OriginalMessage.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 11efcdebaf28..feb77ca8c317 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -169,12 +169,12 @@ type OriginalMessageReportPreview = { type OriginalMessagePolicyChangeLog = { actionName: ValueOf; - originalMessage?: ChangeLog; + originalMessage: ChangeLog; }; type OriginalMessageRoomChangeLog = { actionName: ValueOf; - originalMessage?: ChangeLog; + originalMessage: ChangeLog; }; type OriginalMessagePolicyTask = { From 9d6ef344ecdf94302785475dcec860ac2face1b5 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 28 Nov 2023 22:31:36 +0700 Subject: [PATCH 24/32] update translate --- src/languages/es.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/es.ts b/src/languages/es.ts index a0c5e621e600..94aa21ff3240 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1560,7 +1560,7 @@ export default { genericFailureMessage: 'Se produjo un error al invitar al usuario al espacio de trabajo. Vuelva a intentarlo..', pleaseEnterValidLogin: `Asegúrese de que el correo electrónico o el número de teléfono sean válidos (p. ej. ${CONST.EXAMPLE_PHONE_NUMBER}).`, user: 'usuario', - users: 'usuarias', + users: 'usuarios', invited: 'invitada', removed: 'eliminado', to: 'a', From 333ce90a2e8238bc60b87b9713703e9291425982 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 28 Nov 2023 23:18:26 +0700 Subject: [PATCH 25/32] fix translate --- src/languages/es.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/languages/es.ts b/src/languages/es.ts index 94aa21ff3240..ba53233bfc1e 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1561,8 +1561,8 @@ export default { pleaseEnterValidLogin: `Asegúrese de que el correo electrónico o el número de teléfono sean válidos (p. ej. ${CONST.EXAMPLE_PHONE_NUMBER}).`, user: 'usuario', users: 'usuarios', - invited: 'invitada', - removed: 'eliminado', + invited: 'invitó', + removed: 'eliminó', to: 'a', from: 'de', }, From c624fe2cab8138f3d45130a5e57ec10d534f18b9 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Wed, 29 Nov 2023 09:47:28 +0700 Subject: [PATCH 26/32] fix translate with comma --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + src/libs/ReportActionsUtils.ts | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index fe0032794a66..66ff823ef572 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -270,6 +270,7 @@ export default { selectCurrency: 'Select a currency', card: 'Card', required: 'Required', + serialComma: ', ', }, location: { useCurrent: 'Use current location', diff --git a/src/languages/es.ts b/src/languages/es.ts index ba53233bfc1e..b3df05a31828 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -260,6 +260,7 @@ export default { selectCurrency: 'Selecciona una moneda', card: 'Tarjeta', required: 'Obligatorio', + serialComma: ' ', }, location: { useCurrent: 'Usar ubicación actual', diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 1531d0321be0..246abd52bea8 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -667,6 +667,8 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea function getMemberChangeMessageElements(reportAction: OnyxEntry): MemberChangeMessageElement[] { const isInviteAction = isInviteMemberAction(reportAction); + + // currently, in the app we only have the logic show the message when invite the members const verb = isInviteAction ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); const messageElements: MemberChangeMessageElement[] = [ @@ -729,7 +731,7 @@ function getMemberChangeMessageElements(reportAction: OnyxEntry): }, { kind: 'text', - content: `, `, + content: `${Localize.translateLocal('common.serialComma')}`, }, ); }); From c615c01109a5b8e86dcefd96fec2c5b837cecbd4 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Wed, 29 Nov 2023 15:14:18 +0700 Subject: [PATCH 27/32] refactor --- src/libs/PersonalDetailsUtils.js | 13 +++++++++++++ src/libs/ReportActionsUtils.ts | 9 +-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/libs/PersonalDetailsUtils.js b/src/libs/PersonalDetailsUtils.js index 560480dcec9d..8a4151391453 100644 --- a/src/libs/PersonalDetailsUtils.js +++ b/src/libs/PersonalDetailsUtils.js @@ -197,6 +197,18 @@ function getFormattedAddress(privatePersonalDetails) { return formattedAddress.trim().replace(/,$/, ''); } +/** + * @param {Object} personalDetail - details object + * @returns {String | undefined} - The effective display name + */ +function getEffectiveDisplayName(personalDetail) { + if (personalDetail) { + return LocalePhoneNumber.formatPhoneNumber(personalDetail.login) || personalDetail.displayName; + } + + return undefined; +} + export { getDisplayNameOrDefault, getPersonalDetailsByIDs, @@ -206,4 +218,5 @@ export { getFormattedAddress, getFormattedStreet, getStreetLines, + getEffectiveDisplayName, }; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 246abd52bea8..7bfa9a13321d 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -12,7 +12,6 @@ import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; import * as CollectionUtils from './CollectionUtils'; import * as Environment from './Environment/Environment'; import isReportMessageAttachment from './isReportMessageAttachment'; -import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import Log from './Log'; import * as PersonalDetailsUtils from './PersonalDetailsUtils'; @@ -684,13 +683,7 @@ function getMemberChangeMessageElements(reportAction: OnyxEntry): const mentions = targetAccountIDs.map((accountID) => { const personalDetail = personalDetails.find((personal) => personal.accountID === accountID); - - if (personalDetail) { - const displayNameOrLogin = - LocalePhoneNumber.formatPhoneNumber(personalDetail.login ?? '') || (personalDetail?.displayName ? personalDetail?.displayName : Localize.translateLocal('common.hidden')); - return {content: `@${displayNameOrLogin}`, accountID}; - } - return {content: `@${Localize.translateLocal('common.hidden')}`, accountID}; + return {content: `@${PersonalDetailsUtils.getEffectiveDisplayName(personalDetail) ?? Localize.translateLocal('common.hidden')}`, accountID}; }); const lastMention = mentions.pop(); From b8e581eddb4de337537d930e93d4a47e8e41b2a3 Mon Sep 17 00:00:00 2001 From: Jakub Trzebiatowski Date: Wed, 29 Nov 2023 14:38:05 +0100 Subject: [PATCH 28/32] Implement Localize.formatMessageElementList --- src/libs/Localize/index.ts | 58 +++++++++++-- src/libs/MessageElement.ts | 11 +++ src/libs/ReportActionsUtils.ts | 145 +++++++++++---------------------- src/libs/actions/IOU.js | 2 +- tests/unit/LocalizeTests.js | 8 +- 5 files changed, 115 insertions(+), 109 deletions(-) create mode 100644 src/libs/MessageElement.ts diff --git a/src/libs/Localize/index.ts b/src/libs/Localize/index.ts index 488ff0d9b98a..34116252a7c7 100644 --- a/src/libs/Localize/index.ts +++ b/src/libs/Localize/index.ts @@ -8,6 +8,8 @@ import {TranslationFlatObject, TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import LocaleListener from './LocaleListener'; import BaseLocaleListener from './LocaleListener/BaseLocaleListener'; +import BaseLocale from "@libs/Localize/LocaleListener/types"; +import {MessageTextElement, MessageElementBase} from "@libs/MessageElement"; // Current user mail is needed for handling missing translations let userEmail = ''; @@ -27,6 +29,7 @@ LocaleListener.connect(); // Note: This has to be initialized inside a function and not at the top level of the file, because Intl is polyfilled, // and if React Native executes this code upon import, then the polyfill will not be available yet and it will barf let CONJUNCTION_LIST_FORMATS_FOR_LOCALES: Record; + function init() { CONJUNCTION_LIST_FORMATS_FOR_LOCALES = Object.values(CONST.LOCALES).reduce((memo: Record, locale) => { // This is not a supported locale, so we'll use ES_ES instead @@ -121,15 +124,51 @@ function translateIfPhraseKey(message: MaybePhraseKey): string { } } +function getPreferredListFormat(): Intl.ListFormat { + if (!CONJUNCTION_LIST_FORMATS_FOR_LOCALES) { + init(); + } + + return CONJUNCTION_LIST_FORMATS_FOR_LOCALES[BaseLocaleListener.getPreferredLocale()]; +} + /** * Format an array into a string with comma and "and" ("a dog, a cat and a chicken") */ -function arrayToString(anArray: string[]) { - if (!CONJUNCTION_LIST_FORMATS_FOR_LOCALES) { - init(); +function formatList(components: string[]) { + const listFormat = getPreferredListFormat(); + return listFormat.format(components); +} + +function formatMessageElementList(elements: readonly E[]): ReadonlyArray { + const listFormat = getPreferredListFormat(); + const parts = listFormat.formatToParts(elements.map((e) => e.content)); + + console.log(parts); + + const resultElements: Array = []; + + let nextElementIndex = 0; + for (const part of parts) { + if (part.type === "element") { + /** + * The standard guarantees that all input elements will be present in the constructed parts, each exactly + * once, and without any modifications: https://tc39.es/ecma402/#sec-createpartsfromlist + */ + const element = elements[nextElementIndex++]; + + resultElements.push(element); + } else { + const literalElement: MessageTextElement = { + kind: "text", + content: part.value, + }; + + resultElements.push(literalElement); + } } - const listFormat = CONJUNCTION_LIST_FORMATS_FOR_LOCALES[BaseLocaleListener.getPreferredLocale()]; - return listFormat.format(anArray); + + return resultElements; } /** @@ -139,5 +178,12 @@ function getDevicePreferredLocale(): string { return RNLocalize.findBestAvailableLanguage([CONST.LOCALES.EN, CONST.LOCALES.ES])?.languageTag ?? CONST.LOCALES.DEFAULT; } -export {translate, translateLocal, translateIfPhraseKey, arrayToString, getDevicePreferredLocale}; +export { + translate, + translateLocal, + translateIfPhraseKey, + formatList, + formatMessageElementList, + getDevicePreferredLocale +}; export type {PhraseParameters, Phrase, MaybePhraseKey}; diff --git a/src/libs/MessageElement.ts b/src/libs/MessageElement.ts new file mode 100644 index 000000000000..584d7e1e289a --- /dev/null +++ b/src/libs/MessageElement.ts @@ -0,0 +1,11 @@ +type MessageElementBase = { + readonly kind: string; + readonly content: string; +}; + +type MessageTextElement = { + readonly kind: 'text'; + readonly content: string; +} & MessageElementBase; + +export type {MessageElementBase, MessageTextElement}; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 7bfa9a13321d..2710f968039d 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -9,6 +9,7 @@ import {ActionName, ChangeLog} from '@src/types/onyx/OriginalMessage'; import Report from '@src/types/onyx/Report'; import ReportAction, {Message, ReportActions} from '@src/types/onyx/ReportAction'; import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; +import {MessageTextElement, MessageElementBase} from "./MessageElement"; import * as CollectionUtils from './CollectionUtils'; import * as Environment from './Environment/Environment'; import isReportMessageAttachment from './isReportMessageAttachment'; @@ -22,28 +23,21 @@ type LastVisibleMessage = { lastMessageHtml?: string; }; -type MemberChangeMessageElementBase = { - readonly kind: string; - readonly content: string; -}; - -type MemberChangeMessageTextElement = { - readonly kind: 'text'; - readonly content: string; -}; - type MemberChangeMessageUserMentionElement = { readonly kind: 'userMention'; readonly accountID: number; -} & MemberChangeMessageElementBase; +} & MessageElementBase; type MemberChangeMessageRoomReferenceElement = { readonly kind: 'roomReference'; readonly roomName: string; readonly roomID: number; -} & MemberChangeMessageElementBase; +} & MessageElementBase; -type MemberChangeMessageElement = MemberChangeMessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement; +type MemberChangeMessageElement = + MessageTextElement + | MemberChangeMessageUserMentionElement + | MemberChangeMessageRoomReferenceElement; const allReports: OnyxCollection = {}; Onyx.connect({ @@ -664,109 +658,64 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea return actions.includes(reportAction.actionName); } -function getMemberChangeMessageElements(reportAction: OnyxEntry): MemberChangeMessageElement[] { +function getMemberChangeMessageElements(reportAction: OnyxEntry): readonly MemberChangeMessageElement[] { const isInviteAction = isInviteMemberAction(reportAction); // currently, in the app we only have the logic show the message when invite the members const verb = isInviteAction ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); - const messageElements: MemberChangeMessageElement[] = [ - { - kind: 'text', - content: `${verb} `, - }, - ]; - const originalMessage = reportAction?.originalMessage as ChangeLog; const targetAccountIDs: number[] = originalMessage?.targetAccountIDs ?? []; const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs(targetAccountIDs, 0); - const mentions = targetAccountIDs.map((accountID) => { + const mentionElements = targetAccountIDs.map((accountID): MemberChangeMessageUserMentionElement => { const personalDetail = personalDetails.find((personal) => personal.accountID === accountID); - return {content: `@${PersonalDetailsUtils.getEffectiveDisplayName(personalDetail) ?? Localize.translateLocal('common.hidden')}`, accountID}; - }); - - const lastMention = mentions.pop(); - if (!lastMention) { - return []; - } + const handleText = PersonalDetailsUtils.getEffectiveDisplayName(personalDetail) ?? Localize.translateLocal('common.hidden'); - if (mentions.length === 0) { - messageElements.push({ + return { kind: 'userMention', - content: lastMention.content, - accountID: lastMention.accountID, - }); - } else if (mentions.length === 1) { - messageElements.push( - { - kind: 'userMention', - content: mentions[0].content, - accountID: mentions[0].accountID, - }, - { - kind: 'text', - content: ` ${Localize.translateLocal('common.and')} `, - }, - { - kind: 'userMention', - content: lastMention.content, - accountID: lastMention.accountID, - }, - ); - } else { - mentions.forEach((mention) => { - messageElements.push( - { - kind: 'userMention', - accountID: mention.accountID, - content: `${mention.content}`, - }, - { - kind: 'text', - content: `${Localize.translateLocal('common.serialComma')}`, - }, - ); - }); - - messageElements.push( - { - kind: 'text', - content: `${Localize.translateLocal('common.and')} `, - }, - { - kind: 'userMention', - content: lastMention.content, - accountID: lastMention.accountID, - }, - ); - } - - const roomName = originalMessage?.roomName; - if (roomName) { - const preposition = isInviteAction ? ` ${Localize.translateLocal('workspace.invite.to')} ` : ` ${Localize.translateLocal('workspace.invite.from')} `; - - if (originalMessage.reportID) { - messageElements.push( - { - kind: 'text', - content: preposition, - }, - { - kind: 'roomReference', - roomName, - roomID: originalMessage.reportID, - content: roomName, - }, - ); + content: `@${handleText}`, + accountID, + }; + }); + + const buildRoomElements = (): readonly MemberChangeMessageElement[] => { + const roomName = originalMessage?.roomName; + + if (roomName) { + const preposition = isInviteAction ? ` ${Localize.translateLocal('workspace.invite.to')} ` : ` ${Localize.translateLocal('workspace.invite.from')} `; + + if (originalMessage.reportID) { + return [ + { + kind: 'text', + content: preposition, + }, + { + kind: 'roomReference', + roomName, + roomID: originalMessage.reportID, + content: roomName, + }, + ]; + } } + + return []; } - return messageElements; + return [ + { + kind: 'text', + content: `${verb} `, + }, + ...Localize.formatMessageElementList(mentionElements), + ...buildRoomElements(), + ]; } function getMemberChangeMessageFragment(reportAction: OnyxEntry): Message { - const messageElements: MemberChangeMessageElement[] = getMemberChangeMessageElements(reportAction); + const messageElements: readonly MemberChangeMessageElement[] = getMemberChangeMessageElements(reportAction); const html = messageElements .map((messageElement) => { switch (messageElement.kind) { diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 939a11dad511..a7db8d0b93cd 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -926,7 +926,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco // ReportID is -2 (aka "deleted") on the group transaction: https://github.com/Expensify/Auth/blob/3fa2698654cd4fbc30f9de38acfca3fbeb7842e4/auth/command/SplitTransaction.cpp#L24-L27 const formattedParticipants = isOwnPolicyExpenseChat ? [currentUserLogin, ReportUtils.getReportName(splitChatReport)] - : Localize.arrayToString([currentUserLogin, ..._.map(participants, (participant) => participant.login || '')]); + : Localize.formatList([currentUserLogin, ..._.map(participants, (participant) => participant.login || '')]); const splitTransaction = TransactionUtils.buildOptimisticTransaction( amount, diff --git a/tests/unit/LocalizeTests.js b/tests/unit/LocalizeTests.js index 4c89d587fc06..7693a0a4a88d 100644 --- a/tests/unit/LocalizeTests.js +++ b/tests/unit/LocalizeTests.js @@ -15,7 +15,7 @@ describe('localize', () => { afterEach(() => Onyx.clear()); - describe('arrayToString', () => { + describe('formatList', () => { test.each([ [ [], @@ -52,9 +52,9 @@ describe('localize', () => { [CONST.LOCALES.ES]: 'rory, vit e ionatan', }, ], - ])('arrayToSpokenList(%s)', (input, {[CONST.LOCALES.DEFAULT]: expectedOutput, [CONST.LOCALES.ES]: expectedOutputES}) => { - expect(Localize.arrayToString(input)).toBe(expectedOutput); - return Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES).then(() => expect(Localize.arrayToString(input)).toBe(expectedOutputES)); + ])('formatList(%s)', (input, {[CONST.LOCALES.DEFAULT]: expectedOutput, [CONST.LOCALES.ES]: expectedOutputES}) => { + expect(Localize.formatList(input)).toBe(expectedOutput); + return Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES).then(() => expect(Localize.formatList(input)).toBe(expectedOutputES)); }); }); }); From c216c935774e93bced01841c89f9ad64d8049080 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Wed, 29 Nov 2023 23:12:11 +0700 Subject: [PATCH 29/32] refactor use Intl handle listing --- src/languages/en.ts | 1 - src/languages/es.ts | 1 - src/libs/Localize/index.ts | 19 ++++--------------- src/libs/ReportActionsUtils.ts | 9 +++------ 4 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 95c97d1ff770..6ca1ac7447b7 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -270,7 +270,6 @@ export default { selectCurrency: 'Select a currency', card: 'Card', required: 'Required', - serialComma: ', ', showing: 'Showing', of: 'of', }, diff --git a/src/languages/es.ts b/src/languages/es.ts index 6f91f492ecc7..980fc2e13a4c 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -260,7 +260,6 @@ export default { selectCurrency: 'Selecciona una moneda', card: 'Tarjeta', required: 'Obligatorio', - serialComma: ' ', showing: 'Mostrando', of: 'de', }, diff --git a/src/libs/Localize/index.ts b/src/libs/Localize/index.ts index 34116252a7c7..ab65192834d8 100644 --- a/src/libs/Localize/index.ts +++ b/src/libs/Localize/index.ts @@ -1,6 +1,7 @@ import * as RNLocalize from 'react-native-localize'; import Onyx from 'react-native-onyx'; import Log from '@libs/Log'; +import {MessageElementBase, MessageTextElement} from '@libs/MessageElement'; import Config from '@src/CONFIG'; import CONST from '@src/CONST'; import translations from '@src/languages/translations'; @@ -8,8 +9,6 @@ import {TranslationFlatObject, TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import LocaleListener from './LocaleListener'; import BaseLocaleListener from './LocaleListener/BaseLocaleListener'; -import BaseLocale from "@libs/Localize/LocaleListener/types"; -import {MessageTextElement, MessageElementBase} from "@libs/MessageElement"; // Current user mail is needed for handling missing translations let userEmail = ''; @@ -143,14 +142,11 @@ function formatList(components: string[]) { function formatMessageElementList(elements: readonly E[]): ReadonlyArray { const listFormat = getPreferredListFormat(); const parts = listFormat.formatToParts(elements.map((e) => e.content)); - - console.log(parts); - const resultElements: Array = []; let nextElementIndex = 0; for (const part of parts) { - if (part.type === "element") { + if (part.type === 'element') { /** * The standard guarantees that all input elements will be present in the constructed parts, each exactly * once, and without any modifications: https://tc39.es/ecma402/#sec-createpartsfromlist @@ -160,7 +156,7 @@ function formatMessageElementList(elements: readon resultElements.push(element); } else { const literalElement: MessageTextElement = { - kind: "text", + kind: 'text', content: part.value, }; @@ -178,12 +174,5 @@ function getDevicePreferredLocale(): string { return RNLocalize.findBestAvailableLanguage([CONST.LOCALES.EN, CONST.LOCALES.ES])?.languageTag ?? CONST.LOCALES.DEFAULT; } -export { - translate, - translateLocal, - translateIfPhraseKey, - formatList, - formatMessageElementList, - getDevicePreferredLocale -}; +export {translate, translateLocal, translateIfPhraseKey, formatList, formatMessageElementList, getDevicePreferredLocale}; export type {PhraseParameters, Phrase, MaybePhraseKey}; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 2710f968039d..c6367e4bc273 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -9,12 +9,12 @@ import {ActionName, ChangeLog} from '@src/types/onyx/OriginalMessage'; import Report from '@src/types/onyx/Report'; import ReportAction, {Message, ReportActions} from '@src/types/onyx/ReportAction'; import {EmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; -import {MessageTextElement, MessageElementBase} from "./MessageElement"; import * as CollectionUtils from './CollectionUtils'; import * as Environment from './Environment/Environment'; import isReportMessageAttachment from './isReportMessageAttachment'; import * as Localize from './Localize'; import Log from './Log'; +import {MessageElementBase, MessageTextElement} from './MessageElement'; import * as PersonalDetailsUtils from './PersonalDetailsUtils'; type LastVisibleMessage = { @@ -34,10 +34,7 @@ type MemberChangeMessageRoomReferenceElement = { readonly roomID: number; } & MessageElementBase; -type MemberChangeMessageElement = - MessageTextElement - | MemberChangeMessageUserMentionElement - | MemberChangeMessageRoomReferenceElement; +type MemberChangeMessageElement = MessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement; const allReports: OnyxCollection = {}; Onyx.connect({ @@ -702,7 +699,7 @@ function getMemberChangeMessageElements(reportAction: OnyxEntry): } return []; - } + }; return [ { From 4d403abab2a373a4779b7d7640308ca09628144b Mon Sep 17 00:00:00 2001 From: Nam Le Date: Wed, 29 Nov 2023 23:15:24 +0700 Subject: [PATCH 30/32] remove new line --- src/libs/Localize/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/Localize/index.ts b/src/libs/Localize/index.ts index ab65192834d8..77c34ebdc576 100644 --- a/src/libs/Localize/index.ts +++ b/src/libs/Localize/index.ts @@ -28,7 +28,6 @@ LocaleListener.connect(); // Note: This has to be initialized inside a function and not at the top level of the file, because Intl is polyfilled, // and if React Native executes this code upon import, then the polyfill will not be available yet and it will barf let CONJUNCTION_LIST_FORMATS_FOR_LOCALES: Record; - function init() { CONJUNCTION_LIST_FORMATS_FOR_LOCALES = Object.values(CONST.LOCALES).reduce((memo: Record, locale) => { // This is not a supported locale, so we'll use ES_ES instead From 0dea62f2f17eb22e61f4fc2cf392006dd8b76a44 Mon Sep 17 00:00:00 2001 From: Nam Le <39086067+namhihi237@users.noreply.github.com> Date: Thu, 30 Nov 2023 22:01:01 +0700 Subject: [PATCH 31/32] update comment Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.com> --- src/libs/ReportActionsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index c6367e4bc273..59807a983597 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -658,7 +658,7 @@ function isNotifiableReportAction(reportAction: OnyxEntry): boolea function getMemberChangeMessageElements(reportAction: OnyxEntry): readonly MemberChangeMessageElement[] { const isInviteAction = isInviteMemberAction(reportAction); - // currently, in the app we only have the logic show the message when invite the members + // Currently, we only render messages when members are invited const verb = isInviteAction ? Localize.translateLocal('workspace.invite.invited') : Localize.translateLocal('workspace.invite.removed'); const originalMessage = reportAction?.originalMessage as ChangeLog; From 243f932043089c625b0f6be4dea43925177b96c2 Mon Sep 17 00:00:00 2001 From: Nam Le Date: Tue, 5 Dec 2023 20:21:34 +0700 Subject: [PATCH 32/32] fix lint --- src/libs/actions/IOU.js | 478 ++++++++++++++++++++-------------------- 1 file changed, 239 insertions(+), 239 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index ebe5aaf0a427..ed43569c360a 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1,4 +1,4 @@ -import { format } from 'date-fns'; +import {format} from 'date-fns'; import Str from 'expensify-common/lib/str'; import lodashGet from 'lodash/get'; import lodashHas from 'lodash/has'; @@ -138,7 +138,7 @@ function buildOnyxDataForMoneyRequest( lastMessageTranslationKey: '', hasOutstandingIOU: iouReport.total !== 0, iouReportID: iouReport.reportID, - ...(isNewChatReport ? { pendingFields: { createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD } } : {}), + ...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}), }, }, { @@ -148,7 +148,7 @@ function buildOnyxDataForMoneyRequest( ...iouReport, lastMessageText: iouAction.message[0].text, lastMessageHtml: iouAction.message[0].html, - ...(isNewIOUReport ? { pendingFields: { createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD } } : {}), + ...(isNewIOUReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}), }, }, { @@ -160,7 +160,7 @@ function buildOnyxDataForMoneyRequest( onyxMethod: isNewChatReport ? Onyx.METHOD.SET : Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, value: { - ...(isNewChatReport ? { [chatCreatedAction.reportActionID]: chatCreatedAction } : {}), + ...(isNewChatReport ? {[chatCreatedAction.reportActionID]: chatCreatedAction} : {}), [reportPreviewAction.reportActionID]: reportPreviewAction, }, }, @@ -168,7 +168,7 @@ function buildOnyxDataForMoneyRequest( onyxMethod: isNewIOUReport ? Onyx.METHOD.SET : Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, value: { - ...(isNewIOUReport ? { [iouCreatedAction.reportActionID]: iouCreatedAction } : {}), + ...(isNewIOUReport ? {[iouCreatedAction.reportActionID]: iouCreatedAction} : {}), [iouAction.reportActionID]: iouAction, }, }, @@ -201,27 +201,27 @@ function buildOnyxDataForMoneyRequest( const successData = [ ...(isNewChatReport ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: { - pendingFields: null, - errorFields: null, - }, - }, - ] + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + pendingFields: null, + errorFields: null, + }, + }, + ] : []), ...(isNewIOUReport ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, - value: { - pendingFields: null, - errorFields: null, - }, - }, - ] + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + value: { + pendingFields: null, + errorFields: null, + }, + }, + ] : []), { onyxMethod: Onyx.METHOD.MERGE, @@ -237,11 +237,11 @@ function buildOnyxDataForMoneyRequest( value: { ...(isNewChatReport ? { - [chatCreatedAction.reportActionID]: { - pendingAction: null, - errors: null, - }, - } + [chatCreatedAction.reportActionID]: { + pendingAction: null, + errors: null, + }, + } : {}), [reportPreviewAction.reportActionID]: { pendingAction: null, @@ -254,11 +254,11 @@ function buildOnyxDataForMoneyRequest( value: { ...(isNewIOUReport ? { - [iouCreatedAction.reportActionID]: { - pendingAction: null, - errors: null, - }, - } + [iouCreatedAction.reportActionID]: { + pendingAction: null, + errors: null, + }, + } : {}), [iouAction.reportActionID]: { pendingAction: null, @@ -279,26 +279,26 @@ function buildOnyxDataForMoneyRequest( pendingFields: null, ...(isNewChatReport ? { - errorFields: { - createChat: ErrorUtils.getMicroSecondOnyxError('report.genericCreateReportFailureMessage'), - }, - } + errorFields: { + createChat: ErrorUtils.getMicroSecondOnyxError('report.genericCreateReportFailureMessage'), + }, + } : {}), }, }, ...(isNewIOUReport ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, - value: { - pendingFields: null, - errorFields: { - createChat: ErrorUtils.getMicroSecondOnyxError('report.genericCreateReportFailureMessage'), - }, - }, - }, - ] + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + value: { + pendingFields: null, + errorFields: { + createChat: ErrorUtils.getMicroSecondOnyxError('report.genericCreateReportFailureMessage'), + }, + }, + }, + ] : []), { onyxMethod: Onyx.METHOD.MERGE, @@ -315,19 +315,19 @@ function buildOnyxDataForMoneyRequest( value: { ...(isNewChatReport ? { - [chatCreatedAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), - }, - [reportPreviewAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError(null), - }, - } + [chatCreatedAction.reportActionID]: { + errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), + }, + [reportPreviewAction.reportActionID]: { + errors: ErrorUtils.getMicroSecondOnyxError(null), + }, + } : { - [reportPreviewAction.reportActionID]: { - created: reportPreviewAction.created, - errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), - }, - }), + [reportPreviewAction.reportActionID]: { + created: reportPreviewAction.created, + errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), + }, + }), }, }, { @@ -336,18 +336,18 @@ function buildOnyxDataForMoneyRequest( value: { ...(isNewIOUReport ? { - [iouCreatedAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), - }, - [iouAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError(null), - }, - } + [iouCreatedAction.reportActionID]: { + errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), + }, + [iouAction.reportActionID]: { + errors: ErrorUtils.getMicroSecondOnyxError(null), + }, + } : { - [iouAction.reportActionID]: { - errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), - }, - }), + [iouAction.reportActionID]: { + errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericCreateFailureMessage'), + }, + }), }, }, ]; @@ -442,7 +442,7 @@ function getMoneyRequestInformation( if (iouReport) { if (isPolicyExpenseChat) { - iouReport = { ...iouReport }; + iouReport = {...iouReport}; // Because of the Expense reports are stored as negative values, we substract the total from the amount iouReport.total -= amount; @@ -537,14 +537,14 @@ function getMoneyRequestInformation( // Add optimistic personal details for participant const optimisticPersonalDetailListAction = shouldCreateOptimisticPersonalDetails ? { - [payerAccountID]: { - accountID: payerAccountID, - avatar: UserUtils.getDefaultAvatarURL(payerAccountID), - displayName: LocalePhoneNumber.formatPhoneNumber(participant.displayName || payerEmail), - login: participant.login, - isOptimisticPersonalDetail: true, - }, - } + [payerAccountID]: { + accountID: payerAccountID, + avatar: UserUtils.getDefaultAvatarURL(payerAccountID), + displayName: LocalePhoneNumber.formatPhoneNumber(participant.displayName || payerEmail), + login: participant.login, + isOptimisticPersonalDetail: true, + }, + } : undefined; // STEP 5: Build Onyx Data @@ -605,7 +605,7 @@ function createDistanceRequest(report, participant, comment, created, transactio source: ReceiptGeneric, state: CONST.IOU.RECEIPT_STATE.OPEN, }; - const { iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData } = getMoneyRequestInformation( + const {iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData} = getMoneyRequestInformation( currentChatReport, participant, comment, @@ -702,7 +702,7 @@ function editDistanceMoneyRequest(transactionID, transactionThreadReportID, tran onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread.reportID}`, value: { - [updatedReportAction.reportActionID]: { pendingAction: null }, + [updatedReportAction.reportActionID]: {pendingAction: null}, }, }); failureData.push({ @@ -716,7 +716,7 @@ function editDistanceMoneyRequest(transactionID, transactionThreadReportID, tran // Step 4: Compute the IOU total and update the report preview message (and report header) so LHN amount owed is correct. // Should only update if the transaction matches the currency of the report, else we wait for the update // from the server with the currency conversion - let updatedMoneyRequestReport = { ...iouReport }; + let updatedMoneyRequestReport = {...iouReport}; if (updatedTransaction.currency === iouReport.currency && updatedTransaction.modifiedAmount) { const diff = TransactionUtils.getAmount(transaction, true) - TransactionUtils.getAmount(updatedTransaction, true); if (ReportUtils.isExpenseReport(iouReport)) { @@ -734,7 +734,7 @@ function editDistanceMoneyRequest(transactionID, transactionThreadReportID, tran successData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, - value: { pendingAction: null }, + value: {pendingAction: null}, }); } } @@ -790,7 +790,7 @@ function editDistanceMoneyRequest(transactionID, transactionThreadReportID, tran value: iouReport, }); - API.write('UpdateDistanceRequest', params, { optimisticData, successData, failureData }); + API.write('UpdateDistanceRequest', params, {optimisticData, successData, failureData}); } /** @@ -828,7 +828,7 @@ function requestMoney( // If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report; - const { payerAccountID, payerEmail, iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData } = + const {payerAccountID, payerEmail, iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData} = getMoneyRequestInformation(currentChatReport, participant, comment, amount, currency, created, merchant, payeeAccountID, payeeEmail, receipt, undefined, category, tag, billable); const activeReportID = isMoneyRequestReport ? report.reportID : chatReport.reportID; @@ -952,7 +952,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco onyxMethod: existingSplitChatReport ? Onyx.METHOD.MERGE : Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${splitChatReport.reportID}`, value: { - ...(existingSplitChatReport ? {} : { [splitCreatedReportAction.reportActionID]: splitCreatedReportAction }), + ...(existingSplitChatReport ? {} : {[splitCreatedReportAction.reportActionID]: splitCreatedReportAction}), [splitIOUReportAction.reportActionID]: splitIOUReportAction, }, }, @@ -968,14 +968,14 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${splitChatReport.reportID}`, value: { - ...(existingSplitChatReport ? {} : { [splitCreatedReportAction.reportActionID]: { pendingAction: null } }), - [splitIOUReportAction.reportActionID]: { pendingAction: null }, + ...(existingSplitChatReport ? {} : {[splitCreatedReportAction.reportActionID]: {pendingAction: null}}), + [splitIOUReportAction.reportActionID]: {pendingAction: null}, }, }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${splitTransaction.transactionID}`, - value: { pendingAction: null }, + value: {pendingAction: null}, }, ]; @@ -983,7 +983,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco successData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${splitChatReport.reportID}`, - value: { pendingFields: { createChat: null } }, + value: {pendingFields: {createChat: null}}, }); } @@ -1032,7 +1032,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco // Loop through participants creating individual chats, iouReports and reportActionIDs as needed const splitAmount = IOUUtils.calculateAmount(participants.length, amount, currency, false); - const splits = [{ email: currentUserEmailForIOUSplit, accountID: currentUserAccountID, amount: IOUUtils.calculateAmount(participants.length, amount, currency, true) }]; + const splits = [{email: currentUserEmailForIOUSplit, accountID: currentUserAccountID, amount: IOUUtils.calculateAmount(participants.length, amount, currency, true)}]; const hasMultipleParticipants = participants.length > 1; _.each(participants, (participant) => { @@ -1131,14 +1131,14 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco // Add optimistic personal details for new participants const oneOnOnePersonalDetailListAction = shouldCreateOptimisticPersonalDetails ? { - [accountID]: { - accountID, - avatar: UserUtils.getDefaultAvatarURL(accountID), - displayName: LocalePhoneNumber.formatPhoneNumber(participant.displayName || email), - login: participant.login, - isOptimisticPersonalDetail: true, - }, - } + [accountID]: { + accountID, + avatar: UserUtils.getDefaultAvatarURL(accountID), + displayName: LocalePhoneNumber.formatPhoneNumber(participant.displayName || email), + login: participant.login, + isOptimisticPersonalDetail: true, + }, + } : undefined; let oneOnOneReportPreviewAction = ReportActionsUtils.getReportPreviewAction(oneOnOneChatReport.reportID, oneOnOneIOUReport.reportID); @@ -1203,7 +1203,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco return { splitData, splits, - onyxData: { optimisticData, successData, failureData }, + onyxData: {optimisticData, successData, failureData}, }; } @@ -1220,7 +1220,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco * @param {String} merchant */ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, tag, existingSplitChatReportID = '', merchant) { - const { splitData, splits, onyxData } = createSplitsAndOnyxData( + const {splitData, splits, onyxData} = createSplitsAndOnyxData( participants, currentUserLogin, currentUserAccountID, @@ -1268,7 +1268,7 @@ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, * @param {String} merchant */ function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, tag, merchant) { - const { splitData, splits, onyxData } = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, tag, '', merchant); + const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, tag, '', merchant); API.write( 'SplitBillAndOpenReport', { @@ -1313,8 +1313,8 @@ function startSplitBill(participants, currentUserLogin, currentUserAccountID, co const splitChatReport = existingSplitChatReport || ReportUtils.buildOptimisticChatReport(participantAccountIDs); const isOwnPolicyExpenseChat = splitChatReport.isOwnPolicyExpenseChat || false; - const { name: filename, source, state = CONST.IOU.RECEIPT_STATE.SCANREADY } = receipt; - const receiptObject = { state, source }; + const {name: filename, source, state = CONST.IOU.RECEIPT_STATE.SCANREADY} = receipt; + const receiptObject = {state, source}; // ReportID is -2 (aka "deleted") on the group transaction const splitTransaction = TransactionUtils.buildOptimisticTransaction( @@ -1370,7 +1370,7 @@ function startSplitBill(participants, currentUserLogin, currentUserAccountID, co onyxMethod: existingSplitChatReport ? Onyx.METHOD.MERGE : Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${splitChatReport.reportID}`, value: { - ...(existingSplitChatReport ? {} : { [splitChatCreatedReportAction.reportActionID]: splitChatCreatedReportAction }), + ...(existingSplitChatReport ? {} : {[splitChatCreatedReportAction.reportActionID]: splitChatCreatedReportAction}), [splitIOUReportAction.reportActionID]: splitIOUReportAction, }, }, @@ -1386,14 +1386,14 @@ function startSplitBill(participants, currentUserLogin, currentUserAccountID, co onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${splitChatReport.reportID}`, value: { - ...(existingSplitChatReport ? {} : { [splitChatCreatedReportAction.reportActionID]: { pendingAction: null } }), - [splitIOUReportAction.reportActionID]: { pendingAction: null }, + ...(existingSplitChatReport ? {} : {[splitChatCreatedReportAction.reportActionID]: {pendingAction: null}}), + [splitIOUReportAction.reportActionID]: {pendingAction: null}, }, }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${splitTransaction.transactionID}`, - value: { pendingAction: null }, + value: {pendingAction: null}, }, ]; @@ -1401,7 +1401,7 @@ function startSplitBill(participants, currentUserLogin, currentUserAccountID, co successData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${splitChatReport.reportID}`, - value: { pendingFields: { createChat: null } }, + value: {pendingFields: {createChat: null}}, }); } @@ -1451,7 +1451,7 @@ function startSplitBill(participants, currentUserLogin, currentUserAccountID, co ); } - const splits = [{ email: currentUserEmailForIOUSplit, accountID: currentUserAccountID }]; + const splits = [{email: currentUserEmailForIOUSplit, accountID: currentUserAccountID}]; _.each(participants, (participant) => { const email = participant.isOwnPolicyExpenseChat ? '' : OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login || participant.text).toLowerCase(); @@ -1513,9 +1513,9 @@ function startSplitBill(participants, currentUserLogin, currentUserAccountID, co receipt, comment, isFromGroupDM: !existingSplitChatReport, - ...(existingSplitChatReport ? {} : { createdReportActionID: splitChatCreatedReportAction.reportActionID }), + ...(existingSplitChatReport ? {} : {createdReportActionID: splitChatCreatedReportAction.reportActionID}), }, - { optimisticData, successData, failureData }, + {optimisticData, successData, failureData}, ); resetMoneyRequestInfo(); @@ -1533,7 +1533,7 @@ function startSplitBill(participants, currentUserLogin, currentUserAccountID, co */ function completeSplitBill(chatReportID, reportAction, updatedTransaction, sessionAccountID, sessionEmail) { const currentUserEmailForIOUSplit = OptionsListUtils.addSMSDomainIfPhoneNumber(sessionEmail); - const { transactionID } = updatedTransaction; + const {transactionID} = updatedTransaction; const unmodifiedTransaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; // Save optimistic updated transaction and action @@ -1564,7 +1564,7 @@ function completeSplitBill(chatReportID, reportAction, updatedTransaction, sessi { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, - value: { pendingAction: null }, + value: {pendingAction: null}, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -1595,12 +1595,12 @@ function completeSplitBill(chatReportID, reportAction, updatedTransaction, sessi ]; const splitParticipants = updatedTransaction.comment.splits; - const { modifiedAmount: amount, modifiedCurrency: currency } = updatedTransaction; + const {modifiedAmount: amount, modifiedCurrency: currency} = updatedTransaction; // Exclude the current user when calculating the split amount, `calculateAmount` takes it into account const splitAmount = IOUUtils.calculateAmount(splitParticipants.length - 1, amount, currency, false); - const splits = [{ email: currentUserEmailForIOUSplit }]; + const splits = [{email: currentUserEmailForIOUSplit}]; _.each(splitParticipants, (participant) => { // Skip creating the transaction for the current user if (participant.email === currentUserEmailForIOUSplit) { @@ -1656,7 +1656,7 @@ function completeSplitBill(chatReportID, reportAction, updatedTransaction, sessi CONST.IOU.TYPE.SPLIT, transactionID, updatedTransaction.modifiedMerchant, - { ...updatedTransaction.receipt, state: CONST.IOU.RECEIPT_STATE.OPEN }, + {...updatedTransaction.receipt, state: CONST.IOU.RECEIPT_STATE.OPEN}, updatedTransaction.filename, ); @@ -1732,7 +1732,7 @@ function completeSplitBill(chatReportID, reportAction, updatedTransaction, sessi comment: transactionComment, splits: JSON.stringify(splits), }, - { optimisticData, successData, failureData }, + {optimisticData, successData, failureData}, ); Navigation.dismissModal(chatReportID); Report.notifyNewAction(chatReportID, sessionAccountID); @@ -1774,8 +1774,8 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans // STEP 3: Compute the IOU total and update the report preview message so LHN amount owed is correct // Should only update if the transaction matches the currency of the report, else we wait for the update // from the server with the currency conversion - let updatedMoneyRequestReport = { ...iouReport }; - const updatedChatReport = { ...chatReport }; + let updatedMoneyRequestReport = {...iouReport}; + const updatedChatReport = {...chatReport}; const diff = TransactionUtils.getAmount(transaction, true) - TransactionUtils.getAmount(updatedTransaction, true); if (updatedTransaction.currency === iouReport.currency && updatedTransaction.modifiedAmount && diff !== 0) { if (ReportUtils.isExpenseReport(iouReport)) { @@ -1848,25 +1848,25 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans }, ...(!isScanning ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, - value: { - [transactionThread.parentReportActionID]: { - whisperedToAccountIDs: [], - }, - }, - }, - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.parentReportID}`, - value: { - [iouReport.parentReportActionID]: { - whisperedToAccountIDs: [], - }, - }, - }, - ] + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + value: { + [transactionThread.parentReportActionID]: { + whisperedToAccountIDs: [], + }, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.parentReportID}`, + value: { + [iouReport.parentReportActionID]: { + whisperedToAccountIDs: [], + }, + }, + }, + ] : []), ]; @@ -1883,7 +1883,7 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread.reportID}`, value: { - [updatedReportAction.reportActionID]: { pendingAction: null }, + [updatedReportAction.reportActionID]: {pendingAction: null}, }, }, { @@ -1905,7 +1905,7 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, - value: { pendingAction: null }, + value: {pendingAction: null}, }, ]; @@ -1945,7 +1945,7 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans ]; // STEP 6: Call the API endpoint - const { created, amount, currency, comment, merchant, category, billable, tag } = ReportUtils.getTransactionDetails(updatedTransaction); + const {created, amount, currency, comment, merchant, category, billable, tag} = ReportUtils.getTransactionDetails(updatedTransaction); API.write( 'EditMoneyRequest', { @@ -1960,7 +1960,7 @@ function editRegularMoneyRequest(transactionID, transactionThreadReportID, trans billable, tag, }, - { optimisticData, successData, failureData }, + {optimisticData, successData, failureData}, ); } @@ -2031,7 +2031,7 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView let updatedReportPreviewAction = null; if (!shouldDeleteIOUReport) { if (ReportUtils.isExpenseReport(iouReport)) { - updatedIOUReport = { ...iouReport }; + updatedIOUReport = {...iouReport}; // Because of the Expense reports are stored as negative values, we add the total from the amount updatedIOUReport.total += TransactionUtils.getAmount(transaction, true); @@ -2048,7 +2048,7 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView updatedIOUReport.lastMessageText = iouReportLastMessageText; updatedIOUReport.lastVisibleActionCreated = lodashGet(lastVisibleAction, 'created'); - updatedReportPreviewAction = { ...reportPreviewAction }; + updatedReportPreviewAction = {...reportPreviewAction}; const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(iouReport); const messageText = Localize.translateLocal(hasNonReimbursableTransactions ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', { payer: ReportUtils.getPersonalDetailsForAccountID(updatedIOUReport.managerID).login || '', @@ -2070,17 +2070,17 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView }, ...(shouldDeleteTransactionThread ? [ - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadID}`, - value: null, - }, - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadID}`, - value: null, - }, - ] + { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadID}`, + value: null, + }, + { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadID}`, + value: null, + }, + ] : []), { onyxMethod: shouldDeleteIOUReport ? Onyx.METHOD.SET : Onyx.METHOD.MERGE, @@ -2101,18 +2101,18 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView }, ...(shouldDeleteIOUReport ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: { - hasOutstandingIOU: false, - hasOutstandingChildRequest: false, - iouReportID: null, - lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport.chatReportID, { [reportPreviewAction.reportActionID]: null }).lastMessageText, - lastVisibleActionCreated: lodashGet(ReportActionsUtils.getLastVisibleAction(iouReport.chatReportID, { [reportPreviewAction.reportActionID]: null }), 'created'), - }, - }, - ] + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + hasOutstandingIOU: false, + hasOutstandingChildRequest: false, + iouReportID: null, + lastMessageText: ReportActionsUtils.getLastVisibleMessage(iouReport.chatReportID, {[reportPreviewAction.reportActionID]: null}).lastMessageText, + lastVisibleActionCreated: lodashGet(ReportActionsUtils.getLastVisibleAction(iouReport.chatReportID, {[reportPreviewAction.reportActionID]: null}), 'created'), + }, + }, + ] : []), ]; @@ -2121,7 +2121,7 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, value: { - [reportAction.reportActionID]: { pendingAction: null }, + [reportAction.reportActionID]: {pendingAction: null}, }, }, ]; @@ -2134,12 +2134,12 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView }, ...(shouldDeleteTransactionThread ? [ - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadID}`, - value: transactionThread, - }, - ] + { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadID}`, + value: transactionThread, + }, + ] : []), { onyxMethod: Onyx.METHOD.MERGE, @@ -2165,12 +2165,12 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView }, ...(shouldDeleteIOUReport ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, - value: chatReport, - }, - ] + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: chatReport, + }, + ] : []), ]; @@ -2181,7 +2181,7 @@ function deleteMoneyRequest(transactionID, reportAction, isSingleTransactionView transactionID, reportActionID: reportAction.reportActionID, }, - { optimisticData, successData, failureData }, + {optimisticData, successData, failureData}, ); // STEP 7: Navigate the user depending on which page they are on and which resources were deleted @@ -2304,7 +2304,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${optimisticTransaction.transactionID}`, - value: { pendingAction: null }, + value: {pendingAction: null}, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -2337,11 +2337,11 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType optimisticIOUReportData.onyxMethod = Onyx.METHOD.SET; // Set and clear pending fields on the chat report - optimisticChatReportData.value.pendingFields = { createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD }; + optimisticChatReportData.value.pendingFields = {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}; successData.push({ onyxMethod: Onyx.METHOD.MERGE, key: optimisticChatReportData.key, - value: { pendingFields: null }, + value: {pendingFields: null}, }); failureData.push( { @@ -2482,7 +2482,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho { onyxMethod: Onyx.METHOD.MERGE, key: ONYXKEYS.NVP_LAST_PAYMENT_METHOD, - value: { [iouReport.policyID]: paymentMethodType }, + value: {[iouReport.policyID]: paymentMethodType}, }, ]; @@ -2552,9 +2552,9 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho * @param {Object} recipient - The user receiving the money */ function sendMoneyElsewhere(report, amount, currency, comment, managerID, recipient) { - const { params, optimisticData, successData, failureData } = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, managerID, recipient); + const {params, optimisticData, successData, failureData} = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, managerID, recipient); - API.write('SendMoneyElsewhere', params, { optimisticData, successData, failureData }); + API.write('SendMoneyElsewhere', params, {optimisticData, successData, failureData}); resetMoneyRequestInfo(); Navigation.dismissModal(params.chatReportID); @@ -2570,9 +2570,9 @@ function sendMoneyElsewhere(report, amount, currency, comment, managerID, recipi * @param {Object} recipient - The user receiving the money */ function sendMoneyWithWallet(report, amount, currency, comment, managerID, recipient) { - const { params, optimisticData, successData, failureData } = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.EXPENSIFY, managerID, recipient); + const {params, optimisticData, successData, failureData} = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.EXPENSIFY, managerID, recipient); - API.write('SendMoneyWithWallet', params, { optimisticData, successData, failureData }); + API.write('SendMoneyWithWallet', params, {optimisticData, successData, failureData}); resetMoneyRequestInfo(); Navigation.dismissModal(params.chatReportID); @@ -2629,7 +2629,7 @@ function approveMoneyRequest(expenseReport) { }, ]; - API.write('ApproveMoneyRequest', { reportID: expenseReport.reportID, approvedReportActionID: optimisticApprovedReportAction.reportActionID }, { optimisticData, successData, failureData }); + API.write('ApproveMoneyRequest', {reportID: expenseReport.reportID, approvedReportActionID: optimisticApprovedReportAction.reportActionID}, {optimisticData, successData, failureData}); } /** @@ -2664,17 +2664,17 @@ function submitReport(expenseReport) { }, ...(parentReport.reportID ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`, - value: { - ...parentReport, - hasOutstandingIOU: false, - hasOutstandingChildRequest: false, - iouReportID: null, - }, - }, - ] + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`, + value: { + ...parentReport, + hasOutstandingIOU: false, + hasOutstandingChildRequest: false, + iouReportID: null, + }, + }, + ] : []), ]; @@ -2710,16 +2710,16 @@ function submitReport(expenseReport) { }, ...(parentReport.reportID ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`, - value: { - hasOutstandingIOU: parentReport.hasOutstandingIOU, - hasOutstandingChildRequest: parentReport.hasOutstandingChildRequest, - iouReportID: expenseReport.reportID, - }, - }, - ] + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${parentReport.reportID}`, + value: { + hasOutstandingIOU: parentReport.hasOutstandingIOU, + hasOutstandingChildRequest: parentReport.hasOutstandingChildRequest, + iouReportID: expenseReport.reportID, + }, + }, + ] : []), ]; @@ -2730,7 +2730,7 @@ function submitReport(expenseReport) { managerAccountID: expenseReport.managerID, reportActionID: optimisticSubmittedReportAction.reportActionID, }, - { optimisticData, successData, failureData }, + {optimisticData, successData, failureData}, ); } @@ -2741,20 +2741,20 @@ function submitReport(expenseReport) { * @param {String} reimbursementBankAccountState */ function payMoneyRequest(paymentType, chatReport, iouReport) { - const recipient = { accountID: iouReport.ownerAccountID }; - const { params, optimisticData, successData, failureData } = getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentType); + const recipient = {accountID: iouReport.ownerAccountID}; + const {params, optimisticData, successData, failureData} = getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentType); // For now we need to call the PayMoneyRequestWithWallet API since PayMoneyRequest was not updated to work with // Expensify Wallets. const apiCommand = paymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY ? 'PayMoneyRequestWithWallet' : 'PayMoneyRequest'; - API.write(apiCommand, params, { optimisticData, successData, failureData }); + API.write(apiCommand, params, {optimisticData, successData, failureData}); Navigation.dismissModal(chatReport.reportID); } function detachReceipt(transactionID) { const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] || {}; - const newTransaction = { ...transaction, filename: '', receipt: {} }; + const newTransaction = {...transaction, filename: '', receipt: {}}; const optimisticData = [ { @@ -2772,7 +2772,7 @@ function detachReceipt(transactionID) { }, ]; - API.write('DetachReceipt', { transactionID }, { optimisticData, failureData }); + API.write('DetachReceipt', {transactionID}, {optimisticData, failureData}); } /** @@ -2809,7 +2809,7 @@ function replaceReceipt(transactionID, receipt, filePath) { }, ]; - API.write('ReplaceReceipt', { transactionID, receipt }, { optimisticData, failureData }); + API.write('ReplaceReceipt', {transactionID, receipt}, {optimisticData, failureData}); } /** @@ -2826,71 +2826,71 @@ function startMoneyRequest(iouType, reportID = '') { * @param {String} id */ function setMoneyRequestId(id) { - Onyx.merge(ONYXKEYS.IOU, { id }); + Onyx.merge(ONYXKEYS.IOU, {id}); } /** * @param {Number} amount */ function setMoneyRequestAmount(amount) { - Onyx.merge(ONYXKEYS.IOU, { amount }); + Onyx.merge(ONYXKEYS.IOU, {amount}); } /** * @param {String} created */ function setMoneyRequestCreated(created) { - Onyx.merge(ONYXKEYS.IOU, { created }); + Onyx.merge(ONYXKEYS.IOU, {created}); } /** * @param {String} currency */ function setMoneyRequestCurrency(currency) { - Onyx.merge(ONYXKEYS.IOU, { currency }); + Onyx.merge(ONYXKEYS.IOU, {currency}); } /** * @param {String} comment */ function setMoneyRequestDescription(comment) { - Onyx.merge(ONYXKEYS.IOU, { comment: comment.trim() }); + Onyx.merge(ONYXKEYS.IOU, {comment: comment.trim()}); } /** * @param {String} merchant */ function setMoneyRequestMerchant(merchant) { - Onyx.merge(ONYXKEYS.IOU, { merchant: merchant.trim() }); + Onyx.merge(ONYXKEYS.IOU, {merchant: merchant.trim()}); } /** * @param {String} category */ function setMoneyRequestCategory(category) { - Onyx.merge(ONYXKEYS.IOU, { category }); + Onyx.merge(ONYXKEYS.IOU, {category}); } function resetMoneyRequestCategory() { - Onyx.merge(ONYXKEYS.IOU, { category: '' }); + Onyx.merge(ONYXKEYS.IOU, {category: ''}); } /* * @param {String} tag */ function setMoneyRequestTag(tag) { - Onyx.merge(ONYXKEYS.IOU, { tag }); + Onyx.merge(ONYXKEYS.IOU, {tag}); } function resetMoneyRequestTag() { - Onyx.merge(ONYXKEYS.IOU, { tag: '' }); + Onyx.merge(ONYXKEYS.IOU, {tag: ''}); } /** * @param {Boolean} billable */ function setMoneyRequestBillable(billable) { - Onyx.merge(ONYXKEYS.IOU, { billable }); + Onyx.merge(ONYXKEYS.IOU, {billable}); } /** @@ -2898,7 +2898,7 @@ function setMoneyRequestBillable(billable) { * @param {Boolean} isSplitRequest */ function setMoneyRequestParticipants(participants, isSplitRequest) { - Onyx.merge(ONYXKEYS.IOU, { participants, isSplitRequest }); + Onyx.merge(ONYXKEYS.IOU, {participants, isSplitRequest}); } /** @@ -2906,16 +2906,16 @@ function setMoneyRequestParticipants(participants, isSplitRequest) { * @param {String} receiptFilename */ function setMoneyRequestReceipt(receiptPath, receiptFilename) { - Onyx.merge(ONYXKEYS.IOU, { receiptPath, receiptFilename, merchant: '' }); + Onyx.merge(ONYXKEYS.IOU, {receiptPath, receiptFilename, merchant: ''}); } function setUpDistanceTransaction() { const transactionID = NumberUtils.rand64(); Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, { transactionID, - comment: { type: CONST.TRANSACTION.TYPE.CUSTOM_UNIT, customUnit: { name: CONST.CUSTOM_UNITS.NAME_DISTANCE } }, + comment: {type: CONST.TRANSACTION.TYPE.CUSTOM_UNIT, customUnit: {name: CONST.CUSTOM_UNITS.NAME_DISTANCE}}, }); - Onyx.merge(ONYXKEYS.IOU, { transactionID }); + Onyx.merge(ONYXKEYS.IOU, {transactionID}); } /** @@ -2951,11 +2951,11 @@ function navigateToNextPage(iou, iouType, report, path = '') { if (_.isEmpty(iou.participants) || shouldReset) { const currentUserAccountID = currentUserPersonalDetails.accountID; const participants = ReportUtils.isPolicyExpenseChat(chatReport) - ? [{ reportID: chatReport.reportID, isPolicyExpenseChat: true, selected: true }] + ? [{reportID: chatReport.reportID, isPolicyExpenseChat: true, selected: true}] : _.chain(chatReport.participantAccountIDs) - .filter((accountID) => currentUserAccountID !== accountID) - .map((accountID) => ({ accountID, selected: true })) - .value(); + .filter((accountID) => currentUserAccountID !== accountID) + .map((accountID) => ({accountID, selected: true})) + .value(); setMoneyRequestParticipants(participants); resetMoneyRequestCategory(); resetMoneyRequestTag();