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
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
21 changes: 13 additions & 8 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4118,26 +4118,31 @@ function getIOUReportActionDisplayMessage(reportAction) {

/**
* 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 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you actually tested that this case is required? I thought I tested it with my suggested variant

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh... I think I get it

Copy link
Contributor

Choose a reason for hiding this comment

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

Still, I think this logic is still slightly more readable (even if the advantage is smaller than I originally assumed)

return `${actionPerformed} ${mentions[0]} and ${lastMention}`;
}
return `${actionPerformed} ${listMention.join(', ')}${lastPrefix}${lastMention}`;

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

/**
Expand Down
Loading