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

fix: restore report lastMessageText after resolve whisper msg #44764

Merged
merged 11 commits into from
Jul 31, 2024
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
31 changes: 31 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7089,6 +7089,36 @@ function findPolicyExpenseChatByPolicyID(policyID: string): OnyxEntry<Report> {
return Object.values(ReportConnection.getAllReports() ?? {}).find((report) => isPolicyExpenseChat(report) && report?.policyID === policyID);
}

/**
* A function to get the report last message. This is usually used to restore the report message preview in LHN after report actions change.
* @param reportID
* @param actionsToMerge
* @returns containing the calculated message preview data of the report
*/
function calcReportLastMessage(reportID: string, actionsToMerge?: ReportActions) {
let result: Partial<Report> = {
lastMessageTranslationKey: '',
lastMessageText: '',
lastVisibleActionCreated: '',
};

const {lastMessageText = '', lastMessageTranslationKey = ''} = getLastVisibleMessage(reportID, actionsToMerge);

if (lastMessageText || lastMessageTranslationKey) {
const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID, actionsToMerge);
const lastVisibleActionCreated = lastVisibleAction?.created;
const lastActorAccountID = lastVisibleAction?.actorAccountID;
result = {
lastMessageTranslationKey,
lastMessageText,
lastVisibleActionCreated,
lastActorAccountID,
};
}

return result;
}

export {
addDomainToShortMention,
areAllRequestsBeingSmartScanned,
Expand Down Expand Up @@ -7369,6 +7399,7 @@ export {
getChatUsedForOnboarding,
findPolicyExpenseChatByPolicyID,
hasOnlyNonReimbursableTransactions,
calcReportLastMessage,
getMostRecentlyVisitedReport,
};

Expand Down
32 changes: 31 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3626,6 +3626,16 @@ function resolveActionableMentionWhisper(reportId: string, reportAction: OnyxEnt
resolution,
};

const optimisticReportActions = {
[reportAction.reportActionID]: {
originalMessage: {
resolution,
},
},
};

const reportUpdateDataWithPreviousLastMessage = ReportUtils.calcReportLastMessage(reportId, optimisticReportActions as ReportActions);

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -3639,6 +3649,11 @@ function resolveActionableMentionWhisper(reportId: string, reportAction: OnyxEnt
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportId}`,
value: reportUpdateDataWithPreviousLastMessage,
},
];

const failureData: OnyxUpdate[] = [
Expand Down Expand Up @@ -3673,6 +3688,16 @@ function resolveActionableReportMentionWhisper(
return;
}

const optimisticReportActions = {
[reportAction.reportActionID]: {
originalMessage: {
resolution,
},
},
};

const reportUpdateDataWithPreviousLastMessage = ReportUtils.calcReportLastMessage(reportId, optimisticReportActions as ReportActions);

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -3683,7 +3708,12 @@ function resolveActionableReportMentionWhisper(
resolution,
},
},
},
} as ReportActions,
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportId}`,
value: reportUpdateDataWithPreviousLastMessage,
},
];

Expand Down
Loading