Skip to content

[HOLD for payment 2023-12-29] [$500] Chat–Name of message owner disappears from DM for a second when delete first message in Offline #32101

Closed

Description

@izarutskaya

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: v1.4.4-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause-Internal Team
Slack conversation: @

Action Performed:

  1. Go to https://staging.new.expensify.com/
  2. Log in with any account.
  3. Disable the internet connection in the main testing device
  4. Choose the first of several messages you already sent back-to-back
  5. Verify the chat header with your name appears only on your first message
  6. Hover over that first message to view the action menu
  7. Click/Tap on the Trash icon to delete the message
  8. Go Online

Expected Result:

The message has been deleted

Actual Result:

The name of the message owner disappears from conversation for a second when delete first message in Offline and go back to Online.

Workaround:

Unknown

Platforms:

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

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6292645_1701145916396.The_name_of_the_message_owner_disappears.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~012bb87b742d38cd4b
  • Upwork Job ID: 1729458938833915904
  • Last Price Increase: 2023-11-28
  • Automatic offers:
    • shubham1206agra | Contributor | 28062142
    • tienifr | Contributor | 28062150
Issue OwnerCurrent Issue Owner: @kevinksullivan

Activity

  1. added
    External
    Daily
    Bug
    on Nov 28, 2023
  2. changed the title [-]Chat–Name of message owner disappears from DM for a second when delete first message in Offline[/-] [+][$500] Chat–Name of message owner disappears from DM for a second when delete first message in Offline[/+] on Nov 28, 2023
  3. melvin-bot commented on Nov 28, 2023

    @melvin-bot
  4. melvin-bot commented on Nov 28, 2023

    @melvin-bot

    Triggered auto assignment to @kevinksullivan (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

  5. added
    Help Wanted
    on Nov 28, 2023
  6. melvin-bot commented on Nov 28, 2023

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  7. melvin-bot commented on Nov 28, 2023

    @melvin-bot

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

  8. AmjedNazzal commented on Nov 28, 2023

    @AmjedNazzal
    Contributor

    @izarutskaya Can you please check the screenshots/videos section, it seemed to have not uploaded correctly.

  9. bernhardoj commented on Nov 28, 2023

    @bernhardoj
    Contributor

    Proposal

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

    When we send a message, it will show who sent it, and if we send another message within 5 minutes, it will be grouped and the 2nd (or later) message won't show who sent it anymore. If we delete the first message that has that info while offline, coming back offline makes it disappears along with the first message.

    What is the root cause of that problem?

    The logic to decide whether to show the user info is coming from ReportActionsUtils.isConsecutiveActionMadeByPreviousActor which will check the current and previous action sent time difference.

    displayAsGroup={ReportActionsUtils.isConsecutiveActionMadeByPreviousActor(sortedReportActions, index)}

    // Comments are only grouped if they happen within 5 minutes of each other
    if (new Date(currentAction.created).getTime() - new Date(previousAction.created).getTime() > 300000) {
    return false;
    }

    When we go online, the first message that we optimistically delete disappears thanks to OfflineWithFeedback, but the first message report action object actually still exists (assuming the delete action API isn't complete yet) in the Onyx.

    So, when we compare the 2nd message with the 1st message sent time, it's obvious that the user info won't show. After the API completes, the 1st message is deleted from the Onyx and the 2nd message is now the 1st message and because the previous action is CREATED action, the user info is shown.

    But this is not the real root cause. If we see the logic on how we retrieve the previous action, we already skip any action that has a pending delete while ONLINE.

    function findPreviousAction(reportActions: ReportAction[] | null, actionIndex: number): OnyxEntry<ReportAction> {
    if (!reportActions) {
    return null;
    }
    for (let i = actionIndex + 1; i < reportActions.length; i++) {
    // Find the next non-pending deletion report action, as the pending delete action means that it is not displayed in the UI, but still is in the report actions list.
    // If we are offline, all actions are pending but shown in the UI, so we take the previous action, even if it is a delete.
    if (isNetworkOffline || reportActions[i].pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
    return reportActions[i];
    }
    }

    The problem is, that we memorized ReportActionsListItemRenderer

    export default memo(ReportActionsListItemRenderer);

    which only rerenders when the props change, but the network status (isNetworkOffline) is coming from the util file itself,

    let isNetworkOffline = false;
    Onyx.connect({
    key: ONYXKEYS.NETWORK,
    callback: (val) => (isNetworkOffline = val?.isOffline ?? false),
    });

    so even when the network status changes, the component won't rerender.

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

    Subscribe the network status in ReportActionsListItemRenderer and pass it to ReportActionsUtils.isConsecutiveActionMadeByPreviousActor > ReportActionsUtils.findPreviousAction.

    const {isOffline} = useNetwork();
    ReportActionsUtils.isConsecutiveActionMadeByPreviousActor(actions, index, isOffline);
    
  10. tienifr commented on Nov 28, 2023

    @tienifr
    Contributor

    Proposal

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

    Chat–Name of message owner disappears from DM for a second when delete first message in Offline

    What is the root cause of that problem?

    we decide to display the chat-name based on displayAsGroup here

    displayAsGroup={ReportActionsUtils.isConsecutiveActionMadeByPreviousActor(sortedReportActions, index)}

    in

    if (isNetworkOffline || reportActions[i].pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {

    we already have the logic to check isNetworkOffline, but isConsecutiveActionMadeByPreviousActor function is not called when the users go online because in ReportActionsListItemRenderer we did not listen for network change

    -> displayAsGroup is not updated immediately. When API DeleteComment calls successfully that makes sortedReportActions get changed -> ReportActionsListItemRenderer is re-rendered -> displayAsGroup is updated

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

    We don't need to pass whole sortedReportActions to ReportActionsListItemRenderer because this component is used to render only 1 item and we just need it to get displayAsGroup -> it can cause this component re-renders unexpectedly.

    Instead of that we should pass

    displayAsGroup={ReportActionsUtils.isConsecutiveActionMadeByPreviousActor(sortedReportActions, index)}
    

    in

    <ReportActionsListItemRenderer

    and remove this line

    sortedReportActions={sortedReportActions}

    then use displayAsGroup in here

    displayAsGroup={displayAsGroup}
    

    For now, we can make sure displayAsGroup will be updated after uses go online because we already listen for network change in ReportActionsList

    Result

    Screen.Recording.2023-11-28.at.23.39.15.mov
  11. Santhosh-Sellavel commented on Nov 29, 2023

    @Santhosh-Sellavel
    Collaborator

    @tienifr's proposal LGTM!
    C+ Reviewed
    🎀 👀 🎀

  12. 54 remaining items

  13. melvin-bot commented on Dec 22, 2023

    @melvin-bot

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    • [@shubham1206agra] The PR that introduced the bug has been identified. Link to the PR:
    • [@shubham1206agra] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
    • [@shubham1206agra] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
    • [@shubham1206agra] Determine if we should create a regression test for this bug.
    • [@shubham1206agra] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    • [@kevinksullivan] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  14. added
    Daily
    and removed
    Weekly
    on Dec 28, 2023
  15. melvin-bot commented on Jan 2, 2024

    @melvin-bot

    @Julesssss, @kevinksullivan, @shubham1206agra, @tienifr Huh... This is 4 days overdue. Who can take care of this?

  16. shubham1206agra commented on Jan 3, 2024

    @shubham1206agra
    Contributor

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    1. Go to App
    2. Send someone messages back-to-back.
    3. Disable the internet connection.
    4. Choose the first of several messages you already sent back-to-back
    5. Verify the chat header with your name appears only on your first message
    6. Hover over that first message to view the action menu
    7. Click/Tap on the Trash icon to delete the message
    8. Go Online
    • [@kevinksullivan] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  17. melvin-bot commented on Jan 4, 2024

    @melvin-bot

    @Julesssss, @kevinksullivan, @shubham1206agra, @tienifr Still overdue 6 days?! Let's take care of this!

  18. shubham1206agra commented on Jan 8, 2024

    @shubham1206agra
    Contributor

    @kevinksullivan Bump for the payment here

  19. melvin-bot commented on Jan 8, 2024

    @melvin-bot

    @Julesssss, @kevinksullivan, @shubham1206agra, @tienifr 10 days overdue. Is anyone even seeing these? Hello?

  20. Julesssss commented on Jan 8, 2024

    @Julesssss
    Contributor

    Not overdue, just awaiting payment

  21. melvin-bot commented on Jan 10, 2024

    @melvin-bot

    @Julesssss, @kevinksullivan, @shubham1206agra, @tienifr 12 days overdue. Walking. Toward. The. Light...

  22. Julesssss commented on Jan 12, 2024

    @Julesssss
    Contributor

    Waiting for payment

  23. kevinksullivan commented on Jan 12, 2024

    @kevinksullivan
    Contributor

    Thanks for your patience, everyone! Paid out.

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

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions