Skip to content

Commit

Permalink
Merge pull request Expensify#30898 from dukenv0307/fix/30272
Browse files Browse the repository at this point in the history
Fix copy invite room message
  • Loading branch information
bondydaa authored Nov 16, 2023
2 parents 1deced4 + d581ca2 commit e5e1965
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ function isReimbursementQueuedAction(reportAction: OnyxEntry<ReportAction>) {
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED;
}

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
);
}

/**
* Returns whether the comment is a thread parent message/the first message in a thread
*/
Expand Down Expand Up @@ -657,4 +666,5 @@ export {
shouldReportActionBeVisible,
shouldReportActionBeVisibleAsLastAction,
getFirstVisibleReportActionID,
isChannelLogMemberAction,
};
44 changes: 44 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as IOU from './actions/IOU';
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';
Expand Down Expand Up @@ -4144,6 +4145,48 @@ function getIOUReportActionDisplayMessage(reportAction) {
});
}

/**
* Return room channel log display message
*
* @param {Object} reportAction
* @returns {String}
*/
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);
const displayNameOrLogin =
LocalePhoneNumber.formatPhoneNumber(lodashGet(personalDetail, 'login', '')) || lodashGet(personalDetail, 'displayName', '') || Localize.translateLocal('common.hidden');
return `@${displayNameOrLogin}`;
});

const lastMention = mentions.pop();
let message = '';

if (mentions.length === 0) {
message = `${verb} ${lastMention}`;
} else if (mentions.length === 1) {
message = `${verb} ${mentions[0]} and ${lastMention}`;
} else {
message = `${verb} ${mentions.join(', ')}, 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 message;
}

/**
* Checks if a report is a group chat.
*
Expand Down Expand Up @@ -4366,6 +4409,7 @@ export {
parseReportRouteParams,
getReimbursementQueuedActionMessage,
getPersonalDetailsForAccountID,
getChannelLogMemberMessage,
getRoom,
shouldDisableWelcomeMessage,
};
3 changes: 3 additions & 0 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ export default [
} else if (ReportActionsUtils.isMoneyRequestAction(reportAction)) {
const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction);
Clipboard.setString(displayMessage);
} else if (ReportActionsUtils.isChannelLogMemberAction(reportAction)) {
const logMessage = ReportUtils.getChannelLogMemberMessage(reportAction);
Clipboard.setString(logMessage);
} else if (content) {
const parser = new ExpensiMark();
if (!Clipboard.canSetHtml()) {
Expand Down

0 comments on commit e5e1965

Please sign in to comment.