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
35 changes: 30 additions & 5 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,8 @@ function openReport(params: OpenReportActionParams) {

// If we are creating a new report, we need to add the optimistic report data and a report action
if (isCreatingNewReport) {
const shouldKeepPersonalDetailsOnFailure = shouldAddPendingFields && !isNewThread && !transaction && !newReportObject.parentReportID;

// Change the method to set for new reports because it doesn't exist yet, is faster,
// and we need the data to be available when we navigate to the chat page
const optimisticDataItem = optimisticData.at(0);
Expand Down Expand Up @@ -1899,11 +1901,13 @@ function openReport(params: OpenReportActionParams) {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: optimisticPersonalDetails,
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: settledPersonalDetails,
});
if (!shouldKeepPersonalDetailsOnFailure) {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
value: settledPersonalDetails,
});
}

if (!isNewThread) {
failureData.push({
Expand Down Expand Up @@ -4585,6 +4589,23 @@ function navigateToConciergeChatAndDeleteReport(
);
}

function cleanUpOptimisticPersonalDetailsForFailedChat(report: OnyxEntry<Report>, currentUserAccountID: number) {
const personalDetailsToRemove: PersonalDetailsList = {};

for (const accountID of Object.keys(report?.participants ?? {}).map(Number)) {
if (accountID === currentUserAccountID || !allPersonalDetails?.[accountID]?.isOptimisticPersonalDetail) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict cleanup to details created by this chat

When the failed chat reuses an optimistic personal-detail record that was already in Onyx, such as the same unknown email already present in a pending group chat, openReport() never owned that record or added it to settledPersonalDetails; however this cleanup deletes any optimistic participant in the failed report. Dismissing the failed direct chat can therefore remove the shared personal detail and make the other pending chat/invite lose the participant email again. Track and remove only the account IDs created for this failed report instead of all optimistic participants.

Useful? React with 👍 / 👎.

continue;
}
personalDetailsToRemove[accountID] = null;
}

if (isEmptyObject(personalDetailsToRemove)) {
return;
}

Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetailsToRemove);
}

function clearCreateChatError(
report: OnyxEntry<Report>,
conciergeReportID: string | undefined,
Expand All @@ -4603,6 +4624,10 @@ function clearCreateChatError(
return;
}

if (report?.errorFields?.createChat && isOptimisticReport) {
cleanUpOptimisticPersonalDetailsForFailedChat(report, currentUserAccountID);
}

navigateToConciergeChatAndDeleteReport(
report?.reportID,
conciergeReportID,
Expand Down
Loading