Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.3k stars 2.74k forks source link

[HOLD for payment 2024-08-09] [$250] Threads - Leaving from multilevel threads navigates to wrong thread #46085

Closed lanitochka17 closed 2 weeks ago

lanitochka17 commented 1 month ago

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.11-0 Reproducible in staging?: Y Reproducible in production?: N If this was caught during regression testing, add the test name, ID and link from TestRail: N/A Email or phone of affected tester (no customers): bezawitgebremichael+kkii@gmail.com Issue reported by: Applause - Internal Team

Action Performed:

  1. Navigate to staging.new.expensify.com
  2. Open a chat
  3. Send a message (Name it parent message for easier observation)
  4. Hover over the message and click on reply in thread
  5. Send another message in the thread (Name it thread 1 for easier observation)
  6. Hover over the message and click on reply in thread
  7. Send another message in the thread (Name it thread 2 for easier observation)
  8. Click on the header of the thread
  9. Click on leave
  10. Note the name of the header and click on it
  11. Click on leave
  12. Note the name of the header and wait a few seconds

Expected Result:

When leaving the first level thread app navigates user to the parent thread, when leaving from the parent thread app navigates to the Original chat and no "You don't have access to this chat" page is displayed

Actual Result:

When leaving the first level thread app navigates to the parent thread but when leaving the parent thread again the app navigates user back to the first level thread and then after a few seconds "You don't have access to this chat" page is displayed

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/user-attachments/assets/e3859a61-2e16-4172-9b2f-cdf66ac49b09

405

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01a17100bfa3035f8c
  • Upwork Job ID: 1816165199632115677
  • Last Price Increase: 2024-07-24
Issue OwnerCurrent Issue Owner: @mananjadhav
melvin-bot[bot] commented 1 month ago

