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

[No QA] Report_AddComment Refactor Part 1 #9328

Merged
merged 4 commits into from
Jun 7, 2022

Conversation

marcaaron
Copy link
Contributor

@marcaaron marcaaron commented Jun 7, 2022

Details

Was looking into refactoring Report_AddComment, but quickly realized it's kind of a mess and thought it would be helpful to split things up into:

  • Stuff we will eventually be able to set in the server
  • Stuff we can't yet set in the server.

My idea here is to basically take updateReportWithNewAction() and minimize it so that it is only used to set data that the server can set. This will be the basis for the next refactoring step - which is to move that stuff into Web-Expensify and then we'll follow that up with the last step to see what else we can do to move more logic into the backend.

Fixed Issues (Related To)

https://github.com/Expensify/Expensify/issues/211241

Tests

  1. Set up two sessions with two different users
  2. Test messaging back and forth works correctly
  3. Test that browser notifications are working correctly
  4. Refresh the page and verify everything works normally
  • Verify that no errors appear in the JS console

PR Review Checklist

PR Reviewer Checklist

  • 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 verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 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 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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team 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 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 */
    • Any functional components have the displayName property
    • 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 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(themeColors.componentBG)
  • 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.

QA Steps

  • Verify that no errors appear in the JS console

@marcaaron marcaaron self-assigned this Jun 7, 2022
@marcaaron marcaaron changed the title Reorganize report action handler Report_AddComment Refactor Part 1 Jun 7, 2022
@marcaaron marcaaron requested a review from yuwenmemon June 7, 2022 00:49
Use timestamp based solution to determine if we need to send a notification

set notificationPreference in report object

Use notification preference from Pusher for now

improve comment

Get rid of sendLocalNotification and just perform directly in Onyx.connect

change name to viewNewReportAction

Make a better diff

Fix tests
@marcaaron marcaaron force-pushed the marcaaron-localNotifications branch from d1fcde6 to 0b0616d Compare June 7, 2022 01:57
@marcaaron marcaaron changed the title Report_AddComment Refactor Part 1 [No QA] Report_AddComment Refactor Part 1 Jun 7, 2022
@marcaaron marcaaron marked this pull request as ready for review June 7, 2022 02:01
@marcaaron marcaaron requested a review from a team as a code owner June 7, 2022 02:01
@melvin-bot melvin-bot bot requested review from arosiclair and removed request for a team June 7, 2022 02:01
@marcaaron
Copy link
Contributor Author

marcaaron commented Jun 7, 2022

I tried to add in the hasAttemptedToNotify stuff, but it's not working in the current state of this PR because I still have some data that must be set inside the "new action" handler. I'm setting report data there which I suspect is triggering the report actions callback again. Think we can just revisit this in a later PR so this is ready for review.

*By not working, I mean it causes extreme lag and triggers many browser notifications.

unreadActionCount: newMaxSequenceNumber - (lastReadSequenceNumbers[reportID] || 0) - ReportActions.getDeletedCommentsCount(reportID, lastReadSequenceNumbers[reportID] || 0),
};

Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, updatedReportObject);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking from an offline perspective. Let's say I'm offline and eventually I receive the new report action. If the 10-second check returns early we won't run this code and thus won't update the unreadActionCount, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you are offline then you can't get any Pusher updates at all. There is no "eventually" - you missed it and it's never coming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you're asking what happens when we come back online - then we would fetch the reports which should update the unreadActionCount for any reports. If you manage to miss a report action update because you're offline and then come back online before the 10 second window - I guess you'd see a notification - which seems alright.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah okay, thanks for clarifying!

Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, updatedReportObject);

// If chat report receives an action with IOU and we have an IOUReportID, update IOU object
if (action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && action.originalMessage.IOUReportID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment for this logic as for above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the answer is the same here. If you miss this update then we just need to have the "reconnection" callbacks account for this data. All the IOU reports should ideally be sent whenever we are "reconnecting".

@yuwenmemon yuwenmemon merged commit 4a1b55d into main Jun 7, 2022
@yuwenmemon yuwenmemon deleted the marcaaron-localNotifications branch June 7, 2022 21:07
@OSBotify
Copy link
Contributor

OSBotify commented Jun 7, 2022

✋ 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

OSBotify commented Jun 8, 2022

🚀 Deployed to staging by @yuwenmemon in version: 1.1.74-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 failure ❌
🍎 iOS 🍎 cancelled 🔪
🕸 web 🕸 failure ❌

@OSBotify
Copy link
Contributor

OSBotify commented Jun 9, 2022

🚀 Deployed to production by @yuwenmemon in version: 1.1.74-2 🚀

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

Comment on lines +1520 to +1524
// If we are currently viewing this report do not show a notification.
if (reportID === lastViewedReportID && Visibility.isVisible()) {
Log.info('[LOCAL_NOTIFICATION] No notification because it was a comment for the current report');
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We didn't consider whether the window has focus, which led to a regression here

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.

4 participants