Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.56k stars 2.9k forks source link

[$250] [HOLD for payment 2024-07-10] Split bill - New group is created when splitting bill with the same users #40579

Closed lanitochka17 closed 4 months ago

lanitochka17 commented 7 months ago

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: 1.4.63-7 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/4496719 Email or phone of affected tester (no customers): natnael.expensify+3@gmail.com Issue reported by: Applause - Internal Team

Action Performed:

  1. Click on FAB > and create a split bill with two new users
  2. Click on FAB > and create another split bill the same two users you have created with on step one

Expected Result:

New group shouldn't be created, and the split bill should be added to the existing group

Actual Result:

A second, new group is created

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/Expensify/App/assets/78819774/b4527362-dcdf-4103-b3f0-a566fba97660

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01c9e84f7fad619cd5
  • Upwork Job ID: 1811859168529416327
  • Last Price Increase: 2024-07-12
melvin-bot[bot] commented 7 months ago

Triggered auto assignment to @joekaufmanexpensify (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 commented 7 months ago

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

FitseTLT commented 7 months ago

Proposal

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

Split bill - New group is created when splitting bill with the same users

What is the root cause of that problem?

We are not checking if the group chat exists or not before creating here https://github.com/Expensify/App/blob/9b2c5187e2203d83bba50bfa66936691788cbd18/src/libs/actions/IOU.ts#L3104-L3119

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

We should check if it already exists in onyx

   if (participants.length > 1) {
        const existing = ReportUtils.getChatByParticipants(allParticipantsAccountIDs, undefined, true) ?? null;
        const splitChatReport =
            !existing &&
            ReportUtils.buildOptimisticChatReport(
                allParticipantsAccountIDs,
                '',
                CONST.REPORT.CHAT_TYPE.GROUP,
                undefined,
                undefined,
                undefined,
                undefined,
                undefined,
                undefined,
                CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
            );
        return {existingSplitChatReport: existing, splitChatReport: existing ?? splitChatReport};
    }

currently getChatByParticipants doesn't include group chats so we should update it to take a parameter includeGroupChats and pass as true here

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

What alternative solutions did you explore? (Optional)

Optonally we can update this line of code https://github.com/Expensify/App/blob/9b2c5187e2203d83bba50bfa66936691788cbd18/src/libs/actions/IOU.ts#L3088-L3092 to

if (!existingSplitChatReport) {
        existingSplitChatReport = ReportUtils.getChatByParticipants(
            [...participantAccountIDs, ...(participantAccountIDs.length > 1 ? [currentUserAccountID] : [])],
            undefined,
            participantAccountIDs.length > 1,
        );
    }
shahinyan11 commented 7 months ago

Proposal

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

Split bill - New group is created when splitting bill with the same users

What is the root cause of that problem?

New feature

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

Add below code above this line

const existingChatWithCurrentParticipants = ReportUtils.getChatByParticipants(participantAccountIDs)

if(!existingSplitChatReportID && !!existingChatWithCurrentParticipants){
    existingSplitChatReportID = existingChatWithCurrentParticipants.reportID
}

Update this line as follows getChatByParticipants(participants)?.reportID || ''

What alternative solutions did you explore? (Optional)

FitseTLT commented 7 months ago

Updated Only to add a refactored code for same solution

joekaufmanexpensify commented 7 months ago

I think this report is going to be obviated by a feature refactor we're working on. Discussing.

joekaufmanexpensify commented 6 months ago

Not overdue

joekaufmanexpensify commented 6 months ago

Bumped in slack

joekaufmanexpensify commented 6 months ago

Bumped 1:1

joekaufmanexpensify commented 6 months ago

Flagged again in Slack. This is definitely #vip-split related. But don't want to make external just yet since I feel like there is a solid chance we will close this.

youssef-lr commented 6 months ago

@joekaufmanexpensify I'll take a look at the proposals tomorrow.

joekaufmanexpensify commented 6 months ago

Great. TY!

joekaufmanexpensify commented 6 months ago

@youssef-lr is going to look at proposals

joekaufmanexpensify commented 6 months ago

Still pending

youssef-lr commented 6 months ago

I will get to this this week

joekaufmanexpensify commented 6 months ago

Great. TY!

melvin-bot[bot] commented 6 months ago

@youssef-lr @joekaufmanexpensify 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!

joekaufmanexpensify commented 6 months ago

@youssef-lr will you have a chance to circle back to this soon? If you think we should definitely change this behavior, also happy to assign a C+ so they do preliminary review for you

joekaufmanexpensify commented 6 months ago

@youssef-lr making this external for now so we can start to look at the proposals. When you have a sec, could you confirm if the solution in OP of the issue is what you wanted from the design doc?

melvin-bot[bot] commented 6 months ago

Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.

melvin-bot[bot] commented 6 months ago

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

Ollyws commented 6 months ago

I'm getting a different behaviour as described in the OP. Seems the split functionality has been moved to the FAB menu and following the steps from there results in:

Screenshot 2024-05-08 at 10 16 38

joekaufmanexpensify commented 6 months ago

@Ollyws yeah the split button did move to FAB, but I still get the same result when I try and reproduce. Splitting two expenses with the same two people creates a new group each time. Is that what you did to get that error?

tsa321 commented 6 months ago

Proposal

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

Split bill always making new report despite existing group chat with same paritcipants.

What is the root cause of that problem?

In here:

https://github.com/Expensify/App/blob/807c945ef8edabe86cc62f16c866aa754db8750b/src/libs/actions/IOU.ts#L3604-L3606

the ReportUtils.getChatByParticipants won't be called because shouldGetOrCreateOneOneDM will be false if number of participant of splited bill more than 2 (including user that make split bills). So shouldGetOrCreateOneOneDM will only be true if we split bills with exactly one other user. Then ReportUtils.getChatByParticipants won't be called and existingSplitChatReport will be undefined or null, then create new report in here:

https://github.com/Expensify/App/blob/807c945ef8edabe86cc62f16c866aa754db8750b/src/libs/actions/IOU.ts#L3620


and another problem if we disable shouldGetOrCreateOneOneDM check, and do getChatByParticipants, the call to the function isn't including self/current account id. so it just pass other participant without ownself/current user (user that create split bill):

https://github.com/Expensify/App/blob/807c945ef8edabe86cc62f16c866aa754db8750b/src/libs/actions/IOU.ts#L3606


and another problem in getChatByParticipants function:

https://github.com/Expensify/App/blob/807c945ef8edabe86cc62f16c866aa754db8750b/src/libs/ReportUtils.ts#L5151

it won't check on group report.

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

We need to add parameter currentUserAccountID if we use ReportUtils.getChatByParticipants and we need to investigate why the function won't search on groupChat:

https://github.com/Expensify/App/blob/807c945ef8edabe86cc62f16c866aa754db8750b/src/libs/ReportUtils.ts#L5151

if we can disable this check then we can use this function. If we cannot disable this check (because of regression if we disable it) then we can create new function getGroupChatByParticipants and use it in getOrCreateOptimisticSplitChatReport function instead of ReportUtils.getChatByParticipants.

Also we need to investigate why:

https://github.com/Expensify/App/blob/807c945ef8edabe86cc62f16c866aa754db8750b/src/libs/actions/IOU.ts#L3605

shouldGetOrCreateOneOneDM condition will be false if number split bill participant is more than 1. I think we can disable this check but, further investigation on git blame will give some information .

Result: https://github.com/Expensify/App/assets/114975543/018d4364-e29d-4e57-b629-3cd2d69536ec
joekaufmanexpensify commented 6 months ago

Still discussing behavior here

Ollyws commented 6 months ago

I'm getting the behaviour mentioned here https://github.com/Expensify/App/issues/40579#issuecomment-2100014121 when splitting from the FAB menu, but if I split from the + menu in the chat it seems to create a new report action in the same chat:

Screenshot 2024-05-10 at 14 08 23

tsa321 commented 6 months ago

@Ollyws the error is because the app create new report every time user splits expense from + FAB button -> Split expense. The server will returns error, because we must use existing group report with same split expense participant and we mustn't create new report.

If you can check my proposal, and here is the result:

Result: https://github.com/Expensify/App/assets/114975543/018d4364-e29d-4e57-b629-3cd2d69536ec
joekaufmanexpensify commented 6 months ago

I'm getting the behaviour mentioned here https://github.com/Expensify/App/issues/40579#issuecomment-2100014121 when splitting from the FAB menu, but if I split from the + menu in the chat it seems to create a new report action in the same chat:

Got it. I think the behavior specifically reported for this issue is for FAB. Though, I definitely agree this should work if from within the group too

joekaufmanexpensify commented 6 months ago

Still pending further discussion

Ollyws commented 6 months ago

Investigating this one...

joekaufmanexpensify commented 6 months ago

TY!

joekaufmanexpensify commented 6 months ago

@Ollyws any update on this?

Ollyws commented 6 months ago

Apologies for the delay, will come to a conclusion tomorrow.

Ollyws commented 6 months ago

@FitseTLT's proposal LGTM. I don't see why we can't just update getChatByParticipants to support group chats and remove the && shouldGetOrCreateOneOneDM condition but we can address this in the PR.

🎀👀🎀 C+ reviewed

melvin-bot[bot] commented 6 months ago

Current assignee @youssef-lr is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

melvin-bot[bot] commented 6 months ago

📣 @ShaheFS! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
shahinyan11 commented 6 months ago

@Ollyws Could you please give a feedback about my proposal ?

joekaufmanexpensify commented 6 months ago

Pending sign off from @youssef-lr

melvin-bot[bot] commented 6 months ago

@youssef-lr @Ollyws @joekaufmanexpensify this issue is now 4 weeks old, please consider:

Thanks!

joekaufmanexpensify commented 6 months ago

@FitseTLT please share ETA for a PR

melvin-bot[bot] commented 6 months ago

@youssef-lr, @Ollyws, @FitseTLT, @joekaufmanexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

joekaufmanexpensify commented 6 months ago

@FitseTLT is there an ETA for a PR here?

FitseTLT commented 6 months ago

PR is ready

joekaufmanexpensify commented 5 months ago

PR in review

joekaufmanexpensify commented 5 months ago

PR awaiting review from @youssef-lr

FitseTLT commented 5 months ago

bump for a final review @youssef-lr

youssef-lr commented 5 months ago

on it today @FitseTLT

joekaufmanexpensify commented 5 months ago

Still pending review from @youssef-lr

joekaufmanexpensify commented 5 months ago

@youssef-lr Is this issue on hold now because of the change in project status?

FitseTLT commented 4 months ago

@youssef-lr The conflict resolved and ready for your final review 👍