Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
af2c7d0
Include 'deleted' in considering if a whisper is resolved
deetergp Feb 18, 2026
f14c9ae
Add a test to cover deleted marking whispers resolved
deetergp Feb 18, 2026
11482d9
ESLint fix
deetergp Feb 25, 2026
20be867
Include reportID
deetergp Feb 26, 2026
e7a4f2c
Update the comment to better explain what we're testing
deetergp Feb 26, 2026
c72739f
Merge branch 'main' into scott-deleteMentionWithAddComment
deetergp Mar 4, 2026
78b64e7
Optimistically delete the mention whisper
deetergp Mar 4, 2026
97fb8aa
TypeScript Checker fix
deetergp Mar 4, 2026
10b7697
Merge branch 'main' into scott-deleteMentionWithAddComment
deetergp Mar 5, 2026
957af9d
Optimistically hide actionable whisper when parent comment is deleted
deetergp Mar 6, 2026
0595ce5
Add a test for offline deletion
deetergp Mar 6, 2026
90d3ff2
ESLint fix
deetergp Mar 6, 2026
20a9f90
Wrap whisper in getOriginalMessage
deetergp Mar 6, 2026
6b765ca
Merge branch 'main' into scott-deleteMentionWithAddComment
deetergp Mar 13, 2026
902943d
Make array of unresolved whisper IDs to delete
deetergp Mar 13, 2026
3507c30
Add test for when multiple unresolved whispers present
deetergp Mar 13, 2026
85a0d13
ESLint fixes
deetergp Mar 13, 2026
2e1b218
Merge branch 'main' into scott-deleteMentionWithAddComment
deetergp Mar 16, 2026
54aae53
Pass the report action for reverse checking deleted status
deetergp Mar 17, 2026
f7600a5
Add a test to ensure past whisper stays visible
deetergp Mar 17, 2026
fb54737
Pass all report actions to shouldReportActionBeVisible
deetergp Mar 17, 2026
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
57 changes: 48 additions & 9 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
}

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 92 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -101,7 +101,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 104 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -110,13 +110,13 @@
});

let isNetworkOffline = false;
Onyx.connect({

Check warning on line 113 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NETWORK,
callback: (val) => (isNetworkOffline = val?.isOffline ?? false),
});

let deprecatedCurrentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 119 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, value is undefined
Expand Down Expand Up @@ -1078,10 +1078,38 @@
* Checks whether an action is actionable track expense and resolved.
*
*/
function isResolvedActionableWhisper(reportAction: OnyxEntry<ReportAction>): boolean {
function isResolvedActionableWhisper(reportAction: OnyxEntry<ReportAction>, allActionsForReport?: OnyxEntry<ReportActions>): boolean {
const originalMessage = getOriginalMessage(reportAction);
const resolution = originalMessage && typeof originalMessage === 'object' && 'resolution' in originalMessage ? originalMessage?.resolution : null;
return !!resolution;
if (!originalMessage || typeof originalMessage !== 'object') {
return false;
}
const resolution = 'resolution' in originalMessage ? originalMessage?.resolution : null;
if (resolution) {
return true;
}

const deleted = 'deleted' in originalMessage ? originalMessage?.deleted : null;
if (!deleted) {
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) {
const parentOffset = isActionableReportMentionWhisper(reportAction) ? 2n : 1n;
const parentActionID = String(BigInt(reportAction.reportActionID) - parentOffset);
const parentAction = actions[parentActionID];
if (parentAction && !isDeletedAction(parentAction)) {
return false;
}
}
}

return true;
}

/**
Expand All @@ -1106,7 +1134,13 @@
* 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>): boolean {
function shouldReportActionBeVisible(
reportAction: OnyxEntry<ReportAction>,
key: string | number,
canUserPerformWriteAction?: boolean,
reportsParam?: OnyxCollection<Report>,
allActionsForReport?: OnyxEntry<ReportActions>,
): boolean {
if (!reportAction) {
return false;
}
Expand Down Expand Up @@ -1183,7 +1217,7 @@
}

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

Expand Down Expand Up @@ -1219,22 +1253,27 @@
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);
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, undefined, reportActionsForReport);
}

if (visibleReportActions) {
const reportCache = visibleReportActions[reportID];
if (!reportCache) {
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction);
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, undefined, reportActionsForReport);
}
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);
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, undefined, reportActionsForReport);
}
if (!staticVisibility) {
return false;
Expand All @@ -1244,7 +1283,7 @@
}
return true;
}
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction);
return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, undefined, reportActionsForReport);
}

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

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

Expand Down
64 changes: 54 additions & 10 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@

Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {

Check warning on line 376 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
if (!key || !actions) {
return;
}
Expand All @@ -385,7 +385,7 @@
let allReports: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,

Check warning on line 388 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
callback: (value) => {
allReports = value;
},
Expand All @@ -394,7 +394,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {

Check warning on line 397 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
allPersonalDetails = value ?? {};
},
});
Expand All @@ -412,7 +412,7 @@
let onboarding: OnyxEntry<Onboarding>;
Onyx.connect({
key: ONYXKEYS.NVP_ONBOARDING,
callback: (val) => {

Check warning on line 415 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
if (Array.isArray(val)) {
return;
}
Expand Down Expand Up @@ -2440,6 +2440,7 @@
isOriginalReportArchived: boolean | undefined,
currentEmail: string,
visibleReportActionsDataParam?: VisibleReportActionsDerivedValue,
currentReportActionsParam?: OnyxEntry<ReportActions>,
) {
const reportID = report?.reportID;
const originalReportID = getOriginalReportID(reportID, reportAction, undefined);
Expand Down Expand Up @@ -2470,6 +2471,42 @@
},
};

// Optimistically hide whispers associated with the deleted comment. We use the same conventions
// as the backend (UpdateReportComment.cpp) to locate the correct whisper(s):
// - ACTIONABLE_MENTION_WHISPER has ID = parentCommentID + 1
// - ACTIONABLE_REPORT_MENTION_WHISPER has ID = parentCommentID + 2, and its originalMessage
// also stores the parent's reportActionID so we can verify the match.
// We prefer the actions passed directly from the calling component (currentReportActionsParam)
// since those come from useOnyx and are guaranteed to be up to date. We fall back to the
// module-level allReportActions cache.
const reportActionsForReport = currentReportActionsParam ?? allReportActions?.[originalReportID] ?? {};
const unresolvedMentionWhisperIDs: string[] = [];

const mentionWhisperID = String(BigInt(reportActionID) + 1n);
const mentionWhisperAction = reportActionsForReport[mentionWhisperID];
if (ReportActionsUtils.isActionableMentionWhisper(mentionWhisperAction)) {
const originalMessage = ReportActionsUtils.getOriginalMessage(mentionWhisperAction);
if (!originalMessage?.resolution && !originalMessage?.deleted) {
unresolvedMentionWhisperIDs.push(mentionWhisperID);
}
}

const reportMentionWhisperID = String(BigInt(reportActionID) + 2n);
const reportMentionWhisperAction = reportActionsForReport[reportMentionWhisperID];
if (ReportActionsUtils.isActionableReportMentionWhisper(reportMentionWhisperAction)) {
const originalMessage = ReportActionsUtils.getOriginalMessage(reportMentionWhisperAction);
if (!originalMessage?.resolution && !originalMessage?.deleted) {
unresolvedMentionWhisperIDs.push(reportMentionWhisperID);
}
}

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.

This PR missed a case (#86084). The offset-based whisper lookup only checks parentID + 1 and parentID + 2 to find associated whispers. This works for whispers created on initial send, but when a message is edited to add a new mention, the backend creates a new whisper with a random ID (since the +1 slot is already taken). These edit-created whispers are missed by both the optimistic deletion and the isResolvedActionableWhisper visibility check, which uses the reverse offset (whisperID - 1) to find the parent.

Fix: #86264


const deletedTime = DateUtils.getDBTime();
for (const whisperID of unresolvedMentionWhisperIDs) {
optimisticReportActions[whisperID] = {
originalMessage: {deleted: deletedTime},
};
}

// If we are deleting the last visible message, let's find the previous visible one (or set an empty one if there are none) and update the lastMessageText in the LHN.
// Similarly, if we are deleting the last read comment we will want to update the lastVisibleActionCreated to use the previous visible message.
const canUserPerformWriteAction = canUserPerformWriteActionReportUtils(report, isReportArchived);
Expand All @@ -2481,28 +2518,35 @@

const didCommentMentionCurrentUser = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentEmail);
if (didCommentMentionCurrentUser && reportAction.created === report?.lastMentionedTime) {
const reportActionsForReport = allReportActions?.[reportID];
const latestMentionedReportAction = Object.values(reportActionsForReport ?? {}).find(
const reportActionsForReportID = allReportActions?.[reportID];
const latestMentionedReportAction = Object.values(reportActionsForReportID ?? {}).find(
(action) =>
action.reportActionID !== reportAction.reportActionID &&
ReportActionsUtils.didMessageMentionCurrentUser(action, currentEmail) &&
ReportActionsUtils.isReportActionVisible(action, reportID, undefined, visibleReportActionsDataParam),
);
optimisticReport.lastMentionedTime = latestMentionedReportAction?.created ?? null;
}

// If the API call fails we must show the original message again, so we revert the message content back to how it was
// and and remove the pendingAction so the strike-through clears
// and remove the pendingAction so the strike-through clears
const failureReportActionsData: NullishDeep<ReportActions> = {
[reportActionID]: {
message: reportAction.message,
pendingAction: null,
previousMessage: null,
},
};
for (const whisperID of unresolvedMentionWhisperIDs) {
failureReportActionsData[whisperID] = {
originalMessage: {deleted: null},
};
}
const failureData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>> = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`,
value: {
[reportActionID]: {
message: reportAction.message,
pendingAction: null,
previousMessage: null,
},
},
value: failureReportActionsData,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ function PopoverReportActionContextMenu({ref}: PopoverReportActionContextMenuPro
const reportActionDraftMessageRef = useRef<string | undefined>(undefined);
const isReportArchived = useReportIsArchived(reportIDRef.current);
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportIDRef.current}`);
const reportActionsRef = useRef(reportActions);
reportActionsRef.current = reportActions;
const isOriginalReportArchived = useReportIsArchived(getOriginalReportID(reportIDRef.current, reportActionRef.current, reportActions));
const {iouReport, chatReport, isChatIOUReportArchived} = useGetIOUReportFromReportAction(reportActionRef.current);
const {transitionActionSheetState} = useActionSheetAwareScrollViewActions();
Expand Down Expand Up @@ -388,7 +390,16 @@ function PopoverReportActionContextMenu({ref}: PopoverReportActionContextMenuPro
} else if (reportAction) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => {
deleteReportComment(report, reportAction, ancestorsRef.current, isReportArchived, isOriginalReportArchived, email ?? '', visibleReportActionsData ?? undefined);
deleteReportComment(
report,
reportAction,
ancestorsRef.current,
isReportArchived,
isOriginalReportArchived,
email ?? '',
visibleReportActionsData ?? undefined,
reportActionsRef.current ?? undefined,
);
});
}

Expand Down
9 changes: 9 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ type OriginalMessageActionableMentionWhisper = {

/** Collection of accountIDs of users mentioned in message */
whisperedTo?: number[];

/** Timestamp of when the whisper was deleted (set by the backend when the parent comment is deleted) */
deleted?: string | null;
};

/** Model of `actionable card fraud alert` report action */
Expand Down Expand Up @@ -189,6 +192,12 @@ type OriginalMessageActionableReportMentionWhisper = {

/** Collection of accountIDs of users mentioned in message */
whisperedTo?: number[];

/** Timestamp of when the whisper was deleted (set by the backend when the parent comment is deleted) */
deleted?: string | null;

/** The reportActionID of the parent comment that triggered this whisper */
reportActionID?: number;
};

/** Model of `welcome whisper` report action */
Expand Down
Loading
Loading