Skip to content

Commit

Permalink
fix copy message for policy member log
Browse files Browse the repository at this point in the history
  • Loading branch information
dukenv0307 committed Nov 8, 2023
1 parent db16de3 commit 65c5cc9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
11 changes: 8 additions & 3 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ function isReimbursementQueuedAction(reportAction: OnyxEntry<ReportAction>) {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED;
}

function isRoomChannelLogMember(reportAction: OnyxEntry<ReportAction>) {
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<ReportAction>) {
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
);
}

/**
Expand Down Expand Up @@ -666,5 +671,5 @@ export {
shouldReportActionBeVisible,
shouldReportActionBeVisibleAsLastAction,
getFirstVisibleReportActionID,
isRoomChannelLogMember,
isChannelLogMemberAction,
};
29 changes: 21 additions & 8 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -4367,6 +4380,6 @@ export {
parseReportRouteParams,
getReimbursementQueuedActionMessage,
getPersonalDetailsForAccountID,
getRoomChannelLogMemberMessage,
getChannelLogMemberMessage,
getRoom,
};
4 changes: 2 additions & 2 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 65c5cc9

Please sign in to comment.