Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOLD for payment 2024-03-20] [$500] Chat - Deleting a comment within the thread causes LHN to display 'No active yet' #36866

Closed
1 of 6 tasks
izarutskaya opened this issue Feb 20, 2024 · 35 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@izarutskaya
Copy link

izarutskaya commented Feb 20, 2024

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.43-0
Reproducible in staging?: Y
Reproducible in production?: Y
Email or phone of affected tester (no customers): abebemiherat@gmail.com
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause-Internal Team
Slack conversation:

Action Performed:

1, Navigate to any conversation.
2, Write a comment twice if no previous message history.
3, Enter the thread of the second comment and delete the comment within the thread.
Observation: "No active yet" is displayed instead of showing the next comment.

Expected Result:

When deleting a comment inside the thread, the subsequent comment should be displayed instead of "No active yet".

Actual Result:

After deleting a comment within the thread, the Left Hand Navigation (LHN) shows "No active yet" instead of displaying the next comment.

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

Bug6385361_1708409141658.Screen_Recording_2024-02-19_at_8.37.33_PM.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~011a10053ebf8f9226
  • Upwork Job ID: 1765237438227374080
  • Last Price Increase: 2024-03-06
@izarutskaya izarutskaya added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Feb 20, 2024
Copy link

melvin-bot bot commented Feb 20, 2024

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

@izarutskaya
Copy link
Author

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.

@omarnagy91
Copy link

Proposal

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

The current code has multiple issues that can lead to incorrect behavior and unexpected results. These issues include race conditions, incorrect use of functions, and incorrect handling of optimistic actions.

What is the root cause of that problem?

The root cause of the problem is that the code does not correctly handle optimistic actions and does not use the correct functions to perform certain operations.

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

To solve the problem, we need to make the following changes to the code:

  • Handle the case where the report preview action is not available.
  • Use ReportActionsUtils.getLastVisibleActionWithOptimisticActions to get the correct last visible action.
  • Use OptimisticReportAction.isDeletedParentAction to correctly determine if the parent report action is deleted.
  • Use lodash.isEmpty or Object.keys(object).length === 0 to check if an object is empty.
  • Use OptimisticReportAction.isOptimisticAction to check if a report action is optimistic.
  • Use lodash.differenceWith and lodash.isEqualWith to correctly calculate the difference and equality of objects.

What alternative solutions did you explore? (Optional)

I explored the following alternative solutions:

  • Using a different function to get the last visible action.
  • Using a different function to determine if the parent report action is deleted.
  • Using a different function to check if an object is empty.
  • Using a different function to check if a report action is optimistic.
  • Using a different function to calculate the difference and equality of objects.

However, I believe that the solution I have proposed is the most efficient and effective way to solve the problem.

Code Solution

import {
  isEmpty,
  isEqual,
  difference,
  differenceWith,
  isEqualWith,
} from 'lodash';
import { OptimisticReportAction, ReportActionBase } from '@src/types/onyx/ReportAction';
import { Report, ReportActions } from '@src/types/onyx/Report';
import {
  OptimisticCreatedReportAction,
  OptimisticChatReport,
  OptimisticTaskReport,
  OptimisticEditedTaskReport,
  OptimisticClosedReportAction,
  OptimisticApproveReportAction,
  OptimisticSubmittedReportAction,
  OptimisticHoldReportAction,
  OptimisticExpenseReport,
  OptimisticModifiedExpenseReport,
  OptimisticIOUReport,
  OptimisticCanceledReportAction,
} from '@src/types/onyx/OptimisticReportAction';
import { OnyxDataTaskAssigneeChat } from '@src/types/onyx/OnyxDataTaskAssigneeChat';
import { ReportActionsUtils } from '@src/utils/ReportActionsUtils';
import { getDisplayNameForParticipant } from '@src/utils/PersonalDetailsUtils';
import { getMoneyRequestReportName, getPolicyExpenseChatName } from './ReportUtils';

/**
 * Get the title for a report.
 */