Triggered auto assignment to @marcaaron (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

github-actions[bot] commented 1 month ago

:wave: Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

  1. Identify the pull request that introduced this issue and revert it.
  2. Find someone who can quickly fix the issue.
  3. Fix the issue yourself.
lanitochka17 commented 1 month ago

We think that this bug might be related to #vip-vsp

nyomanjyotisa commented 1 month ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

Leaving from multilevel threads navigates to wrong thread

What is the root cause of that problem?

On leave action we always navigate to the most recent report/the last accessed report here

https://github.com/Expensify/App/blob/2bb1d002b9dfa7045a5ddbcb7ee99d4ae207948d/src/libs/actions/Report.ts#L2706

What changes do you think we should make in order to solve the problem?

If parentReportID exist navigate to the parent report instead of the most recent report

    if (report.parentReportID) {
        const parentReportRoute = ROUTES.REPORT_WITH_ID.getRoute(report.parentReportID);
        Navigation.goBack(parentReportRoute);
    }else{
        navigateToMostRecentReport(report);
    }

What alternative solutions did you explore? (Optional)

daledah commented 1 month ago

Proposal

Please re-state the problem that we are trying to solve in this issue.

When leaving the first level thread app navigates to the parent thread but when leaving the parent thread again the app navigates user back to the first level thread and then after a few seconds "You don't have access to this chat" page is displayed

What is the root cause of that problem?

When leaving room, we always call: https://github.com/Expensify/App/blob/2bb1d002b9dfa7045a5ddbcb7ee99d4ae207948d/src/libs/actions/Report.ts#L2790 That function get the most recent access report based on: https://github.com/Expensify/App/blob/2bb1d002b9dfa7045a5ddbcb7ee99d4ae207948d/src/libs/ReportUtils.ts#L1209-L1214 without filtering the leaved thread, lead to the loop behavior: Assume we have two thread 1 and 2. Access 1 then access 2. Now leave thread 2. User is moved to thread 1. Then leave thread 1. User is moved to thread 2. And then join thread 2. Then leave thread 2. User is moved to thread 1, ...

What changes do you think we should make in order to solve the problem?

We should filter the leaved report from above:

function getMostRecentlyVisitedReport(reports: Array<OnyxEntry<Report>>, reportMetadata: OnyxCollection<ReportMetadata>, shouldKeepLeavedThread = true): OnyxEntry<Report> {
    const filteredReports = reports.filter((report) => {
        const shouldKeep = shouldKeepLeavedThread || !isChatThread(report) || (isChatThread(report) && report?.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);
        return shouldKeep && !!report?.reportID && !!(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`]?.lastVisitTime ?? report?.lastReadTime);
    });
    return lodashMaxBy(filteredReports, (a) => new Date(reportMetadata?.[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${a?.reportID}`]?.lastVisitTime ?? a?.lastReadTime ?? '').valueOf());
}

When leaving room, we use shouldKeepLeavedThread : false to make sure this change does not break other logic.

francoisl commented 1 month ago

Thanks for the proposals. Can you identify which PR from the checklist introduced this issue?

melvin-bot[bot] commented 1 month ago

Job added to Upwork: https://www.upwork.com/jobs/~01a17100bfa3035f8c

melvin-bot[bot] commented 1 month ago

Triggered auto assignment to Contributor-plus team member for initial proposal review - @mananjadhav (External)

allroundexperts commented 1 month ago

Thanks for the proposals everyone!

@daledah's proposal has the correct RCA and fixes the root issue.

@nyomanjyotisa I think your proposal is applying a cosmetic patch, without addressing the actual underlying issue.

πŸŽ€ πŸ‘€ πŸŽ€ C+ reviewed

melvin-bot[bot] commented 1 month ago

Current assignee @marcaaron is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

melvin-bot[bot] commented 1 month ago

πŸ“£ @daledah You have been assigned to this job! Please apply to the Upwork job and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review πŸ§‘β€πŸ’» Once you apply to this job, your Upwork ID will be stored and you will be automatically hired for future jobs! Keep in mind: Code of Conduct | Contributing πŸ“–

francoisl commented 1 month ago

@daledah are you available to submit a PR?

francoisl commented 1 month ago

We had an issue with the web production deploy that caused the deploy to fail for a few days, but it's fixed now and this issue is now reproducible on production. Going to remove the deploy blocker.

daledah commented 1 month ago

@francoisl I'm opening a PR soon.

daledah commented 1 month ago

@allroundexperts this PR is ready for review.

melvin-bot[bot] commented 1 month ago

@allroundexperts, @marcaaron, @daledah Huh... This is 4 days overdue. Who can take care of this?

melvin-bot[bot] commented 1 month ago

Reviewing label has been removed, please complete the "BugZero Checklist".

melvin-bot[bot] commented 1 month ago

The solution for this issue has been :rocket: deployed to production :rocket: in version 9.0.15-9 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-08-09. :confetti_ball:

For reference, here are some details about the assignees on this issue:

melvin-bot[bot] commented 4 weeks ago

Issue is ready for payment but no BZ is assigned. @adelekennedy you are the lucky winner! Please verify the payment summary looks correct and complete the checklist. Thanks!

melvin-bot[bot] commented 4 weeks ago

Payment Summary

Upwork Job

BugZero Checklist (@adelekennedy)

allroundexperts commented 3 weeks ago

Checklist

  1. https://github.com/Expensify/App/pull/44948/files
  2. https://github.com/Expensify/App/pull/44948/files#r1713856786
  3. N/A
  4. A regression test would be helpful.

Regression Test

  1. Navigate to the app and Open a chat
  2. Send a message (Name it parent message for easier observation)
  3. Hover over the message and click on reply in thread
  4. Send another message in the thread (Name it thread 1 for easier observation)
  5. Hover over the message and click on reply in thread
  6. Send another message in the thread (Name it thread 2 for easier observation)
  7. Click on the header of the thread and click on leave
  8. Note the name of the header and click on it, and click on leave

Verify that when leaving the first level thread app navigates user to the parent thread, when leaving from the parent thread app navigates to the Original chat and no "You don't have access to this chat" page is displayed

Do we πŸ‘ or πŸ‘Ž ?

adelekennedy commented 3 weeks ago

Payouts due:

Upwork job is here.

adelekennedy commented 3 weeks ago

Bump @daledah!

daledah commented 3 weeks ago

Sorry @adelekennedy I don't have any Upwork Connects so I could not apply to the job. Instead, could you send the offer directly to my profile here https://www.upwork.com/freelancers/~0138d999529f34d33f. TY

melvin-bot[bot] commented 2 weeks ago

@allroundexperts, @marcaaron, @adelekennedy, @daledah Whoops! This issue is 2 days overdue. Let's get this updated quick!

adelekennedy commented 2 weeks ago

hired @daledah!

daledah commented 2 weeks ago

@adelekennedy I have accepted, thank you