Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 7 additions & 37 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ const supportedActionTypes = new Set<ReportActionName>([...Object.values(otherAc
* Checks whether an action is actionable track expense and resolved.
*
*/
function isResolvedActionableWhisper(reportAction: OnyxEntry<ReportAction>, allActionsForReport?: OnyxEntry<ReportActions>): boolean {
function isResolvedActionableWhisper(reportAction: OnyxEntry<ReportAction>): boolean {
const originalMessage = getOriginalMessage(reportAction);
if (!originalMessage || typeof originalMessage !== 'object') {
return false;
Expand All @@ -1145,25 +1145,6 @@ function isResolvedActionableWhisper(reportAction: OnyxEntry<ReportAction>, allA
return false;
}

// For mention whispers, only treat as deleted if the parent comment is also deleted.
// This distinguishes cascade deletion (parent deleted -> whisper should hide) from
// the backend's one-per-user cleanup (parent still exists -> whisper should stay visible).
if (reportAction?.reportActionID && (isActionableMentionWhisper(reportAction) || isActionableReportMentionWhisper(reportAction))) {
const reportID = reportAction.reportID;
const actions = allActionsForReport ?? (reportID ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] : undefined);
if (actions) {
// Prefer the stored reportActionID from the whisper's originalMessage when available (set for
// whispers created during message edits, which don't follow the parentID+1 ID convention).
// Fall back to offset arithmetic for legacy whispers that predate this field.
const storedParentID = isActionableMentionWhisper(reportAction) ? (originalMessage as {parentReportActionID?: string}).parentReportActionID : undefined;
const parentActionID = storedParentID ?? String(BigInt(reportAction.reportActionID) - (isActionableReportMentionWhisper(reportAction) ? 2n : 1n));
const parentAction = actions[parentActionID];
if (parentAction && !isDeletedAction(parentAction)) {
return false;
}
}
}

return true;
Comment thread
shubham1206agra marked this conversation as resolved.
Resolved
}

Expand All @@ -1189,13 +1170,7 @@ function isResolvedConciergeDescriptionOptions(reportAction: OnyxEntry<ReportAct
* Checks if a reportAction is fit for display, meaning that it's not deprecated, is of a valid
* and supported type, it's not deleted and also not closed.
*/
function shouldReportActionBeVisible(
reportAction: OnyxEntry<ReportAction>,
key: string | number,
canUserPerformWriteAction?: boolean,
reportsParam?: OnyxCollection<Report>,
allActionsForReport?: OnyxEntry<ReportActions>,
): boolean {
function shouldReportActionBeVisible(reportAction: OnyxEntry<ReportAction>, key: string | number, canUserPerformWriteAction?: boolean, reportsParam?: OnyxCollection<Report>): boolean {
if (!reportAction) {
return false;
}
Expand Down Expand Up @@ -1275,7 +1250,7 @@ function shouldReportActionBeVisible(
}

// If action is actionable whisper and resolved by user, then we don't want to render anything
if (isActionableWhisper(reportAction) && isResolvedActionableWhisper(reportAction, allActionsForReport)) {
if (isActionableWhisper(reportAction) && isResolvedActionableWhisper(reportAction)) {
return false;
}

Expand Down Expand Up @@ -1319,27 +1294,22 @@ function isReportActionVisible(
return false;
}

// Look up all actions for this report so the parent-check in isResolvedActionableWhisper
// can determine whether a whisper's `deleted` flag reflects a real cascade deletion
// (parent comment deleted) vs. the backend's one-per-user cleanup (parent still exists).
const reportActionsForReport = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];

// Actions with pendingAction are optimistic or in-flight, so their visibility may differ
// from what's cached in visibleReportActions (which reflects persisted Onyx data).
// We must recalculate visibility at runtime to ensure accuracy for these transient states.
if (reportAction.pendingAction) {
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, undefined, reportActionsForReport);
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction);
}

if (visibleReportActions && reportID) {
const reportCache = visibleReportActions[reportID];
if (!reportCache) {
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, undefined, reportActionsForReport);
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction);
}
const staticVisibility = reportCache[reportAction.reportActionID];
// If action is not in derived value cache, fall back to runtime calculation
if (staticVisibility === undefined) {
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, undefined, reportActionsForReport);
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction);
}
if (!staticVisibility) {
return false;
Expand All @@ -1349,7 +1319,7 @@ function isReportActionVisible(
}
return true;
}
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, undefined, reportActionsForReport);
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default createOnyxDerivedValueConfig({
if (shouldSkipCachingAction(action)) {
continue;
}
reportVisibility[action.reportActionID] = shouldReportActionBeVisible(action, actionID, undefined, allReports, reportActions);
reportVisibility[action.reportActionID] = shouldReportActionBeVisible(action, actionID, undefined, allReports);
}
}
}
Expand Down Expand Up @@ -114,7 +114,7 @@ export default createOnyxDerivedValueConfig({
delete reportVisibility[action.reportActionID];
continue;
}
reportVisibility[action.reportActionID] = shouldReportActionBeVisible(action, actionID, undefined, allReports, reportActions);
reportVisibility[action.reportActionID] = shouldReportActionBeVisible(action, actionID, undefined, allReports);
}
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ export default createOnyxDerivedValueConfig({
continue;
}

reportVisibility[action.reportActionID] = shouldReportActionBeVisible(action, actionID, undefined, allReports, reportActions);
reportVisibility[action.reportActionID] = shouldReportActionBeVisible(action, actionID, undefined, allReports);
}
}

