Skip to content

[Due for payment 2025-05-27] [$250] Chat - Unread marker displayed constantly on chat after keeping one duplicate expense. #58673

Closed

Description

@mitarachim

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.1.15-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Yes, reproducible on both
If this was caught during regression testing, add the test name, ID and link from TestRail: #58382
Email or phone of affected tester (no customers): ibellicotest+416@gmail.com
Issue reported by: Applause Internal Team
Device used: Motorola MotoG60 - Android 12 - Chrome / Windows 10 - Chrome
App Component: Chat Report View

Action Performed:

  1. Open the staging.new.expensify.com website.
  2. Open any workspace chat.
  3. Create two identical expenses.
  4. Open the expenses report.
  5. Tap on any of the two expenses.
  6. Dismiss the "Hold" modal.
  7. Tap on "Review duplicates" and "Keep this one" on any of the two expenses.
  8. Tap on "Confirm"
  9. Return to conversation.
  10. Note that now, an unread marker is displayed above expense report.
  11. Return to LHN and open chat again.
  12. Check if unread marker is still displayed.

Expected Result:

Unread marker shouldn´t appear on chat after keeping one of the duplicates expenses.

Actual Result:

Unread marker appears above expense report, after finishing the review duplicates process and keeping only one. Also, unread marker doesn´t disappear after closing and reopening chat. It remains constantly displayed.

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6774970_1742346365407.Dupe.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021904348606828653423
  • Upwork Job ID: 1904348606828653423
  • Last Price Increase: 2025-04-08
  • Automatic offers:
    • rohit9625 | Contributor | 106851623
Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @adelekennedy

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 19, 2025
  2. melvin-bot commented on Mar 19, 2025

    @melvin-bot

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

  3. rohit9625 commented on Mar 21, 2025

    @rohit9625
    Contributor

    I can see the unread marker just after creating two same expenses. Don't need to keep an expense.

  4. melvin-bot commented on Mar 24, 2025

    @melvin-bot

    @adelekennedy Eep! 4 days overdue now. Issues have feelings too...

  5. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Mar 25, 2025
  6. changed the title [-]Chat - Unread marker displayed constantly on chat after keeping one duplicate expense.[/-] [+][$250] Chat - Unread marker displayed constantly on chat after keeping one duplicate expense.[/+] on Mar 25, 2025
  7. melvin-bot commented on Mar 25, 2025

    @melvin-bot
  8. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Mar 25, 2025
  9. melvin-bot commented on Mar 25, 2025

    @melvin-bot

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

  10. rohit9625 commented on Mar 26, 2025

    @rohit9625
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-03-26 07:15:03 UTC.

    Proposal

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

    Chat - Unread marker displayed constantly on chat after keeping one duplicate expense. The unread marker also displayed constantly when we created an expense, switched to another report chats, and again opened the recently created expense report chats.

    What is the root cause of that problem?

    When we create an expense, we update the unreadMarkerTime at the below line when lastAction.created changes.

    setUnreadMarkerTime(mostRecentReportActionCreated);

    But we don't update the report.lastReadTime when any report action is created. That's why unreadMarker doesn't show up when we create an expense, but if we navigate to some other screen and again open the chat where we created Expense recently, then we can see the unreadMarker constantly. When keeping a duplicate expense, we eventually navigated to another screen.

    Before_Fix.mp4

    And when we returned to our current chat, the unreadMarkerTime was initialized with report.lastReadTime that wasn't updated previously.

    const reportLastReadTime = report.lastReadTime ?? '';
    /**
    * The timestamp for the unread marker.
    *
    * This should ONLY be updated when the user
    * - switches reports
    * - marks a message as read/unread
    * - reads a new message as it is received
    */
    const [unreadMarkerTime, setUnreadMarkerTime] = useState(reportLastReadTime);
    useEffect(() => {
    setUnreadMarkerTime(reportLastReadTime);
    // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
    }, [report.reportID]);

    Hence, resulting in isReportActionUnread() function returns true because the message.created time is recent but the unreadMarkerTime was initialized with the old report.lastReadTime:

    const isCurrentMessageUnread = isReportActionUnread(message, unreadMarkerTime);

    Above function implementation:

    /**
     * Note: Prefer `ReportActionsUtils.isCurrentActionUnread` over this method, if applicable.
     * Check whether a specific report action is unread.
     */
    function isReportActionUnread(reportAction: OnyxEntry<ReportAction>, lastReadTime?: string) {
        if (!lastReadTime) {
            return !isCreatedAction(reportAction);
        }
    
        return !!(reportAction && lastReadTime && reportAction.created && lastReadTime < reportAction.created);
    }

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

    We can update the report.lastReadTime by calling the readNewestAction function whenever the lastAction.created changes, i.e., a report action is created. However, we're already calling this function inside two effects as shown here:

    if (isUnread(report, transactionThreadReport)) {
    // On desktop, when the notification center is displayed, isVisible will return false.
    // Currently, there's no programmatic way to dismiss the notification center panel.
    // To handle this, we use the 'referrer' parameter to check if the current navigation is triggered from a notification.
    const isFromNotification = route?.params?.referrer === CONST.REFERRER.NOTIFICATION;
    if ((isVisible || isFromNotification) && scrollingVerticalOffset.current < CONST.REPORT.ACTIONS.ACTION_VISIBLE_THRESHOLD) {
    readNewestAction(report.reportID);
    if (isFromNotification) {
    Navigation.setParams({referrer: undefined});
    }
    } else {
    readActionSkipped.current = true;
    }
    }

    But, the isUnread function returns false when we create a report action because it compares lastReadTime < lastVisibleActionCreated and both are equal when we create an Expense Report. Hence, the readNewestAction function doesn't get called.

    We can refactor the if condition like this:

    // If the last action's created time < report's last read time, i.e., the last action created is unread then the condition will be true
    if (isUnread(report, transactionThreadReport) || isReportActionUnread(lastAction, report.lastReadTime)) 

    Results

    After_Fix.mp4

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

    We should write a test in the UnreadIndicatorsTest.tsx file to test behavior when creating an expense.

    What alternative solutions did you explore? (Optional)

    We can also update the report.lastReadTime by:

    1. Replace setUnreadMarkerTime with readNewestAction because the readNewestAction() function also updates unreadMarkerTime:
      setUnreadMarkerTime(mostRecentReportActionCreated);
    2. Creating a separate useEffect for this task:
        /*This useEffect reads the newest action and update report.lastReadTime when:
        * 1. When the report is opened
        * 2. When a new action is created
        */
       useEffect(() => {
    
        if ((isVisible || isFocused) && scrollingVerticalOffset.current < CONST.REPORT.ACTIONS.ACTION_VISIBLE_THRESHOLD) {
            readNewestAction(report.reportID);
        } else {
            readActionSkipped.current = true;
        }
        readNewestAction(report.reportID)
       }, [lastAction?.created, report.reportID, isVisible, isFocused])

    I would prefer refactoring the whole logic to show the unread marker because I think the code execution is pretty unpredictable right now. Refactoring it would ensure clean code and the desired behavior.

  11. 64 remaining items

  12. changed the title [-][$250] Chat - Unread marker displayed constantly on chat after keeping one duplicate expense.[/-] [+][Due for payment 2025-05-27] [$250] Chat - Unread marker displayed constantly on chat after keeping one duplicate expense.[/+] on May 20, 2025
  13. melvin-bot commented on May 20, 2025

    @melvin-bot

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

  14. melvin-bot commented on May 20, 2025

    @melvin-bot

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

    If no regressions arise, payment will be issued on 2025-05-27. 🎊

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

  15. melvin-bot commented on May 20, 2025

    @melvin-bot

    @Ollyws @adelekennedy @Ollyws The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  16. adelekennedy commented on May 27, 2025

    @adelekennedy
    Contributor

    payment time!

    Payment Summary

    Contributor: @rohit9625 paid $250 via Upwork
    Contributor+: @Ollyws due $250 via NewDot

  17. Ollyws commented on May 27, 2025

    @Ollyws
    Contributor

    Requested in ND.

  18. melvin-bot commented on Jun 2, 2025

    @melvin-bot

    @adelekennedy Huh... This is 4 days overdue. Who can take care of this?

  19. garrettmknight commented on Jun 3, 2025

    @garrettmknight
    Contributor

    $250 approved for @Ollyws

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions