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

Prevent threads from being counted as DMs #37030

Merged
merged 4 commits into from
Mar 12, 2024
Merged

Conversation

esh-g
Copy link
Contributor

@esh-g esh-g commented Feb 21, 2024

Details

Fixed Issues

$ #34651
PROPOSAL: #34651 (comment)

Tests

  1. [User A] Create a group chat with User B and C
  2. [User A] Send a message in group chat
  3. [User B] Open the message in thread
  4. [User B] Click on the header and note that "Share code" is present
  5. [User B] Reply in thread and return to main chat
  6. [User B] Revisit the thread > Click chat header
  7. [User B] Make sure the share code option is still present.
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. [User A] Create a group chat with User B and C
  2. [User A] Send a message in group chat
  3. [User B] Open the message in thread
  4. [User B] Click on the header and note that "Share code" is present
  5. [User B] Reply in thread and return to main chat
  6. [User B] Revisit the thread > Click chat header
  7. [User B] Make sure the share code option is still present.
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2024-02-21.at.9.43.57.PM.mov
Android: mWeb Chrome
Screen.Recording.2024-02-21.at.9.34.52.PM.mov
iOS: Native
Screen.Recording.2024-02-21.at.9.52.33.PM.mov
iOS: mWeb Safari
Screen.Recording.2024-02-21.at.9.54.50.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2024-02-21.at.9.25.59.PM.mov
MacOS: Desktop
Screen.Recording.2024-02-21.at.10.36.04.PM.mov

@esh-g esh-g requested a review from a team as a code owner February 21, 2024 15:56
@melvin-bot melvin-bot bot removed the request for review from a team February 21, 2024 15:56
Copy link

melvin-bot bot commented Feb 21, 2024

@thesahindia Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@neil-marcellini
Copy link
Contributor

Hi, I'm looking for reviews so I will jump in here and review early.

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to be careful about modifying a general function like this. We need to make sure that all uses of it make sense with the updated logic.

For example, this code could be broken if we exclude threads from being DMs.

I think we should replace some uses of this function to check if the top level parent report is a DM, and we should test related functionality.

@esh-g
Copy link
Contributor Author

esh-g commented Feb 22, 2024

@neil-marcellini I made sure that this was working with the other invocations of the function as well

For example, this code could be broken if we exclude threads from being DMs.

In this code, it is expected that we should not include threads because we assume the user present only in 1:1 DM and not threads. So, in fact it would maybe fix a possible bug where the current user would be counted as a member of a thread without joining it.
All threads have the current user in the participantAccountIDs so, it is expected.

@thesahindia
Copy link
Member

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native Screenshot 2024-02-22 at 12 31 31 AM
Android: mWeb Chrome Screenshot 2024-02-22 at 12 33 17 AM
iOS: Native Screenshot 2024-02-22 at 1 06 57 AM
iOS: mWeb Safari Screenshot 2024-02-22 at 1 06 33 AM
MacOS: Chrome / Safari Screenshot 2024-02-22 at 12 29 34 AM
MacOS: Desktop Screenshot 2024-02-22 at 12 59 06 AM

@thesahindia
Copy link
Member

I have tested it and approving in case we move forward without changing something. I am going OOO.

@melvin-bot melvin-bot bot requested a review from madmax330 February 22, 2024 09:20
Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this code?

App/src/libs/ReportUtils.ts

Lines 983 to 996 in 0d3f47b

/**
* Returns whether a given report can have tasks created in it.
* We only prevent the task option if it's a DM/group-DM and the other users are all special Expensify accounts
*
*/
function canCreateTaskInReport(report: OnyxEntry<Report>): boolean {
const otherReportParticipants = report?.participantAccountIDs?.filter((accountID) => accountID !== currentUserAccountID) ?? [];
const areExpensifyAccountsOnlyOtherParticipants = otherReportParticipants?.length >= 1 && otherReportParticipants?.every((accountID) => CONST.EXPENSIFY_ACCOUNT_IDS.includes(accountID));
if (areExpensifyAccountsOnlyOtherParticipants && isDM(report)) {
return false;
}
return true;
}