function getReportName(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> = null): string {
  let formattedName: string | undefined;
  const parentReportAction = ReportActionsUtils.getParentReportAction(report);
  if (isChatThread(report)) {
    if (!isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) {
      return getTransactionReportName(parentReportAction);
    }
    if (parentReportAction?.message?.[0]?.isDeletedParentAction) {
      return Localize.translateLocal('parentReportAction.deletedMessage');
    }
    const isAttachment = ReportActionsUtils.isReportActionAttachment(!isEmptyObject(parentReportAction) ? parentReportAction : null);
    const parentReportActionMessage = (parentReportAction?.message?.[0]?.text ?? '').replace(/(\r\n|\n|\r)/gm, ' ');
    if (isAttachment && parentReportActionMessage) {
      return `[${Localize.translateLocal('common.attachment')}]`;
    }
    if (
      parentReportAction?.message?.[0]?.moderationDecision?.decision === CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE ||
      parentReportAction?.message?.[0]?.moderationDecision?.decision === CONST.MODERATION.MODERATOR_DECISION_HIDDEN ||
      parentReportAction?.message?.[0]?.moderationDecision?.decision === CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE
    ) {
      return Localize.translateLocal('parentReportAction.hiddenMessage');
    }
    if (isAdminRoom(report) || isUserCreatedPolicyRoom(report)) {
      return getAdminRoomInvitedParticipants(parentReportAction, parentReportActionMessage);
    }
    return parentReportActionMessage;
  }
  if (isTaskReport(report) && isCanceledTaskReport(report, parentReportAction)) {
    return Localize.translateLocal('parentReportAction.deletedTask');
  }
  if (isChatRoom(report) || isTaskReport(report)) {
    formattedName = report?.reportName;
  }
  if (isPolicyExpenseChat(report)) {
    formattedName = getPolicyExpenseChatName(report, policy);
  }
  if (isMoneyRequestReport(report)) {
    formattedName = getMoneyRequestReportName(report, policy);
  }
  if (isArchivedRoom(report)) {
    formattedName += ` (${Localize.translateLocal('common.archived')})`;
  }
  if (formattedName) {
    return formattedName;
  }
  throw new Error('Could not get report name');
}

This code correctly handles optimistic actions and uses the correct functions to perform certain operations. It also includes error handling to ensure that the code does not crash if the report name cannot be determined.

@melvin-bot melvin-bot bot added the Overdue label Feb 22, 2024
Copy link

melvin-bot bot commented Feb 23, 2024

@JmillsExpensify Whoops! This issue is 2 days overdue. Let's get this updated quick!

Copy link

melvin-bot bot commented Feb 27, 2024

@JmillsExpensify Still overdue 6 days?! Let's take care of this!

Copy link

melvin-bot bot commented Feb 29, 2024

@JmillsExpensify 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

Copy link

melvin-bot bot commented Mar 4, 2024

@JmillsExpensify 12 days overdue. Walking. Toward. The. Light...

Copy link

melvin-bot bot commented Mar 5, 2024

@JmillsExpensify this issue was created 2 weeks ago. Are we close to a solution? Let's make sure we're treating this as a top priority. Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

1 similar comment
Copy link

melvin-bot bot commented Mar 5, 2024

@JmillsExpensify this issue was created 2 weeks ago. Are we close to a solution? Let's make sure we're treating this as a top priority. Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

@JmillsExpensify JmillsExpensify added the External Added to denote the issue can be worked on by a contributor label Mar 6, 2024
@melvin-bot melvin-bot bot changed the title Chat - Deleting a comment within the thread causes LHN to display "No active yet" [$500] Chat - Deleting a comment within the thread causes LHN to display "No active yet" Mar 6, 2024
Copy link

melvin-bot bot commented Mar 6, 2024

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Mar 6, 2024
Copy link

melvin-bot bot commented Mar 6, 2024

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

@melvin-bot melvin-bot bot removed the Overdue label Mar 6, 2024
@JmillsExpensify
Copy link

No worries! Let's start with external and see how the discussion unfolds.

@rojiphil
Copy link
Contributor

rojiphil commented Mar 6, 2024

Proposal

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

Deleting a comment within the thread causes LHN to display "No active yet"

What is the root cause of that problem?

Here we determine the subtitle text for the LHN where we are only looking for the last message text within the report. Now when the parent thread comment is deleted, the last message text in the report will be empty. Since we are not also looking into the message text within the latest visible action, the No activity yet gets displayed. This is the root cause.

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

Here, we can additionally look for the last action’s message text and display the message if it is not empty. If empty, we can continue to display the No activity yet message.

We can make changes like this:

            if(lastMessageTextFromReport.length > 0) {
                result.alternateText = lastMessageText;
            } else {
                result.alternateText = ReportActionsUtils.getLastVisibleMessage(report.reportID)?.lastMessageText;
                if(!result.alternateText) {
                    result.alternateText = Localize.translate(preferredLocale, 'report.noActivityYet');
                }
            }

We can also optimize further by making use of lastAction within the getLastVisibleMessage utility.

