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

Turn channel log member message into HTML #32161

Merged
merged 7 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
13 changes: 9 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import DeepValueOf from '@src/types/utils/DeepValueOf';
import {EmptyObject, isEmptyObject, isNotEmptyObject} from '@src/types/utils/EmptyObject';
import * as CurrencyUtils from './CurrencyUtils';
import DateUtils from './DateUtils';
import * as Environment from './Environment/Environment';
import isReportMessageAttachment from './isReportMessageAttachment';
import * as LocalePhoneNumber from './LocalePhoneNumber';
import * as Localize from './Localize';
Expand Down Expand Up @@ -346,6 +347,9 @@ type OnyxDataTaskAssigneeChat = {
optimisticChatCreatedReportAction?: OptimisticCreatedReportAction;
};

let environmentURL: string;
Environment.getEnvironmentURL().then((url: string) => (environmentURL = url));

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you see tryResolveUrlFromApiRoot instead of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there any specific reason? Because I took reference from ReportActionsUtils here:

updatedReportAction.message[0].html = reportAction.message[0].html?.replace('%baseURL', environmentURL);

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe above method doesn't work in that case, thats why they have used environmentURL directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tryResolveUrlFromApiRoot requires a pre-defined/existing URL to resolve the base domain. In this case, there's no such URL. It's usually used for attachment link. For report actions, I see that environmentURL is used across the app like here, here, here, etc.

let currentUserEmail: string | undefined;
let currentUserAccountID: number | undefined;
let isAnonymousUser = false;
Expand Down Expand Up @@ -4147,8 +4151,8 @@ function getChannelLogMemberMessage(reportAction: OnyxEntry<ReportAction>): stri
? 'invited'
: 'removed';

const mentions = (reportAction?.originalMessage as ChangeLog)?.targetAccountIDs?.map(() => {
const personalDetail = allPersonalDetails?.accountID;
const mentions = (reportAction?.originalMessage as ChangeLog)?.targetAccountIDs?.map((accountID) => {
const personalDetail = allPersonalDetails?.[accountID];
const displayNameOrLogin = LocalePhoneNumber.formatPhoneNumber(personalDetail?.login ?? '') || (personalDetail?.displayName ?? '') || Localize.translateLocal('common.hidden');
return `@${displayNameOrLogin}`;
});
Expand All @@ -4164,13 +4168,14 @@ function getChannelLogMemberMessage(reportAction: OnyxEntry<ReportAction>): stri
message = `${verb} ${mentions?.join(', ')}, and ${lastMention}`;
}

const reportID = (reportAction?.originalMessage as ChangeLog)?.reportID ?? 0;
const roomName = (reportAction?.originalMessage as ChangeLog)?.roomName ?? '';
if (roomName) {
if (reportID && 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}`;
message += `${preposition} <a href="${environmentURL}/r/${reportID}" target="_blank">${roomName}</a>`;
}

return message;
Expand Down
24 changes: 16 additions & 8 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import {clearActiveReportAction, hideContextMenu, showDeleteModal} from './ReportActionContextMenu';

/**
* Sets the HTML string to Clipboard.
* @param {String} content
*/
function setClipboardHtmlMessage(content) {
const parser = new ExpensiMark();
if (!Clipboard.canSetHtml()) {
Clipboard.setString(parser.htmlToMarkdown(content));
} else {
const plainText = parser.htmlToText(content);
Clipboard.setHtml(content, plainText);
}
}

/**
* Gets the HTML version of the message in an action.
* @param {Object} reportAction
Expand Down Expand Up @@ -283,15 +297,9 @@ export default [
Clipboard.setString(displayMessage);
} else if (ReportActionsUtils.isChannelLogMemberAction(reportAction)) {
const logMessage = ReportUtils.getChannelLogMemberMessage(reportAction);
Clipboard.setString(logMessage);
setClipboardHtmlMessage(logMessage);
} else if (content) {
const parser = new ExpensiMark();
if (!Clipboard.canSetHtml()) {
Clipboard.setString(parser.htmlToMarkdown(content));
} else {
const plainText = parser.htmlToText(content);
Clipboard.setHtml(content, plainText);
}
setClipboardHtmlMessage(content);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ type ChronosOOOTimestamp = {
type ChangeLog = {
targetAccountIDs?: number[];
roomName?: string;
reportID?: number;
};

type ChronosOOOEvent = {
Expand Down
Loading