Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copy invite room message #30898

Merged
merged 7 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ 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;
}

/**
* Returns whether the comment is a thread parent message/the first message in a thread
*/
Expand Down Expand Up @@ -657,4 +661,5 @@ export {
shouldReportActionBeVisible,
shouldReportActionBeVisibleAsLastAction,
getFirstVisibleReportActionID,
isRoomChannelLogMember,
};
27 changes: 27 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -4043,6 +4044,21 @@ function getTaskAssigneeChatOnyxData(accountID, assigneeAccountID, taskReportID,
};
}

/**
* Return the mention message of a list accounntID
* @param {Array<String>} accountIDs
* @returns {String}
*/
function getMentionMessage(accountIDs) {
dukenv0307 marked this conversation as resolved.
Show resolved Hide resolved
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 ');
dukenv0307 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns an array of the participants Ids of a report
*
Expand Down Expand Up @@ -4114,6 +4130,16 @@ function getIOUReportActionDisplayMessage(reportAction) {
return displayMessage;
}

/**
* Return room channel log display message
* @param {Object} reportAction
* @returns {String}
*/
function getRoomChannelLogMemberMessage(reportAction) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better! But I have a suggestion to increase the simplicity of the function. Let me know if you agree.

/**
 * 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 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();

    if (mentions.length === 0) {
        return `${actionPerformed} ${lastMention}`;
    }

    return `${actionPerformed} ${mentions.join(', ')} and ${lastMention}`;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me. Will update soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cubuspl42 I updated.

const title = reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ? 'invited' : 'removed';
dukenv0307 marked this conversation as resolved.
Show resolved Hide resolved
return `${title} ${getMentionMessage(reportAction.originalMessage.targetAccountIDs)}`;
}

/**
* Checks if a report is a group chat.
*
Expand Down Expand Up @@ -4315,4 +4341,5 @@ export {
parseReportRouteParams,
getReimbursementQueuedActionMessage,
getPersonalDetailsForAccountID,
getRoomChannelLogMemberMessage,
};
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.isRoomChannelLogMember(reportAction)) {
const logMessage = ReportUtils.getRoomChannelLogMemberMessage(reportAction);
Clipboard.setString(logMessage);
} else if (content) {
const parser = new ExpensiMark();
if (!Clipboard.canSetHtml()) {
Expand Down
4 changes: 2 additions & 2 deletions src/styles/fontFamily/multiFontFamily.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import getOperatingSystem from '@libs/getOperatingSystem';
dukenv0307 marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Loading