Skip to content

Commit

Permalink
Merge pull request #35525 from Expensify/blimpich-fixBaseUrlForLeaveMsgs
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored Feb 1, 2024
2 parents 63ba91f + 8bd87b2 commit c9f7ec3
Showing 1 changed file with 9 additions and 15 deletions.
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));

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;
}

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);

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

0 comments on commit c9f7ec3

Please sign in to comment.