Skip to content

Commit e5e1965

Browse files
authored
Merge pull request #30898 from dukenv0307/fix/30272
Fix copy invite room message
2 parents 1deced4 + d581ca2 commit e5e1965

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/libs/ReportActionsUtils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ function isReimbursementQueuedAction(reportAction: OnyxEntry<ReportAction>) {
9696
return reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENTQUEUED;
9797
}
9898

99+
function isChannelLogMemberAction(reportAction: OnyxEntry<ReportAction>) {
100+
return (
101+
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ||
102+
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.REMOVE_FROM_ROOM ||
103+
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM ||
104+
reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.REMOVE_FROM_ROOM
105+
);
106+
}
107+
99108
/**
100109
* Returns whether the comment is a thread parent message/the first message in a thread
101110
*/
@@ -657,4 +666,5 @@ export {
657666
shouldReportActionBeVisible,
658667
shouldReportActionBeVisibleAsLastAction,
659668
getFirstVisibleReportActionID,
669+
isChannelLogMemberAction,
660670
};

src/libs/ReportUtils.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as IOU from './actions/IOU';
1515
import * as CurrencyUtils from './CurrencyUtils';
1616
import DateUtils from './DateUtils';
1717
import isReportMessageAttachment from './isReportMessageAttachment';
18+
import * as LocalePhoneNumber from './LocalePhoneNumber';
1819
import * as Localize from './Localize';
1920
import linkingConfig from './Navigation/linkingConfig';
2021
import Navigation from './Navigation/Navigation';
@@ -4144,6 +4145,48 @@ function getIOUReportActionDisplayMessage(reportAction) {
41444145
});
41454146
}
41464147

4148+
/**
4149+
* Return room channel log display message
4150+
*
4151+
* @param {Object} reportAction
4152+
* @returns {String}
4153+
*/
4154+
function getChannelLogMemberMessage(reportAction) {
4155+
const verb =
4156+
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM
4157+
? 'invited'
4158+
: 'removed';
4159+
4160+
const mentions = _.map(reportAction.originalMessage.targetAccountIDs, (accountID) => {
4161+
const personalDetail = lodashGet(allPersonalDetails, accountID);
4162+
const displayNameOrLogin =
4163+
LocalePhoneNumber.formatPhoneNumber(lodashGet(personalDetail, 'login', '')) || lodashGet(personalDetail, 'displayName', '') || Localize.translateLocal('common.hidden');
4164+
return `@${displayNameOrLogin}`;
4165+
});
4166+
4167+
const lastMention = mentions.pop();
4168+
let message = '';
4169+
4170+
if (mentions.length === 0) {
4171+
message = `${verb} ${lastMention}`;
4172+
} else if (mentions.length === 1) {
4173+
message = `${verb} ${mentions[0]} and ${lastMention}`;
4174+
} else {
4175+
message = `${verb} ${mentions.join(', ')}, and ${lastMention}`;
4176+
}
4177+
4178+
const roomName = lodashGet(reportAction, 'originalMessage.roomName', '');
4179+
if (roomName) {
4180+
const preposition =
4181+
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM || reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM
4182+
? ' to'
4183+
: ' from';
4184+
message += `${preposition} ${roomName}`;
4185+
}
4186+
4187+
return message;
4188+
}
4189+
41474190
/**
41484191
* Checks if a report is a group chat.
41494192
*
@@ -4366,6 +4409,7 @@ export {
43664409
parseReportRouteParams,
43674410
getReimbursementQueuedActionMessage,
43684411
getPersonalDetailsForAccountID,
4412+
getChannelLogMemberMessage,
43694413
getRoom,
43704414
shouldDisableWelcomeMessage,
43714415
};

src/pages/home/report/ContextMenu/ContextMenuActions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ export default [
281281
} else if (ReportActionsUtils.isMoneyRequestAction(reportAction)) {
282282
const displayMessage = ReportUtils.getIOUReportActionDisplayMessage(reportAction);
283283
Clipboard.setString(displayMessage);
284+
} else if (ReportActionsUtils.isChannelLogMemberAction(reportAction)) {
285+
const logMessage = ReportUtils.getChannelLogMemberMessage(reportAction);
286+
Clipboard.setString(logMessage);
284287
} else if (content) {
285288
const parser = new ExpensiMark();
286289
if (!Clipboard.canSetHtml()) {

0 commit comments

Comments
 (0)