App icon indicating copy to clipboard operation
App copied to clipboard

[$250] LHN - Group chat disappears from the LHN with a split distance expense

Open vincdargento opened this issue 7 months ago • 70 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: v9.1.56-1 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/cases/view/3284939 Email or phone of affected tester (no customers): n/a Issue reported by: Applause Internal Team Device used: Mac 15.4.1/Safari, Desktop, iPhone 13 iOS 18.4.1 Safari, Hybrid App Component: Left Hand Navigation (LHN)

Action Performed:

  1. Navigate to staging.new.expensify.com
  2. Go to the account settings, preferences, priority mode, and choose most recent
  3. Click FAB (Green + button)
  4. Click Start Chat
  5. Add 2 other user to group
  6. Click Next
  7. Click Start Group
  8. Click + icon
  9. Click Split expense
  10. Select Distance and finish the flow
  11. Open a different chat

Expected Result:

Group chat stays in the LHN with a split distance expense

Actual Result:

Group chat disappears from the LHN with a split distance expense

RCA:

Root cause explained here

Workaround:

Unknown

Platforms:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [x] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome / Safari
  • [x] MacOS: Desktop

Screenshots/Videos

https://github.com/user-attachments/assets/a534fcd4-c54a-49e8-bef5-ec68af9821eb

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021929931002972853372
  • Upwork Job ID: 1929931002972853372
  • Last Price Increase: 2025-06-03
  • Automatic offers:
    • QichenZhu | Reviewer | 107616569
    • truph01 | Contributor | 107616572
Issue OwnerCurrent Issue Owner: @neil-marcellini

vincdargento avatar Jun 03 '25 14:06 vincdargento

