Optimistically create policy expense chats for new members of workspaces
Details
Add creating optimistic policy expense chats while adding new members to the workspace, so created chats would pop up while user is offline.
Fixed Issues
$ https://github.com/Expensify/App/issues/14594 PROPOSAL: https://github.com/Expensify/App/issues/14594#issuecomment-1466995775
Tests
Same as QA steps
- [X] Verify that no errors appear in the JS console
Offline tests
Same as the QA steps. Workspace chats for each member should appear optimistically
QA Steps
- Log in with account that has access to the
policy-expense-chatbeta - Go offline by navigating to [profile icon] > Preferences > and enable
Force offline - Create a new workspace.
- Invite some people to the workspace. Verify that workspace chats for each member appear optimistically.
- Go online by navigating to [profile icon] > Preferences > disable
Force online. Verify that workspace chats created for each members are updated accordingly
- [X] Verify that no errors appear in the JS console
PR Author Checklist
- [X] I linked the correct issue in the
### Fixed Issuessection above - [X] I wrote clear testing steps that cover the changes made in this PR
- [X] I added steps for local testing in the
Testssection - [x] I added steps for the expected offline behavior in the
Offline stepssection - [X] I added steps for Staging and/or Production testing in the
QA stepssection - [X] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
- [X] 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)
- [X] 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).
- [X] I added steps for local testing in the
- [X] I included screenshots or videos for tests on all platforms
- [X] I ran the tests on all platforms & verified they passed on:
- [X] Android / native
- [X] Android / Chrome
- [X] iOS / native
- [X] iOS / Safari
- [X] MacOS / Chrome / Safari
- [X] MacOS / Desktop
- [X] 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)
- [X] I followed proper code patterns (see Reviewing the code)
- [X] 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.
toggleReportand notonIconClick) - [X] I verified that comments were added to code that is not self explanatory
- [X] 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.
- [X] I verified any copy / text shown in the product is localized by adding it to
src/languages/*files and using the translation method- [X] 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:
- [X] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
- [X] I verified any copy / text that was added to the app is correct English and approved by marketing by adding the
Waiting for Copylabel for a copy review on the original GH to get the correct copy. - [X] 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.
- [X] I verified the JSDocs style guidelines (in
STYLE.md) were followed
- [X] 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.
- [X] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- [X] I followed the guidelines as stated in the Review Guidelines
- [X] 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 usingAvatarare working as expected) - [X] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
- [X] 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
- [X] I verified that if a function's arguments changed that all usages have also been updated correctly
- [X] If a new component is created I verified that:
- [X] A similar component doesn't exist in the codebase
- [X] All props are defined accurately and each prop has a
/** comment above it */ - [X] The file is named correctly
- [X] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
- [X] The only data being stored in the state is data necessary for rendering and nothing else
- [X] For Class Components, any internal methods passed to components event handlers are bound to
thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor) - [X] Any internal methods bound to
thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick) - [X] All JSX used for rendering exists in the render method
- [X] 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
- [X] If any new file was added I verified that:
- [X] 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
- [X] If a new CSS style is added I verified that:
- [X] A similar style doesn't already exist
- [X] The style can't be created with an existing StyleUtils function (i.e.
StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
- [X] 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
Avataris modified, I verified thatAvataris working as expected in all cases) - [X] 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.
- [X] If a new page is added, I verified it's using the
ScrollViewcomponent to make it scrollable when more elements are added to the page. - [X] If the
mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps. - [X] I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.
Screenshots/Videos
Web
https://user-images.githubusercontent.com/61146594/228816124-18a77c59-8dbc-4901-99a3-bcd603266bc6.mov
Mobile Web - Chrome
https://user-images.githubusercontent.com/61146594/228822830-49b30a11-21f3-47f9-8cd1-b5c24f78bb42.MP4
Mobile Web - Safari
https://user-images.githubusercontent.com/61146594/228822050-f2aa1bc7-a585-434b-99f5-f671747aee98.mov
Desktop
https://user-images.githubusercontent.com/61146594/228823947-bcddeb92-6c9d-4a3d-8d5f-6dd697c1f159.mov
iOS
https://user-images.githubusercontent.com/61146594/228819146-10c9783c-5c18-4052-916e-5bed65dd94aa.mov
Android
https://user-images.githubusercontent.com/61146594/228858213-4561064b-9910-48b7-9121-19b111114467.mov
@bondydaa @0xmiroslav One of you needs to 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]
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅
I have read the CLA Document and I hereby sign the CLA
oh sorry forgot this PR. reviewing now
all you @0xmiroslav let me know if you need help with the checklist.
@RobertKozik can you please merge from main since branch is very behind
@0xmiroslav rebased, so should be up to date
BUG: multiple workspace chats are created for the same user
https://user-images.githubusercontent.com/97473779/230508807-824246f2-0663-4b77-93f9-c5e1d4e20122.mov
@bondydaa should we also cross-out workspace chat when remove user from workspace offline?
should we also cross-out workspace chat when remove user from workspace offline?
Hmm I didn't considered that scenario initially.
I think let's try to keep the scope of this PR small and only focused on the AddMembersToWorkspace API method since I'm assuming the removing of a user is a different API command? We can spin up a new issue to ensure the offline behavior for removing a workspace member is handled properly.
BUG: multiple workspace chats are created for the same user
@bondydaa are you able to reproduce this one?
I didn't see more than 1 when I tested yesterday on desktop but let me try again. Did you only add 1 member while offline? Or multiple? I think I tested adding 2 users but not just a single user so I'll try both.
I didn't see more than 1 when I tested yesterday on desktop but let me try again. Did you only add 1 member while offline? Or multiple? I think I tested adding 2 users but not just a single user so I'll try both.
I tried only one. Please try to repeat adding/removing the same user.
Hmm yeah I am seeing some weird things when you remove the user while offline.
Steps are like:
- Go offline
- add new member to workspace, see optimistic report added to LHN
- remove user from workspace, optimistic report stays in LHN
- Go online
- optimistic report in LHN becomes "real chat", if you open that chat it then disappears from LHN and you see it's archived.
Though I think this is related more to removing a user vs adding a user so I think we handle that in the follow up GH for DeleteMembersFromWorkspace API command
@0xmiroslav @bondydaa I came up with quicker fix, as after removing the user chat remains as archived. We can look for this report and just change it's status to open as API will return it's ID as new chat. What you think about such an approach?
edit: @bondydaa I was testing it with following steps:
- Go offline
- add new member to workspace, see optimistic report added to LHN
- Go online
- Optimistic chat is replaced with real one
- remove user from workspace, optimistic report stays in LHN
- Go offline
- Add member simmilar to the one from step 1
I came across one more problem though @bondydaa . Now we are passing only the reportID and It's merging into one as it should. But as we are not passing the created report action ID, when user clicks the created chat after coming back online we have double welcome notice. I think we should also pass the reportActionID as it is done when creating normal chat Here are steps to repo this:
- Go offline
- Invite new member to workspace (optimistic creation of report is doing fine)
- Go online
- click on created chat and wait for the data to come from server
I created this https://github.com/Expensify/App/issues/17137 for the follow up issue. Let's keep adding reproduce steps for things we see related to removing a user from the workspace / DeleteMembersFromWorkspace APi command to that as we come across them.
I've removed isLoadingReportActions key and add failure onyx data as requested in review.
Though I think this is related more to removing a user vs adding a user so I think we handle that in the follow up GH for DeleteMembersFromWorkspace API command
I think duplicate issue is not related to "remove user when offline". This also happens "when remove user online", so issue should be fixed here.
Hmm interesting, I'll take a look at logs to see if I can confirm the following:
What I suspect is happening is that onyx is just "out of date" with the removed user and that's why you're able to create a new chat successfully which then shows 2 of them since the first one for the user is technically archived which is why I think it's more related to DeleteMembersFromWorkspace.
The behavior is only showing up now in this PR since previously the policy expense chats couldn't be added optimistically anyways.
I checked this more in depth. In my opinion this bug consists of two separate problems:
- When user is offline and tries to remove optimistically workspace member - created chat is not being removed
- User is invited and chat is created successfully online, later removed - in this case when member is going to be re-added while app is offline, optimistically created chat will be created, but passed
reportIDwill be ignored by backend. Returned chat will be the same one as when user was being added for the first time.
The first one is more related to DeleteMembersFromWorkspace as @bondydaa stated. But the second one should be resolved in this PR.
I came up with the solution: after removing the user chat remains as archived. We will look for this report and just change it's status to open (optimistically) as API will return it's ID as new chat. After coming back online, everything should work as intended.
Hi @bondydaa what is the status of your PRs? Can we proceed with this one?
we just deployed the API changes to staging about half an hour ago so feel free to test this against that.
I know you can't access this link but got a PR up fixing the WAF rule here https://github.com/Expensify/Web-Expensify/pull/37082
I'll get it to staging as soon as it's merged via Cherry Pick (CP).
@0xmiroslav can you handle the the reviewer checklist?
@0xmiroslav can you handle the the reviewer checklist?
Sure
@RobertKozik @bondydaa While testing with simulating network, I noticed chat room is still doubled. After logout and login, it disappears. All work fine in normal scenario (when switch real network). Can we ignore simulating network tests?
https://user-images.githubusercontent.com/97473779/234062258-f77ec64a-f05d-4c38-89f4-b68ff1d2fa42.mov
Logout and login:
https://user-images.githubusercontent.com/97473779/234062381-e4dcf40f-a3f5-4397-9834-cc6e666ab40c.mp4
I think this one is more related to deleting the member, thus should be considered in: https://github.com/Expensify/App/issues/17137.
yeah I agree probably most likely related to deleting the member which we know we need to improve in that other issue.
Reviewer Checklist
- [x] I have verified the author checklist is complete (all boxes are checked off).
- [x] I verified the correct issue is linked in the
### Fixed Issuessection above - [x] I verified testing steps are clear and they cover the changes made in this PR
- [x] I verified the steps for local testing are in the
Testssection - [x] I verified the steps for Staging and/or Production testing are in the
QA stepssection - [x] 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)
- [x] 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)
- [x] I verified the steps for local testing are in the
- [x] I checked that screenshots or videos are included for tests on all platforms
- [x] I included screenshots or videos for tests on all platforms
- [x] I verified tests pass on all platforms & I tested again on:
- [x] Android / native
- [x] Android / Chrome
- [x] iOS / native
- [x] iOS / Safari
- [x] MacOS / Chrome / Safari
- [x] MacOS / Desktop
- [x] 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
- [x] I verified proper code patterns were followed (see Reviewing the code)
- [x] 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.
toggleReportand notonIconClick). - [x] I verified that comments were added to code that is not self explanatory
- [x] 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.
- [x] I verified any copy / text shown in the product is localized by adding it to
src/languages/*files and using the translation method - [x] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
- [x] 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 Copylabel for a copy review on the original GH to get the correct copy. - [x] 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.
- [x] I verified the JSDocs style guidelines (in
STYLE.md) were followed
- [x] 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.
- [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- [x] I verified that this PR follows the guidelines as stated in the Review Guidelines
- [x] 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 usingAvatarhave been tested & I retested again) - [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
- [x] 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
- [x] If a new component is created I verified that:
- [x] A similar component doesn't exist in the codebase
- [x] All props are defined accurately and each prop has a
/** comment above it */ - [x] The file is named correctly
- [x] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
- [x] The only data being stored in the state is data necessary for rendering and nothing else
- [x] For Class Components, any internal methods passed to components event handlers are bound to
thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor) - [x] Any internal methods bound to
thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick) - [x] All JSX used for rendering exists in the render method
- [x] 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
- [x] If any new file was added I verified that:
- [x] 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
- [x] If a new CSS style is added I verified that:
- [x] A similar style doesn't already exist
- [x] The style can't be created with an existing StyleUtils function (i.e.
StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
- [x] 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.
- [x] 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
Avataris modified, I verified thatAvataris working as expected in all cases) - [x] 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.
- [x] If a new page is added, I verified it's using the
ScrollViewcomponent to make it scrollable when more elements are added to the page. - [x] If the
mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps. - [x] I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.
Screenshots/Videos
Web
https://user-images.githubusercontent.com/97473779/235016222-c4d71c4f-2786-4abf-be49-fa89c819d7c8.mov
Mobile Web - Chrome
https://user-images.githubusercontent.com/97473779/235015403-483d3b36-8455-46fe-b7a3-563b43df0b9a.mp4
Mobile Web - Safari
Desktop
https://user-images.githubusercontent.com/97473779/235019685-f6667c63-51d8-4405-81a0-48be57bd1076.mov
iOS
https://user-images.githubusercontent.com/97473779/234062258-f77ec64a-f05d-4c38-89f4-b68ff1d2fa42.mov
Logout and login:
https://user-images.githubusercontent.com/97473779/234062381-e4dcf40f-a3f5-4397-9834-cc6e666ab40c.mp4
Android
https://user-images.githubusercontent.com/97473779/235015302-2713875e-2b06-445e-a13f-4efb50694e27.mp4
I found weird bug while testing Force offline in android:
- Let's say workspaces W1, W2 exist and member M1 is already added to W1
- Enable "Force offline"
- invite M1 to W2 Looks good so far
- Disable "Force offline"
- Suddenly W1 workspace name changes to W2
https://user-images.githubusercontent.com/97473779/234100434-13ac02c1-9034-4eb5-87e0-c895263b875e.mov