Skip to content
Merged
Changes from all 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
24 changes: 9 additions & 15 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type MemberChangeMessageRoomReferenceElement = {

type MemberChangeMessageElement = MessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement;

const policyChangeActionsSet = new Set<string>(Object.values(CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NAB: I don't really think this needs to be a const, why don't we just use new Set<string>(Object.values(CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG)) directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See this thread: #35525 (comment).


const allReports: OnyxCollection<Report> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down Expand Up @@ -411,33 +413,25 @@ function shouldReportActionBeVisibleAsLastAction(reportAction: OnyxEntry<ReportA
}

/**
* For invite to room and remove from room policy change logs, report URLs are generated in the server,
* For policy change logs, report URLs are generated in the server,
* which includes a baseURL placeholder that's replaced in the client.
*/
function replaceBaseURL(reportAction: ReportAction): ReportAction {
if (!reportAction) {
function replaceBaseURLInPolicyChangeLogAction(reportAction: ReportAction): ReportAction {
if (!reportAction?.message || !policyChangeActionsSet.has(reportAction?.actionName)) {
return reportAction;
}
Comment thread
marcaaron marked this conversation as resolved.

if (
!reportAction ||
(reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.INVITE_TO_ROOM && reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.POLICYCHANGELOG.REMOVE_FROM_ROOM)
) {
return reportAction;
}
if (!reportAction.message) {
return reportAction;
}
const updatedReportAction = _.clone(reportAction);

Comment thread
marcaaron marked this conversation as resolved.
if (!updatedReportAction.message) {
return updatedReportAction;
}

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

return updatedReportAction;
}

/**
*/
function getLastVisibleAction(reportID: string, actionsToMerge: ReportActions = {}): OnyxEntry<ReportAction> {
const reportActions = Object.values(fastMerge(allReportActions?.[reportID] ?? {}, actionsToMerge, true));
const visibleReportActions = Object.values(reportActions ?? {}).filter((action) => shouldReportActionBeVisibleAsLastAction(action));
Expand Down Expand Up @@ -494,7 +488,7 @@ function getSortedReportActionsForDisplay(reportActions: ReportActions | null, s
const filteredReportActions = Object.entries(reportActions ?? {})
.filter(([key, reportAction]) => shouldReportActionBeVisible(reportAction, key))
.map((entry) => entry[1]);
const baseURLAdjustedReportActions = filteredReportActions.map((reportAction) => replaceBaseURL(reportAction));
const baseURLAdjustedReportActions = filteredReportActions.map((reportAction) => replaceBaseURLInPolicyChangeLogAction(reportAction));
return getSortedReportActions(baseURLAdjustedReportActions, true, shouldMarkTheFirstItemAsNewest);
}

Expand Down