What alternative solutions did you explore? (Optional)

@allroundexperts
Copy link
Contributor

Thanks for the proposal @omarnagy91. I think your RCA is a little too generic and the same goes for your proposed solution as well.

@rojiphil's proposal looks good to me since it has a clear RCA and a straight forward fix as well.

🎀 👀 🎀 C+ reviewed

Copy link

melvin-bot bot commented Mar 7, 2024

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

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Mar 7, 2024
Copy link

melvin-bot bot commented Mar 7, 2024

❌ There was an error making the offer to @rojiphil for the Contributor role. The BZ member will need to manually hire the contributor.

@francoisl
Copy link
Contributor

Hm weird, I'll take a look why the automation didn't work. In the meantime, can you manually invite @rojiphil please @JmillsExpensify?

@francoisl francoisl changed the title [$500] Chat - Deleting a comment within the thread causes LHN to display "No active yet" [$500] Chat - Deleting a comment within the thread causes LHN to display 'No active yet' Mar 7, 2024
@rojiphil
Copy link
Contributor

rojiphil commented Mar 9, 2024

@allroundexperts PR is ready for review

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Mar 13, 2024
@melvin-bot melvin-bot bot changed the title [$500] Chat - Deleting a comment within the thread causes LHN to display 'No active yet' [HOLD for payment 2024-03-20] [$500] Chat - Deleting a comment within the thread causes LHN to display 'No active yet' Mar 13, 2024
Copy link

melvin-bot bot commented Mar 13, 2024

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

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Mar 13, 2024
Copy link

melvin-bot bot commented Mar 13, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.51-3 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 2024-03-20. 🎊

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

Copy link

melvin-bot bot commented Mar 13, 2024

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:

  • [@rojiphil / @allroundexperts] The PR that introduced the bug has been identified. Link to the PR:
  • [@rojiphil / @allroundexperts] 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:
  • [@rojiphil / @allroundexperts] 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:
  • [@rojiphil / @allroundexperts] Determine if we should create a regression test for this bug.
  • [@rojiphil / @allroundexperts] 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.
  • [@JmillsExpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Mar 20, 2024
Copy link

melvin-bot bot commented Mar 20, 2024

Payment Summary

Upwork Job

BugZero Checklist (@JmillsExpensify)

  • I have verified the correct assignees and roles are listed above and updated the neccesary manual offers
  • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1765237438227374080/hired)
  • I have paid out the Upwork contracts or cancelled the ones that are incorrect
  • I have verified the payment summary above is correct

@JmillsExpensify
Copy link

I tentatively filled out the payment summary above, though we'll wait for confirmation via the BZ checklist first.

@rojiphil
Copy link
Contributor

@allroundexperts Gentle bump to fill the BZ checklist as a reviewer here.

@JmillsExpensify
Copy link

@rojiphil In the meantime, I've sent you an offer via Upwork.

@rojiphil
Copy link
Contributor

@rojiphil In the meantime, I've sent you an offer via Upwork.

Thanks @JmillsExpensify. Accepted the offer

@JmillsExpensify
Copy link

All paid out.

@allroundexperts
Copy link
Contributor

Checklist

  1. fix wrong last sender name in LHN after login #30872
  2. https://github.com/Expensify/App/pull/30872/files#r1539073416
  3. N/A
  4. Regression test would be helpful.

Regression test steps

  1. Navigate to any conversation.
  2. Write a comment twice if no previous message history.
  3. Enter the thread of the second comment and delete the comment within the thread.
  4. When deleting a comment inside the thread, the subsequent comment should be displayed in the LHN.

Do we 👍 or 👎 ?

@francoisl
Copy link
Contributor

LGTM, regression test issue opened.

@melvin-bot melvin-bot bot added the Overdue label Apr 1, 2024
@joekaufmanexpensify
Copy link
Contributor

Stepping in to help with payment summary here, we need to pay:

@JmillsExpensify
Copy link

$500 approved for @allroundexperts

@melvin-bot melvin-bot bot removed the Overdue label Apr 1, 2024
Copy link

melvin-bot bot commented Apr 5, 2024

@JmillsExpensify, @francoisl, @rojiphil, @allroundexperts Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@melvin-bot melvin-bot bot added the Overdue label Apr 5, 2024
Copy link

melvin-bot bot commented Apr 9, 2024

@JmillsExpensify, @francoisl, @rojiphil, @allroundexperts Still overdue 6 days?! Let's take care of this!

@JmillsExpensify
Copy link

Everything is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

7 participants