From 9fbb88397ea253d3df1ff2e257eae59c91da7c1a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 6 Nov 2023 11:34:42 +0700 Subject: [PATCH 1/4] Fix copy invite room message --- src/libs/ReportActionsUtils.ts | 5 ++++ src/libs/ReportUtils.js | 27 +++++++++++++++++++ .../report/ContextMenu/ContextMenuActions.js | 3 +++ src/styles/fontFamily/multiFontFamily.ts | 4 +-- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 11e11f549682..1320cba4a9f9 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -95,6 +95,10 @@ function isReimbursementQueuedAction(reportAction: OnyxEntry) { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED; } +function isRoomChannelLogMember(reportAction: OnyxEntry) { + return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.REMOVE_FROM_ROOM; +} + /** * Returns whether the comment is a thread parent message/the first message in a thread */ @@ -657,4 +661,5 @@ export { shouldReportActionBeVisible, shouldReportActionBeVisibleAsLastAction, getFirstVisibleReportActionID, + isRoomChannelLogMember, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 1e3fc5297193..0360eaead493 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -14,6 +14,7 @@ import ROUTES from '@src/ROUTES'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; import isReportMessageAttachment from './isReportMessageAttachment'; +import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import linkingConfig from './Navigation/linkingConfig'; import Navigation from './Navigation/Navigation'; @@ -4043,6 +4044,21 @@ function getTaskAssigneeChatOnyxData(accountID, assigneeAccountID, taskReportID, }; } +/** + * Return the mention message of a list accounntID + * @param {Array} accountIDs + * @returns {String} + */ +function getMentionMessage(accountIDs) { + const listMention = _.map(accountIDs, (accountID) => { + const personalDetail = lodashGet(allPersonalDetails, accountID); + const displayNameOrLogin = + LocalePhoneNumber.formatPhoneNumber(lodashGet(personalDetail, 'login', '')) || lodashGet(personalDetail, 'displayName', '') || Localize.translateLocal('common.hidden'); + return `@${displayNameOrLogin}`; + }); + return listMention.join(' and '); +} + /** * Returns an array of the participants Ids of a report * @@ -4114,6 +4130,16 @@ function getIOUReportActionDisplayMessage(reportAction) { return displayMessage; } +/** + * Return room channel log display message + * @param {Object} reportAction + * @returns {String} + */ +function getRoomChannelLogMemberMessage(reportAction) { + const title = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ? 'invited' : 'removed'; + return `${title} ${getMentionMessage(reportAction.originalMessage.targetAccountIDs)}`; +} + /** * Checks if a report is a group chat. * @@ -4315,4 +4341,5 @@ export { parseReportRouteParams, getReimbursementQueuedActionMessage, getPersonalDetailsForAccountID, + getRoomChannelLogMemberMessage, }; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 5a1266d15a42..0246c514645f 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -281,6 +281,9 @@ export default [ } else if (ReportActionsUtils.isMoneyRequestAction(reportAction)) { const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction); Clipboard.setString(displayMessage); + } else if (ReportActionsUtils.isRoomChannelLogMember(reportAction)) { + const logMessage = ReportUtils.getRoomChannelLogMemberMessage(reportAction); + Clipboard.setString(logMessage); } else if (content) { const parser = new ExpensiMark(); if (!Clipboard.canSetHtml()) { diff --git a/src/styles/fontFamily/multiFontFamily.ts b/src/styles/fontFamily/multiFontFamily.ts index 14f64d406954..5bd89e0d4bcb 100644 --- a/src/styles/fontFamily/multiFontFamily.ts +++ b/src/styles/fontFamily/multiFontFamily.ts @@ -1,7 +1,7 @@ +import getOperatingSystem from '@libs/getOperatingSystem'; +import CONST from '@src/CONST'; import {multiBold} from './bold'; import FontFamilyStyles from './types'; -import CONST from '../../CONST'; -import getOperatingSystem from '../../libs/getOperatingSystem'; // In windows and ubuntu, we need some extra system fonts for emojis to work properly // otherwise few of them will appear as black and white From 427be617ddd28816dbae71209cfd80e373ae7ed2 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 7 Nov 2023 16:46:56 +0700 Subject: [PATCH 2/4] refactor function --- src/libs/ReportUtils.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 49a3f77648d0..0fbb1486156c 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4045,21 +4045,6 @@ function getTaskAssigneeChatOnyxData(accountID, assigneeAccountID, taskReportID, }; } -/** - * Return the mention message of a list accounntID - * @param {Array} accountIDs - * @returns {String} - */ -function getMentionMessage(accountIDs) { - const listMention = _.map(accountIDs, (accountID) => { - const personalDetail = lodashGet(allPersonalDetails, accountID); - const displayNameOrLogin = - LocalePhoneNumber.formatPhoneNumber(lodashGet(personalDetail, 'login', '')) || lodashGet(personalDetail, 'displayName', '') || Localize.translateLocal('common.hidden'); - return `@${displayNameOrLogin}`; - }); - return listMention.join(' and '); -} - /** * Returns an array of the participants Ids of a report * @@ -4137,8 +4122,22 @@ function getIOUReportActionDisplayMessage(reportAction) { * @returns {String} */ function getRoomChannelLogMemberMessage(reportAction) { - const title = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ? 'invited' : 'removed'; - return `${title} ${getMentionMessage(reportAction.originalMessage.targetAccountIDs)}`; + const actionPerformed = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ? 'invited' : 'removed'; + const listMention = _.map(reportAction.originalMessage.targetAccountIDs, (accountID) => { + const personalDetail = lodashGet(allPersonalDetails, accountID); + const displayNameOrLogin = + LocalePhoneNumber.formatPhoneNumber(lodashGet(personalDetail, 'login', '')) || lodashGet(personalDetail, 'displayName', '') || Localize.translateLocal('common.hidden'); + return `@${displayNameOrLogin}`; + }); + const lastMention = listMention.pop(); + let lastPrefix = ', and '; + if (listMention.length === 0) { + lastPrefix = ''; + } + if (listMention.length === 1) { + lastPrefix = ' and '; + } + return `${actionPerformed} ${listMention.join(', ')}${lastPrefix}${lastMention}`; } /** From 4df098eed0f4044dc7a21429abf8b603fa15404b Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 7 Nov 2023 19:01:24 +0700 Subject: [PATCH 3/4] simplicity function --- src/libs/ReportUtils.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 0fbb1486156c..c2c573960fd3 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4118,26 +4118,31 @@ function getIOUReportActionDisplayMessage(reportAction) { /** * Return room channel log display message + * * @param {Object} reportAction * @returns {String} */ function getRoomChannelLogMemberMessage(reportAction) { const actionPerformed = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ? 'invited' : 'removed'; - const listMention = _.map(reportAction.originalMessage.targetAccountIDs, (accountID) => { + + const mentions = _.map(reportAction.originalMessage.targetAccountIDs, (accountID) => { const personalDetail = lodashGet(allPersonalDetails, accountID); const displayNameOrLogin = LocalePhoneNumber.formatPhoneNumber(lodashGet(personalDetail, 'login', '')) || lodashGet(personalDetail, 'displayName', '') || Localize.translateLocal('common.hidden'); return `@${displayNameOrLogin}`; }); - const lastMention = listMention.pop(); - let lastPrefix = ', and '; - if (listMention.length === 0) { - lastPrefix = ''; + + const lastMention = mentions.pop(); + + if (mentions.length === 0) { + return `${actionPerformed} ${lastMention}`; } - if (listMention.length === 1) { - lastPrefix = ' and '; + + if (mentions.length === 1) { + return `${actionPerformed} ${mentions[0]} and ${lastMention}`; } - return `${actionPerformed} ${listMention.join(', ')}${lastPrefix}${lastMention}`; + + return `${actionPerformed} ${mentions.join(', ')}, and ${lastMention}`; } /** From 65c5cc962efdc6d27af52b8ac654e82581336b18 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 8 Nov 2023 15:53:38 +0700 Subject: [PATCH 4/4] fix copy message for policy member log --- src/libs/ReportActionsUtils.ts | 11 +++++-- src/libs/ReportUtils.js | 29 ++++++++++++++----- .../report/ContextMenu/ContextMenuActions.js | 4 +-- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 3cc83b5f9db9..79d899c9d3a1 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -95,8 +95,13 @@ function isReimbursementQueuedAction(reportAction: OnyxEntry) { return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED; } -function isRoomChannelLogMember(reportAction: OnyxEntry) { - return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.REMOVE_FROM_ROOM; +function isChannelLogMemberAction(reportAction: OnyxEntry) { + return ( + reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || + reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.REMOVE_FROM_ROOM || + reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM || + reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.REMOVE_FROM_ROOM + ); } /** @@ -666,5 +671,5 @@ export { shouldReportActionBeVisible, shouldReportActionBeVisibleAsLastAction, getFirstVisibleReportActionID, - isRoomChannelLogMember, + isChannelLogMemberAction, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d899bf7dec8e..409f8387057a 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -4127,12 +4127,15 @@ function getIOUReportActionDisplayMessage(reportAction) { /** * Return room channel log display message - * + * * @param {Object} reportAction * @returns {String} */ -function getRoomChannelLogMemberMessage(reportAction) { - const actionPerformed = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ? 'invited' : 'removed'; +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'; const mentions = _.map(reportAction.originalMessage.targetAccountIDs, (accountID) => { const personalDetail = lodashGet(allPersonalDetails, accountID); @@ -4142,16 +4145,26 @@ function getRoomChannelLogMemberMessage(reportAction) { }); const lastMention = mentions.pop(); + let message = ''; if (mentions.length === 0) { - return `${actionPerformed} ${lastMention}`; + message = `${verb} ${lastMention}`; + } else if (mentions.length === 1) { + message = `${verb} ${mentions[0]} and ${lastMention}`; + } else { + message = `${verb} ${mentions.join(', ')}, and ${lastMention}`; } - if (mentions.length === 1) { - return `${actionPerformed} ${mentions[0]} 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'; + message += `${preposition} ${roomName}`; } - return `${actionPerformed} ${mentions.join(', ')}, and ${lastMention}`; + return message; } /** @@ -4367,6 +4380,6 @@ export { parseReportRouteParams, getReimbursementQueuedActionMessage, getPersonalDetailsForAccountID, - getRoomChannelLogMemberMessage, + getChannelLogMemberMessage, getRoom, }; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 0246c514645f..4f35926c5957 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -281,8 +281,8 @@ export default [ } else if (ReportActionsUtils.isMoneyRequestAction(reportAction)) { const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction); Clipboard.setString(displayMessage); - } else if (ReportActionsUtils.isRoomChannelLogMember(reportAction)) { - const logMessage = ReportUtils.getRoomChannelLogMemberMessage(reportAction); + } else if (ReportActionsUtils.isChannelLogMemberAction(reportAction)) { + const logMessage = ReportUtils.getChannelLogMemberMessage(reportAction); Clipboard.setString(logMessage); } else if (content) { const parser = new ExpensiMark();