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

[$250] mWeb - room- Inviting a previously unknown user to room displays member count incorrectly #46298

Closed
1 of 6 tasks
lanitochka17 opened this issue Jul 26, 2024 · 28 comments
Closed
1 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Help Wanted Apply this label when an issue is open to proposals by contributors Internal Requires API changes or must be handled by Expensify staff Reviewing Has a PR in review Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Jul 26, 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.13
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 https://staging.new.expensify.com/home
  2. Tap on a room chat -- header -- invite
  3. Enter an email you have not previously had contact with eg: jaihanumanblog+1111@gmail.com
    and invite to room
  4. Tap back button
  5. Note members count

Expected Result:

Inviting an user to room via secondary contact must display member count correctly

Actual Result:

Inviting an user to room via secondary contact must display member count correctly

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

Bug6552594_1721908859939.uu122.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01b5145e9ee0c2aee8
  • Upwork Job ID: 1818427399700311066
  • Last Price Increase: 2024-07-30
Issue OwnerCurrent Issue Owner: @ZhenjaHorbach
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 26, 2024
Copy link

melvin-bot bot commented Jul 26, 2024

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

We think that this bug might be related to #vip-vsp

@lanitochka17
Copy link
Author

@stephanieelliott 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
Copy link
Contributor

Proposal

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

room-Inviting a user who you have no contact before displays member count incorrectly

What is the root cause of that problem?

The issue is not caused by using the secondary contact to add a member to a room (as indicated in OP) but instead when a user adds a member who's personal detail doesn't exist in onyx a new optimistic personal detail is created then after a while the real personal detail representing the member comes from BE and the optimistic personal detail will be deleted but the accountID of the optimistic personal detail still exists in report.participants list so the members count will be wrong as we display the participants length here

subtitle: activeChatMembers.length,
isAnonymousAction: false,

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

We should filter particpants whose personal details doesn't exist just the same as what we did in RoomMemebersPage here

participants.forEach((accountID) => {
const details = personalDetails[accountID];
if (!details) {
Log.hmmm(`[RoomMembersPage] no personal details found for room member with accountID: ${accountID}`);
return;
}

We should change
const participants = useMemo(() => {
const shouldExcludeHiddenParticipants = !isGroupChat && !isSystemChat;
return ReportUtils.getParticipantsAccountIDsForDisplay(report, shouldExcludeHiddenParticipants);
}, [report, isGroupChat, isSystemChat]);

to

const participants = useMemo(() => {
        const shouldExcludeHiddenParticipants = !isGroupChat && !isSystemChat;
        const participantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, shouldExcludeHiddenParticipants);
        return participantAccountIDs?.filter((accountID) => !!personalDetails?.[accountID]);
    }, [report, isGroupChat, isSystemChat, personalDetails]);

We can also check and do the same for workspace members too if needed.

What alternative solutions did you explore? (Optional)

@FitseTLT
Copy link
Contributor

@stephanieelliott the title of the OP is a lit bit misleading as it suggests the problem is caused by using the secondary contact to invite the member but the problem is caused by the member being invited was a member with which the current user had no contact before. So to reproduce it, you should test by adding a member with which you had no contact before.
And also I suggest you update the title of the issue accordingly Thx. 👍

@bernhardoj
Copy link
Contributor

bernhardoj commented Jul 27, 2024

Proposal

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

Inviting user we never chat before to a room will make an extra count to the room member count.

What is the root cause of that problem?

When we are searching for a new user, the app will generate a random optimistic account ID.

// Generates an optimistic account ID for new users not yet saved in Onyx
const optimisticAccountID = UserUtils.generateAccountID(searchValue);

When we invite the user, the app will optimistically merge the generated account ID to the room participants.

App/src/libs/actions/Report.ts

Lines 2809 to 2836 in 5e65276

const participantsAfterInvitation = inviteeAccountIDs.reduce(
(reportParticipants: Participants, accountID: number) => {
const participant: ReportParticipant = {
hidden: false,
role: CONST.REPORT.ROLE.MEMBER,
};
// eslint-disable-next-line no-param-reassign
reportParticipants[accountID] = participant;
return reportParticipants;
},
{...report.participants},
);
const logins = inviteeEmails.map((memberLogin) => PhoneNumber.addSMSDomainIfPhoneNumber(memberLogin));
const {newAccountIDs, newLogins} = PersonalDetailsUtils.getNewAccountIDsAndLogins(logins, inviteeAccountIDs);
const newPersonalDetailsOnyxData = PersonalDetailsUtils.getPersonalDetailsOnyxDataForOptimisticUsers(newLogins, newAccountIDs);
const pendingChatMembers = ReportUtils.getPendingChatMembers(inviteeAccountIDs, report?.pendingChatMembers ?? [], CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD);
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
participants: participantsAfterInvitation,
pendingChatMembers,
},
},
];

However, we never clear the optimistic report participant. This logic is used for both invite to room and group, but the issue doesn't happen in a group chat because the API for invite to group chat returns a response when success that will clears the optimistic report participant.

The reason the optimistic participant disappears from the member list is because we skip over members that doesn't have personal details (which are cleared correctly when successful).

if (!details) {
Log.hmmm(`[RoomMembersPage] no personal details found for room member with accountID: ${accountID}`);
return;
}

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

Fix it in the BE so invite to room also returns a response to clear the optimistic report participant.

OR

Fix it in the FE by clearing the optimistic report participant in success data.

const participantsSuccessData = inviteeAccountIDs.reduce(
    (reportParticipants, accountID: number) => ({...reportParticipants, [accountID]: null}),
    {},
);
const successData: OnyxUpdate[] = [
    {
        onyxMethod: Onyx.METHOD.MERGE,
        key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
        value: {
            participants: participantsSuccessData,
            pendingChatMembers: successPendingChatMembers,
        },
    },
];

@melvin-bot melvin-bot bot added the Overdue label Jul 29, 2024
Copy link

melvin-bot bot commented Jul 29, 2024

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

@stephanieelliott stephanieelliott changed the title mWeb - room-Inviting an user to room via secondary contact displays member count incorrectly mWeb - room- Inviting a previously unknown user to room displays member count incorrectly Jul 30, 2024
@stephanieelliott
Copy link
Contributor

Thanks @FitseTLT! I see what you mean -- updated the title and action steps to make that more clear.

@melvin-bot melvin-bot bot removed the Overdue label Jul 30, 2024
@stephanieelliott
Copy link
Contributor

Given that it affects any user you've not previously had contact with (not secondary logins) and persists on the workspace, I think this is worth fixing. Adding labels to get the proposals reviewed.

@stephanieelliott stephanieelliott added the External Added to denote the issue can be worked on by a contributor label Jul 30, 2024
@melvin-bot melvin-bot bot changed the title mWeb - room- Inviting a previously unknown user to room displays member count incorrectly [$250] mWeb - room- Inviting a previously unknown user to room displays member count incorrectly Jul 30, 2024
Copy link

melvin-bot bot commented Jul 30, 2024

Job added to Upwork: https://www.upwork.com/jobs/~01b5145e9ee0c2aee8

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

melvin-bot bot commented Jul 30, 2024

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

@ZhenjaHorbach
Copy link
Contributor

I will check proposals today or tomorrow

@ZhenjaHorbach
Copy link
Contributor

ZhenjaHorbach commented Aug 1, 2024

@FitseTLT @bernhardoj
Thank you for your proposals !

I agree with @bernhardoj that we can fix this in BE

But on the other side If we decide to fix this in FE
I like @FitseTLT proposal more
Firstly, because it works as expected (@bernhardoj proposal works a little unpredictably if we try to invite a known user (This user will disappear from the list))
And secondly, we will be sure that these changes will work with the users already invited

But first, let's find out what the internal team thinks about where it is best to fix it
🎀👀🎀 C+ reviewed

Copy link

melvin-bot bot commented Aug 1, 2024

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

@dangrous
Copy link
Contributor

dangrous commented Aug 2, 2024

Okay yep, I think it makes the most sense to copy the group chat behavior on the backend. I should be able to get to that early next week!

To confirm, if we do that, we shouldn't need any front end fixes, right?

@dangrous dangrous added Internal Requires API changes or must be handled by Expensify staff and removed External Added to denote the issue can be worked on by a contributor labels Aug 2, 2024
@ZhenjaHorbach
Copy link
Contributor

Okay yep, I think it makes the most sense to copy the group chat behavior on the backend. I should be able to get to that early next week!

To confirm, if we do that, we shouldn't need any front end fixes, right?

Since inviting to a group chat works correctly
I think the changes in BE will be enough

@dangrous
Copy link
Contributor

dangrous commented Aug 5, 2024

This did need an incredibly minor front end adjustment, so I went ahead and did that myself. Both PRs will be in review in a sec!

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Aug 5, 2024
@stephanieelliott
Copy link
Contributor

The second PR is held on #46825 which is merged but not yet on prod , so we should be able to resume this soon.

@dangrous
Copy link
Contributor

dangrous commented Aug 9, 2024

still waiting on deploy to prod, will likely be Monday due to earnings, Friday...

@dangrous
Copy link
Contributor

we should be able to test this again on staging and hopefully close out!

@dangrous
Copy link
Contributor

So this ends up with the correct amount, but it takes a while to get there. It doesn't get higher than it should but if I'm the only person in a room and then I invite another person, it stays 1 for a while, before switching to 2. @ZhenjaHorbach (or others) do you want to give this a look and see if there's anything we can do optimistically on the front end that might make this cleaner?

Or if I need to update the backend again we can do that.

@ZhenjaHorbach
Copy link
Contributor

ZhenjaHorbach commented Aug 14, 2024

So this ends up with the correct amount, but it takes a while to get there. It doesn't get higher than it should but if I'm the only person in a room and then I invite another person, it stays 1 for a while, before switching to 2. @ZhenjaHorbach (or others) do you want to give this a look and see if there's anything we can do optimistically on the front end that might make this cleaner?

Or if I need to update the backend again we can do that.

Could you provide a video, please ?
Because everything works great for me now

@dangrous
Copy link
Contributor

Oh weird! I just tested again (in order to take the video) and it works like a charm. Maybe something was happening on the backend.

Are we good to close, or do we need any payments handled?

@ZhenjaHorbach
Copy link
Contributor

ZhenjaHorbach commented Aug 14, 2024

Oh weird! I just tested again (in order to take the video) and it works like a charm. Maybe something was happening on the backend.

Are we good to close, or do we need any payments handled?

Following the new rules and if i understand correctly
I am eligible for 50% of the payment 😀

But if not, then I think we can close this issue !

@dangrous
Copy link
Contributor

Ah yep that seems right to me! cc @stephanieelliott

@stephanieelliott
Copy link
Contributor

Hey @ZhenjaHorbach I extended the offer to you in Upwork, can you accept when you get a sec? https://www.upwork.com/nx/wm/offer/103546715

@ZhenjaHorbach
Copy link
Contributor

Hey @ZhenjaHorbach I extended the offer to you in Upwork, can you accept when you get a sec? https://www.upwork.com/nx/wm/offer/103546715

Done, thanks !

@stephanieelliott
Copy link
Contributor

Summarizing payment on this issue:

  • Contributor: N/A internal
  • Contributor+: @ZhenjaHorbach $250 via Upwork -- PAID

Upwork job is here: https://www.upwork.com/jobs/~01b5145e9ee0c2aee8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Help Wanted Apply this label when an issue is open to proposals by contributors Internal Requires API changes or must be handled by Expensify staff Reviewing Has a PR in review Weekly KSv2
Projects
Status: Done
Development

No branches or pull requests

6 participants