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-08-01] [$250] Invoice - Invoice thread opens when starting DM with the user after sending invoice to them #45187

Closed
6 tasks done
lanitochka17 opened this issue Jul 10, 2024 · 25 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

@lanitochka17
Copy link

lanitochka17 commented Jul 10, 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: 9.0.6-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: N/A
Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to FAB > Send invoice
  3. Enter amount and select any receiver
  4. Go to FAB > Start chat > Chat
  5. Scroll down and click on the same user in Step 3 (invoice receiver)

Expected Result:

DM with the user will open

Actual Result:

Invoice thread with the user opens

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

Add any screenshot/video evidence

Bug6538039_1720625521824.20240710_232325.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0165c9231ff254ae89
  • Upwork Job ID: 1811427918558506425
  • Last Price Increase: 2024-07-11
  • Automatic offers:
    • rayane-djouah | Reviewer | 103140621
Issue OwnerCurrent Issue Owner: @trjExpensify
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 10, 2024
Copy link

melvin-bot bot commented Jul 10, 2024

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

@lanitochka17
Copy link
Author

@trjExpensify 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

@bernhardoj
Copy link
Contributor

Proposal

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

An invoice thread opens when we select the user from new chat page.

What is the root cause of that problem?

When we select a user, it will try to find the user chat by participants using getChatByParticipants.

App/src/libs/ReportUtils.ts

Lines 5561 to 5584 in a19ef98

function getChatByParticipants(newParticipantList: number[], reports: OnyxCollection<Report> = ReportConnection.getAllReports(), shouldIncludeGroupChats = false): OnyxEntry<Report> {
const sortedNewParticipantList = newParticipantList.sort();
return Object.values(reports ?? {}).find((report) => {
const participantAccountIDs = Object.keys(report?.participants ?? {});
// If the report has been deleted, or there are no participants (like an empty #admins room) then skip it
if (
participantAccountIDs.length === 0 ||
isChatThread(report) ||
isTaskReport(report) ||
isMoneyRequestReport(report) ||
isChatRoom(report) ||
isPolicyExpenseChat(report) ||
(isGroupChat(report) && !shouldIncludeGroupChats)
) {
return false;
}
const sortedParticipantsAccountIDs = participantAccountIDs.map(Number).sort();
// Only return the chat if it has all the participants
return lodashIsEqual(sortedNewParticipantList, sortedParticipantsAccountIDs);
});
}

The participants of the invoice report is the same as the DM participants, that is [currentUser, the other user]. Because they contains the same participant, getChatByParticipants has a chance to wrongly returns the wrong report, that is the invoice report instead of the DM.

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

Skip invoice report/room when comparing the participant.

App/src/libs/ReportUtils.ts

Lines 5567 to 5577 in a19ef98

if (
participantAccountIDs.length === 0 ||
isChatThread(report) ||
isTaskReport(report) ||
isMoneyRequestReport(report) ||
isChatRoom(report) ||
isPolicyExpenseChat(report) ||
(isGroupChat(report) && !shouldIncludeGroupChats)
) {
return false;
}

|| isInvoiceReport(report) || isInvoiceRoom(report)

(and any other report type if needed)

What alternative solutions did you explore? (Optional)

I want to propose using !isOneOnOneChat, but getChatByParticipants is also being used to find group chat in split bill.

App/src/libs/actions/IOU.ts

Lines 3806 to 3809 in a19ef98

const allParticipantsAccountIDs = [...participantAccountIDs, currentUserAccountID];
if (!existingSplitChatReport) {
existingSplitChatReport = ReportUtils.getChatByParticipants(allParticipantsAccountIDs, undefined, participantAccountIDs.length > 1);
}

So, the solution is if we aren't searching for group, then we use !isOneOnOneChat(report) condition.

|| (!shouldIncludeGroupChats && !isOneOnOneChat(report))

Then, we can remove the other checks (thread, group, task, etc.)

@trjExpensify
Copy link
Contributor

@cristipaval @davidcardoza for eyes on this.

@trjExpensify trjExpensify added the External Added to denote the issue can be worked on by a contributor label Jul 11, 2024
@melvin-bot melvin-bot bot changed the title Invoice - Invoice thread opens when starting DM with the user after sending invoice to them [$250] Invoice - Invoice thread opens when starting DM with the user after sending invoice to them Jul 11, 2024
Copy link

melvin-bot bot commented Jul 11, 2024

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

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

melvin-bot bot commented Jul 11, 2024

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

@nkdengineer
Copy link
Contributor

Proposal

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

Invoice - Invoice thread opens when starting DM with the user after sending invoice to them

What is the root cause of that problem?

When we start DM with the user, we use getChatByParticipants function to find the report of the DM chat. In this function, we will exclude some types of reports and then compare the participants. But we don't exclude the invoice report and this report has the same participant with the DM chat. So sometimes this function can return wrongly if we find the invoice report first.

App/src/libs/ReportUtils.ts

Lines 5544 to 5549 in 77d95c5

if (
participantAccountIDs.length === 0 ||
isChatThread(report) ||
isTaskReport(report) ||
isMoneyRequestReport(report) ||
isChatRoom(report) ||

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

To avoid this bug happening in the future, we can prioritize the one one chat and group chat. With this change, we can make sure that this function will always return the DM or group first if the participant is matched.

return lodashOrderBy(Object.values(reports ?? {}), (report) => {
    if (isOneOnOneChat(report) || (isGroupChat(report) && shouldIncludeGroupChats)) {
        return 0;
    }
    return 1;
}).find((report) => {

return Object.values(reports ?? {}).find((report) => {

What alternative solutions did you explore? (Optional)

@melvin-bot melvin-bot bot added the Overdue label Jul 15, 2024
@rayane-djouah
Copy link
Contributor

Reviewing proposals

@melvin-bot melvin-bot bot removed the Overdue label Jul 15, 2024
@rayane-djouah
Copy link
Contributor

@bernhardoj's proposal looks good to me.

🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Jul 16, 2024

Triggered auto assignment to @cristipaval, 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 Jul 16, 2024
Copy link

melvin-bot bot commented Jul 16, 2024

📣 @rayane-djouah 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@bernhardoj
Copy link
Contributor

PR is ready

cc: @rayane-djouah

@trjExpensify
Copy link
Contributor

Deployed to staging 4 hours ago.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Jul 25, 2024
@melvin-bot melvin-bot bot changed the title [$250] Invoice - Invoice thread opens when starting DM with the user after sending invoice to them [HOLD for payment 2024-08-01] [$250] Invoice - Invoice thread opens when starting DM with the user after sending invoice to them Jul 25, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jul 25, 2024
Copy link

melvin-bot bot commented Jul 25, 2024

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

Copy link

melvin-bot bot commented Jul 25, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.11-5 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-08-01. 🎊

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

Copy link

melvin-bot bot commented Jul 25, 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:

  • [@rayane-djouah] The PR that introduced the bug has been identified. Link to the PR:
  • [@rayane-djouah] 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:
  • [@rayane-djouah] 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:
  • [@rayane-djouah] Determine if we should create a regression test for this bug.
  • [@rayane-djouah] 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.
  • [@trjExpensify] 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 Overdue and removed Weekly KSv2 labels Jul 31, 2024
@trjExpensify
Copy link
Contributor

Checklist time!

@melvin-bot melvin-bot bot removed the Overdue label Aug 2, 2024
@bernhardoj
Copy link
Contributor

Requested in ND

@rayane-djouah
Copy link
Contributor

rayane-djouah commented Aug 2, 2024

  • The PR that introduced the bug has been identified. Link to the PR: Implement Invoice rooms with individual receivers #40303
  • 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: Implement Invoice rooms with individual receivers #40303 (comment)
  • 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: N/A
  • Determine if we should create a regression test for this bug. There's no need; we've already included automated tests.
  • 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. N/A

cc @trjExpensify

@melvin-bot melvin-bot bot added the Overdue label Aug 5, 2024
@trjExpensify
Copy link
Contributor

Determine if we should create a regression test for this bug. There's no need; we've already included automated tests.

Hm, I don't think we forgo manual regression testing of features in lieu of automated tests. @cristipaval @davidcardoza are manual regression tests being handed over and added centrally for this project?

@melvin-bot melvin-bot bot removed the Overdue label Aug 5, 2024
@trjExpensify
Copy link
Contributor

Payment summary as follows:

@trjExpensify
Copy link
Contributor

^^ going to hold on the Upwork payment for C+ until we're aligned on this Q.

@rayane-djouah
Copy link
Contributor

@trjExpensify - Below are the manual regression test steps if we decide to include them:

Regression Test Proposal

  • Send Invoice flow:
  1. Create a New Account
  2. Click on the Floating Action Button (FAB).
  3. Select "Send Invoice".
  4. Choose a recipient with whom you have no prior interactions.
  5. Complete the invoice details and send it.
  6. Click on FAB again.
  7. Choose "Start Chat".
  8. Select the same recipient as in Step 4.
  9. Verify that the chat that opens should be a direct message (DM) chat, not the invoice report chat.
  • Submit expense flow:
  1. Create a New Account
  2. Click on the Floating Action Button (FAB).
  3. Select "Submit expense".
  4. Choose a recipient with whom you have no prior interactions.
  5. Complete the expense details and send it.
  6. Click on FAB again.
  7. Choose "Start Chat".
  8. Select the same recipient as in Step 4.
  9. Verify that the chat that opens should be a direct message (DM) chat, not the expense report chat.

Do we agree 👍 or 👎

@trjExpensify
Copy link
Contributor

Cool, thanks! Settled up. 👍

@JmillsExpensify
Copy link

$250 approved for @bernhardoj

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
Status: Done
Development

No branches or pull requests

7 participants