Expand Down
60 changes: 0 additions & 60 deletions tests/unit/ReportActionsUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import {
isConsecutiveActionMadeByPreviousActor,
isIOUActionMatchingTransactionList,
isNewerReportAction,
isResolvedActionableWhisper,
shouldHideNewMarker,
} from '../../src/libs/ReportActionsUtils';
import {buildOptimisticCreatedReportForUnapprovedAction} from '../../src/libs/ReportUtils';
Expand Down Expand Up @@ -1044,65 +1043,6 @@ describe('ReportActionsUtils', () => {
// Then the whisper with deleted set should be filtered out, leaving only the ADD_COMMENT
expect(result).toStrictEqual([input.at(0)]);
});

it('should keep ACTIONABLE_MENTION_WHISPER visible when deleted is set but parent comment is not deleted', () => {
// Given a parent ADD_COMMENT (ID N) and an ACTIONABLE_MENTION_WHISPER (ID N+1) whose
// originalMessage.deleted is set (e.g. from the backend one-per-user cleanup rule).
// Use sequential IDs so the parent check can find the parent via whisperID - 1.
const parentID = '1000000000000000';
const whisperID = '1000000000000001';

const parentAction: ReportAction = {
created: '2024-11-19 08:04:13.728',
reportActionID: parentID,
reportID: '1',
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
originalMessage: {
html: '<mention-user accountID="18414674"/>',
whisperedTo: [],
lastModified: '2024-11-19 08:04:13.728',
},
message: [
{
html: '<mention-user accountID="18414674"/>',
text: '@someone',
type: 'COMMENT',
whisperedTo: [],
},
],
};

const whisperAction: ReportAction = {
created: '2024-11-19 08:04:13.730',
reportActionID: whisperID,
reportID: '1',
actionName: CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER,
originalMessage: {
inviteeAccountIDs: [18414674],
lastModified: '2024-11-19 08:04:25.813',
whisperedTo: [18301266],
deleted: '2024-11-19 08:04:27.000',
},
message: [
{
html: "Heads up, <mention-user accountID=18414674></mention-user> isn't a member of this room.",
text: "Heads up, isn't a member of this room.",
type: 'COMMENT',
},
],
};

const allActionsForReport: ReportActions = {
[parentID]: parentAction,
[whisperID]: whisperAction,
};

// When checking whether the whisper is resolved, providing the full action set
const result = isResolvedActionableWhisper(whisperAction, allActionsForReport);

// Then the whisper should NOT be treated as resolved because its parent is still present and not deleted
expect(result).toBe(false);
});
});

describe('hasRequestFromCurrentAccount', () => {
Expand Down
Loading