It says that we should prevent creating a task in a DM / group if all other participants are Expensify accounts. Now that a thread within a DM is not considered a DM, users can create a task in a thread where all other participants are Expensify accounts.

That seems wrong.

Please check all uses of the function recursively and make sure they make sense. It would be helpful to write an explanation of that in the comment. Sorry to be so strict, but I don't want to break a bunch of stuff.

@esh-g
Copy link
Contributor Author

esh-g commented Mar 4, 2024

Really sorry for the delay! Had to take a break due to health reasons...

Here is a comprehensive explanation for the change at all places:

  1. App/src/libs/ReportUtils.ts

    Lines 1153 to 1155 in f50ac2a

    function isWorkspaceThread(report: OnyxEntry<Report>): boolean {
    return isThread(report) && isChatReport(report) && !isDM(report);
    }

    We can see that there is a check for thread already in place here, so this change is okay here

  2. App/src/libs/ReportUtils.ts

    Lines 1217 to 1230 in f50ac2a

    function isOneOnOneChat(report: OnyxEntry<Report>): boolean {
    const participantAccountIDs = report?.participantAccountIDs ?? [];
    return (
    !isThread(report) &&
    !isChatRoom(report) &&
    !isExpenseRequest(report) &&
    !isMoneyRequestReport(report) &&
    !isPolicyExpenseChat(report) &&
    !isTaskReport(report) &&
    isDM(report) &&
    !isIOUReport(report) &&
    participantAccountIDs.length === 1
    );
    }

    This change actually supports this. We can even remove the !isThread() check here since that is already handled in isDM() now.

  3. const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN && !isEmptyObject(report) && !isDM(report);

    I don't think this interferes here because threads don't have admins who can delete messages (correct me if I'm wrong)

  4. App/src/libs/ReportUtils.ts

    Lines 4274 to 4283 in f50ac2a

    function canRequestMoney(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, otherParticipants: number[]): boolean {
    // User cannot request money in chat thread or in task report or in chat room
    if (isChatThread(report) || isTaskReport(report) || isChatRoom(report) || isSelfDM(report)) {
    return false;
    }
    // Users can only request money in DMs if they are a 1:1 DM
    if (isDM(report)) {
    return otherParticipants.length === 1;
    }

    There already is a check for thread above

  5. if ((isChatRoom(report) && otherParticipants.length > 0) || (isDM(report) && hasMultipleOtherParticipants) || (isPolicyExpenseChat(report) && report?.isOwnPolicyExpenseChat)) {

    if (isDM(report) && hasSingleOtherParticipantInReport) {

    Once again there already is a check for thread above.

  6. App/src/libs/ReportUtils.ts

    Lines 999 to 1007 in f50ac2a

    function canCreateTaskInReport(report: OnyxEntry<Report>): boolean {
    const otherReportParticipants = report?.participantAccountIDs?.filter((accountID) => accountID !== currentUserAccountID) ?? [];
    const areExpensifyAccountsOnlyOtherParticipants = otherReportParticipants?.length >= 1 && otherReportParticipants?.every((accountID) => CONST.EXPENSIFY_ACCOUNT_IDS.includes(accountID));
    if (areExpensifyAccountsOnlyOtherParticipants && isDM(report)) {
    return false;
    }
    return true;
    }

    As for the discussion here, I tested the PR that introduced this change and it still seems to work the same.

So now here are the options we have:

  1. Move forward with the current approach and modify isDM()
    a) Do not modify the redundancy of isThread() checks (like in pt. 2)
    b) Remove redundant logic for thread.
  2. Use the approach of just modifying ReportDetails page and not modify isDM()

cc @neil-marcellini

@esh-g
Copy link
Contributor Author

esh-g commented Mar 4, 2024

Please let me know which option to move forward with as listed above.

@neil-marcellini
Copy link
Contributor

@esh-g thanks for checking all uses and adding explanation. It all looks good to me except canCreateTaskInReport. For that we could update it to return false if areExpensifyAccountsOnlyOtherParticipants and it's a DM or a thread.

Let's move forward with this and remove redundant checks for !isThread()

@esh-g
Copy link
Contributor Author

esh-g commented Mar 6, 2024

@neil-marcellini I delved deeper into the canCreateTaskInReport method and it seems that it would make sense to not include threads in a case like this:

  1. If we have one-on-one chat with Expensify account (ex. concierge)
  2. We are not able to assign tasks in the one-on-one chat as expected.
  3. Now, we send a message and make a thread in the one-on-one chat
  4. If we try to assign a task in the thread, it works because upon creation, a thread only has the current user and no other users as it's participant.
  5. Now, imagine if an Expensify account joins the thread.
  6. Now the current user will not be able to assign tasks anymore because of the entry of the expensify account.
  7. This seems unintentional because it would take away a power from the user that was present before only for the sake of presence of an expensify account.

Sorry once again for the communication lag, but I hope you get my point and please correct me if I'm wrong in my understanding somewhere
Thanks!

@neil-marcellini
Copy link
Contributor

@neil-marcellini I delved deeper into the canCreateTaskInReport method and it seems that it would make sense to not include threads in a case like this:

  1. If we have one-on-one chat with Expensify account (ex. concierge)
  2. We are not able to assign tasks in the one-on-one chat as expected.
  3. Now, we send a message and make a thread in the one-on-one chat
  4. If we try to assign a task in the thread, it works because upon creation, a thread only has the current user and no other users as it's participant.
  5. Now, imagine if an Expensify account joins the thread.
  6. Now the current user will not be able to assign tasks anymore because of the entry of the expensify account.
  7. This seems unintentional because it would take away a power from the user that was present before only for the sake of presence of an expensify account.

That's an interesting case and I appreciate you considering it. I'll tag in @thienlnam since he worked on tasks a lot. Also let us know what you think @madmax330. I think that there is currently a bug on prod at step 4. It doesn't really make sense to me that you can't create a task in the parent DM chat, but you can in a thread. Maybe others see it differently though.

With the current changes in this PR you wouldn't be allowed to create a task in a DM with concierge, but you could in a thread on that DM if concierge joined it. That's inconsistent. Let's aim for consistency.

@thienlnam
Copy link
Contributor

const areExpensifyAccountsOnlyOtherParticipants = otherReportParticipants?.length >= 1 && otherReportParticipants?.every((accountID) => CONST.EXPENSIFY_ACCOUNT_IDS.includes(accountID));

This check is only so that you can't create a task when it's just between you and one of our processing expensify email accounts. Likely your DMs with Concierge, Chronos, etc.

Now, imagine if an Expensify account joins the thread.

This generally won't happen - most of those accounts will not join any threads maybe with the exception of Concierge.

I think that there is currently a bug on prod at step 4. It doesn't really make sense to me that you can't create a task in the parent DM chat, but you can in a thread.

We've kind of moved forward with the notion that this isn't a bug because a child report can constitute of different members. Even if you can't invite someone to the DM between you and Concierge, you can create a thread, and invite members there and so we allow task creation there as well

@neil-marcellini
Copy link
Contributor

Alrighty, thanks for your perspective @thienlnam! After your explanation I think I'm happy with the current solution. I didn't know that you can invite members outside of a DM into a thread within that DM. It feels a little strange to me, but if that's how it works we should match that.

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good and I'm happy with what we have discussed so far. I feel like the following is a mistake. Please lmk if I'm wrong somewhere, but I feel pretty confident that this presents an issue.

src/libs/ReportUtils.ts Outdated Show resolved Hide resolved
@esh-g
Copy link
Contributor Author

esh-g commented Mar 11, 2024

@neil-marcellini Be sure to let me know if something else is left. I once checked all instances of isDM() again and it seems okay to me

Copy link
Contributor

@neil-marcellini neil-marcellini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with it now thanks! All you @madmax330

@madmax330 madmax330 merged commit da76977 into Expensify:main Mar 12, 2024
17 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/madmax330 in version: 1.4.51-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 1.4.51-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants