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.35k stars 2.77k forks source link

[$250] LHN - Members' room names are not updated in LHN after cache deletion #49260

Open IuliiaHerets opened 1 week ago

IuliiaHerets commented 1 week 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.34-2 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/4960406 Email or phone of affected tester (no customers): sustinov@applausemail.com Issue reported by: Applause Internal Team

Action Performed:

Prerequisites: Create a WS and add two employees to it

Steps:

  1. Open NewExpensify app
  2. Log in with a WS administrator account
  3. Go to the account settings
  4. Go to the Troubleshoot menu
  5. Click on “Clear cache and restart” and clear the cache
  6. Go back to the LHN Inbox

Expected Result:

Members' room names should be updated and display the room name in LHN after the cache is deleted

Actual Result:

Members' room names are not updated in LHN after cache deletion

Workaround:

Unknown

Platforms:

Screenshots/Videos

https://github.com/user-attachments/assets/db29d7ee-4e4f-4f86-bd16-b4964ab8931c

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021836832143423032683
  • Upwork Job ID: 1836832143423032683
  • Last Price Increase: 2024-09-19
Issue OwnerCurrent Issue Owner: @ikevin127
melvin-bot[bot] commented 1 week ago

Triggered auto assignment to @zanyrenney (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

IuliiaHerets commented 1 week ago

@zanyrenney FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

melvin-bot[bot] commented 4 days ago

@zanyrenney Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

zanyrenney commented 4 days ago

whoops!!!

zanyrenney commented 4 days ago

yeh i agree this is a bug. we should look at this in ND quality.

melvin-bot[bot] commented 4 days ago

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

melvin-bot[bot] commented 4 days ago

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

ikevin127 commented 2 days ago

💰 Looking for proposal (if issue is reproducible).

huult commented 1 day ago

Proposal

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

Members' room names are not updated in LHN after cache deletion

What is the root cause of that problem?

When we clear the cache and restart, personalDetails will return {isOptimisticPersonalDetail: true}, and reportOwnerDisplayName will be set to report?.reportName because getDisplayNameForParticipant(ownerAccountID) or login will not have a value. As a result, we will see the name as Chat Report https://github.com/Expensify/App/blob/9160fa585c26d3312fd6d6fbd69d334e66cb373d/src/libs/ReportUtils.ts#L2681

And when we send a message, personalDetails will be updated after the AddComment call is completed. At this point, getDisplayNameForParticipant(ownerAccountID) will return the participant's display name, and login will also have a value. As a result, the report name will be set based on the logic we check. Therefore, reportOwnerDisplayName will return the value from getDisplayNameForParticipant(ownerAccountID), and this issue will occur.

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

I think this is not a bug, but we need to confirm the expected behavior in this case.

Solution 1

If we want to keep the report name as the members' room name after clearing the cache or restarting, we can check it like this.

// .src/libs/ReportUtils.ts#L560
+ let hasResetOccurredBefore: boolean = false;
+ Onyx.connect({
+    key: ONYXKEYS.HAS_RESET_OCCURRED_BEFORE,
+    waitForCollectionCallback: true,
+    callback: (value) => {
+        hasResetOccurredBefore = value;
+    },
+ });

// .src/libs/ReportUtils.ts#L2681
- const reportOwnerDisplayName = getDisplayNameForParticipant(ownerAccountID) || login || report?.reportName;
+    const reportOwnerDisplayName = hasResetOccurredBefore 
+    ? report?.reportName ?? getDisplayNameForParticipant(ownerAccountID) ?? login 
+    : getDisplayNameForParticipant(ownerAccountID) ?? login ?? report?.reportName;

// .src/pages/settings/Troubleshoot/TroubleshootPage.tsx#L161
         Onyx.clear(App.KEYS_TO_PRESERVE).then(() => {
+                                        Onyx.set(ONYXKEYS.HAS_RESET_OCCURRED_BEFORE, true);
                                        App.openApp();
                                    });

With that solution, we need backend support to store the key by account ID.

Solution 2

We should use the report name instead of the participant's name.

// .src/libs/ReportUtils.ts#L2681
- const reportOwnerDisplayName = getDisplayNameForParticipant(ownerAccountID) || login || report?.reportName;
+ const reportOwnerDisplayName = report?.reportName;