Triggered auto assignment to @Christinadobrzyn (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.

melvin-bot[bot] avatar Jun 03 '25 14:06 melvin-bot[bot]

issue is reproducible. Will this be added to "external help" label for external contributors to fix ?

vishalPwc avatar Jun 03 '25 15:06 vishalPwc

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

melvin-bot[bot] avatar Jun 03 '25 15:06 melvin-bot[bot]

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

melvin-bot[bot] avatar Jun 03 '25 15:06 melvin-bot[bot]

@vishalPwc Thanks! Yes, I've added the External label. I believe this can be fixed externally, but @QichenZhu please let us know if this needs to be internal.

Christinadobrzyn avatar Jun 03 '25 16:06 Christinadobrzyn

@Christinadobrzyn I'm taking a look at it now.

AlexJuarez avatar Jun 03 '25 16:06 AlexJuarez

Proposal

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

  • Group chat disappears from the LHN with a split distance expense

What is the root cause of that problem?

  • When creating split expense, we already have logic which set the notification preference to always: https://github.com/Expensify/App/blob/ab1c0b3ce3d85517121637fb66ab6a55af9a9cff/src/libs/actions/IOU.ts#L5951-L5953

But in case of this bug, the condition doesn't match because the preference notification returned in getReportNotificationPreference(splitChatReport) is "".

  • As a result, the notification preference isn't set to always, so the chat will be disappeared from LHN when we switch the chat. The bug is gone after the SplitBill API is called successfully.

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

  • We can update: https://github.com/Expensify/App/blob/ab1c0b3ce3d85517121637fb66ab6a55af9a9cff/src/libs/actions/IOU.ts#L5951
    if (
        splitChatReport.participants &&
        (getReportNotificationPreference(splitChatReport) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN || !getReportNotificationPreference(splitChatReport))
    ) {

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

  • Add test for getReportNotificationPreference function if we use alternative solution

What alternative solutions did you explore? (Optional)

  • We can update: https://github.com/Expensify/App/blob/7766f89fb5e13aaa5501fc720526a2cc002156b8/src/libs/ReportUtils.ts#L1724

to:

    return participant?.notificationPreference || CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;

truph01 avatar Jun 03 '25 17:06 truph01

@Christinadobrzyn @vincdargento @QichenZhu this issue has some contradiction from the past, so lets clarify it further. This issue is not related to time expenses but group chats are disappearing because of following :

  1. there is no action like new message or any activity on chat which marks the notification preferrences to hidden
  2. after sending a message in group chat & removing the last message. will change the notificationpreferences from hidden to always and will not change to hidden after the deletion of message.

This is the expected behavior as contradicting issue was fixed in month of April 2025. Please check https://github.com/Expensify/App/issues/53496

Do let us know if this is valid, I can provide the proposal to get this fixed based on the clarification.

vishalPwc avatar Jun 03 '25 18:06 vishalPwc

@Christinadobrzyn @vincdargento @QichenZhu any views on last comment ?

vishalPwc avatar Jun 04 '25 18:06 vishalPwc

@truph01 thanks for the proposal. I'll review it today.

QichenZhu avatar Jun 04 '25 21:06 QichenZhu

@vishalPwc thanks for the comment. How does that issue relate to this? In that issue, the group chat is empty, while in this issue, the chat includes an expense.

QichenZhu avatar Jun 04 '25 22:06 QichenZhu

Thanks for clarification @QichenZhu. That makes more sense now. I missed that part when I was trying to reproduce the issue and bumped into #53496.

vishalPwc avatar Jun 05 '25 00:06 vishalPwc

@truph01 any idea why notificationPreference is an empty string? The type says it can't be, so we probably never considered this case. Should we fix the type definition as well?

https://github.com/Expensify/App/blob/0312361437de79bf95766669b58d06ef7dd457ed/src/types/onyx/Report.ts#L9

https://github.com/Expensify/App/blob/0312361437de79bf95766669b58d06ef7dd457ed/src/CONST.ts#L1532-L1537

QichenZhu avatar Jun 05 '25 12:06 QichenZhu

any idea why notificationPreference is an empty string

@QichenZhu It is returned by BE when we create a group chat. I think we can combine the fix on both BE and FE sides. As I suggested in the alternative solution, we should update this function to consider that case the value is empty string: https://github.com/Expensify/App/blob/7766f89fb5e13aaa5501fc720526a2cc002156b8/src/libs/ReportUtils.ts#L1722

truph01 avatar Jun 05 '25 12:06 truph01

@truph01 thanks for the info. Unfortunately, neither the main nor the alternative solutions work for me. Can you try switching between chats and refreshing the page to see if the chat is still there?

QichenZhu avatar Jun 05 '25 13:06 QichenZhu

@QichenZhu Could you share the video from your side? I tested my alternative solution and it works well:

https://github.com/user-attachments/assets/194e4288-bcf5-417a-8846-d9970530794b

truph01 avatar Jun 05 '25 15:06 truph01

@truph01 I tested the alternative again but it still doesn't work for me. Could you check if you have any other local changes not in the proposal?

https://github.com/user-attachments/assets/2804d45c-4870-4788-8b82-a058dd9cac70

QichenZhu avatar Jun 06 '25 03:06 QichenZhu

@QichenZhu In your video, I noticed that switching between reports works as expected, which is great.

However, in the end of video, it looked like the group chat disappeared from the LHN. Could you help confirm whether the group chat is actually being removed from the LHN, or if it has just been pushed to the bottom and requires scrolling to be visible?

truph01 avatar Jun 06 '25 07:06 truph01

@truph01 I tested with a new account that only has a few chats, and the group chat still disappears, as shown in the video.

I saw you split a manual expense in your video. Could you try a distance expense instead?

https://github.com/user-attachments/assets/ad9323b2-4046-48b3-a469-a50e880cfa4b

QichenZhu avatar Jun 06 '25 12:06 QichenZhu

@QichenZhu Ah, I see what’s happening now. My solution does work initially—the notification is optimistically set to always when the split expense is created. However, once the backend responds, it sets the notification value back to an empty string (""), which causes the bug to reappear. So it looks like we need to fix this on both the backend and frontend to ensure consistency.

Refer to my comment:

@QichenZhu In your video, I noticed that switching between reports works as expected, which is great.

That behavior occurs while the API call is still in progress.

However, in the end of the video, it looked like the group chat disappeared from the LHN

That happens after the API call completes successfully—when the backend response resets the notification, causing the issue.

truph01 avatar Jun 06 '25 16:06 truph01

@truph01's proposal and comment make sense to me. We need both backend and frontend fixes.

Backend

Could CreateDistanceRequest return notificationPreference: "always", like SplitBill already does?

API Response
CreateDistanceRequest Image
SplitBill Image

Frontend

I prefer @truph01's main solution because it's consistent with the code below that treats null, undefined, and empty string as hidden, and it works better long term since we'll remove the hidden field entirely.

https://github.com/Expensify/App/blob/e1766ef329607a44d08fe805e22e11d26fab6f25/src/libs/ReportUtils.ts#L1819-L1821

https://github.com/Expensify/App/blob/e1766ef329607a44d08fe805e22e11d26fab6f25/src/libs/ReportUtils.ts#L1828-L1830

🎀👀🎀 C+ reviewed

QichenZhu avatar Jun 07 '25 09:06 QichenZhu

Triggered auto assignment to @neil-marcellini, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] avatar Jun 07 '25 09:06 melvin-bot[bot]

Not overdue, I will review very shortly.

neil-marcellini avatar Jun 09 '25 17:06 neil-marcellini

@Christinadobrzyn I'm not really sure this is a problem. The chat is read as soon as you view it. So why do we think it should stay in the LHN?

neil-marcellini avatar Jun 09 '25 17:06 neil-marcellini

@neil-marcellini Just to confirm: if a group chat has any message, it should remain visible in LHN even when the user switches to another chat—correct?

If so, this is expected behavior in the OP

truph01 avatar Jun 09 '25 17:06 truph01

I don't think that's how Focus Mode works, right? Focus Mode only shows the unread chats, and accounts use focus Mode by default. If this bug is specific to most recent mode, then the reproduction steps should include that.

Yes, I see that it's listed as the expected behavior in the issue description, but I don't think that's correct.

neil-marcellini avatar Jun 09 '25 17:06 neil-marcellini

I don't think that's how Focus Mode works, right? Focus Mode only shows the unread chats, and accounts use focus Mode by default. If this bug is specific to most recent mode, then the reproduction steps should include that.

Yes, based on the video in OP, I think the bug is related to "most recent" mode.

truph01 avatar Jun 09 '25 17:06 truph01

Ah, okay, I got it now. Thanks. I will update the steps to include that, and then review the proposal.

neil-marcellini avatar Jun 09 '25 17:06 neil-marcellini

@truph01 Would you please briefly explain in your proposal how the most recent mode works in regards to keeping chats in the left-hand navigation and how that relates to notification preferences? The proposal discusses the notification preferences, but I'm kind of missing that link about how it connects to whether the chat is shown or not.

neil-marcellini avatar Jun 09 '25 17:06 neil-marcellini

@neil-marcellini RCA:

  • When we create a new group chat, the report.participants data is something like:
{
    "14365522": {
        "notificationPreference": "",
        "role": "admin"
    },
    "20027530": {
        "notificationPreference": "",
        "role": "member"
    },
}

This if block is met: https://github.com/Expensify/App/blob/d58a8ae281acaacbb7e56e86ca0cc3661d97bbc3/src/libs/SidebarUtils.ts#L243-L245 So the newly created group will disappear from LHN by default unless it is the current viewing chat.

  • When we create a split distance expense in this group chat, this if block is expected to call to set the notification to always: https://github.com/Expensify/App/blob/ab1c0b3ce3d85517121637fb66ab6a55af9a9cff/src/libs/actions/IOU.ts#L5951-L5953

But in case of this bug, the condition doesn't match because the preference notification returned in getReportNotificationPreference(splitChatReport) is "".

  • As a result, the notification preference isn't set to always, so the chat will disappear from LHN when we switch the chat even when we sent a split expense.

truph01 avatar Jun 09 '25 18:06 truph01