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

Immediately remove messages flagged as assault or harassment #20223

Merged
merged 11 commits into from
Jun 16, 2023

Conversation

neil-marcellini
Copy link
Contributor

@neil-marcellini neil-marcellini commented Jun 5, 2023

cc @thienlnam

Details

Now when you flag a message as assault or harassment it will be immediately removed from view. The message won't show in the chat, LHN, or on the search page.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/289225
PROPOSAL: N/A

Tests

First check out the corresponding Auth PR https://github.com/Expensify/Auth/pull/8058, build Auth and restart it.

  1. Sign in with any account A
  2. On another device sign in with account B
  3. Send a message from B to A, saying "flag my next message"
  4. Send another message
  5. As account A, flag the message as assault or harassment
  6. Verify that the message is immediately removed from the chat and is no longer visible
  7. Verify that you see a whisper message from concierge saying Thanks for flagging that comment for the Expensify team to review. You will no longer see that message and the Expensify team will take the necessary steps to resolve the situation.
  8. Verify that you do not see the flagged message in the LHN section for account B and see "flag my next message" instead
  9. Open the search page and search for account B
  10. Verify that you do not see the flagged message on the search page and see "flag my next message" instead
  11. Refresh the page and verify that the flagged message is still removed and the whisper is still visible.
  12. Verify the LHN and search page as before
  13. As account B, verify that the flagged message is removed from the chat
  14. Verify that you see a whisper message from concierge saying One of your messages has been flagged. I’ve hidden the message as a potential violation of Rule #2 (Don’t Ruin It For Everyone Else), and it will be reviewed. I will contact you when I have completed my review.
  15. Verify that you do not see the flagged message in the LHN section for account A and see "flag my next message" instead
  16. Open the search page and search for account A
  17. Verify that you do not see the flagged message on the search page and see "flag my next message" instead
  • Verify that no errors appear in the JS console

Offline tests

Same as the tests above, but go offline, flag the comment, then go back online.
Note: This doesn't match the normal offline behavior where the pending "delete" has a strikethrough style, but I think it's best to make an exception for this case because it's not exactly a delete, and more importantly if someone says something awful you want it gone right away, even if you're offline.

QA Steps

Same as tests.

  • 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 / Chrome
    • iOS / native
    • iOS / 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 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(themeColors.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 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 author checklist, including those that don't apply to this PR.

Screenshots/Videos

I'm only testing on web because these changes are platform independent.

Web

Online

online.mov

Offline

offline.mov
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android

@neil-marcellini neil-marcellini self-assigned this Jun 5, 2023
@dangrous dangrous self-requested a review June 7, 2023 17:36
@neil-marcellini neil-marcellini changed the title [HOLD Auth] Mark assault and harassment pending removal [HOLD Auth 8058] Mark assault and harassment pending removal Jun 14, 2023
@neil-marcellini neil-marcellini changed the title [HOLD Auth 8058] Mark assault and harassment pending removal [HOLD Auth 8058] Immediately remove messages flagged as assault or harassment Jun 14, 2023
@neil-marcellini
Copy link
Contributor Author

I did notice a small issue which should probably be fixed. Although I'm successfully hiding the message in the chat, it's still showing up in the LHN from the report.lastMessageText, as you can see in the offline test video. It would also show up on the search or new chat page.

I'll leave it up to you guys whether we need to fix that before merging this. I could write some hacky code here in App to use the previous action message if the latest action is pendingRemove, or I could fix it in Web-Expensify. I'm not sure what's best but I would like to do it in a follow up so we can get the majority of this feature done in time.

@neil-marcellini neil-marcellini marked this pull request as ready for review June 15, 2023 04:37
@neil-marcellini neil-marcellini requested a review from a team as a code owner June 15, 2023 04:37
@melvin-bot melvin-bot bot removed the request for review from a team June 15, 2023 04:38
@melvin-bot
Copy link

melvin-bot bot commented Jun 15, 2023

@abdulrahuman5196 @roryabraham 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]

@abdulrahuman5196
Copy link
Contributor

@neil-marcellini I don't have access to auth PR mentioned in the tests, Do we need to wait for it to merge for testing this PR?

@thienlnam
Copy link
Contributor

@neil-marcellini I don't have access to auth PR mentioned in the tests, Do we need to wait for it to merge for testing this PR?

@abdulrahuman5196 Yeah, you won't be able to do the full tests until the auth PR is deployed (happening later today), but this should work locally/offline. Like if you flag a message as assault it should be hidden

@neil-marcellini neil-marcellini changed the title [HOLD Auth 8058] Immediately remove messages flagged as assault or harassment Immediately remove messages flagged as assault or harassment Jun 15, 2023
@neil-marcellini
Copy link
Contributor Author

I just realized we don't need to hold this on the Auth deploy. It won't break anything without the Auth changes, but it won't work until the Auth changes are deployed.

@neil-marcellini
Copy link
Contributor Author

Ok @thienlnam @dangrous @roryabraham this is ready for review now. The Auth PR is merged but isn't on production quite yet. It should be soon and I'll try to comment here once it's deployed.

Comment on lines -80 to 92
const allReportActions = {};
const allSortedReportActions = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!key || !actions) {
return;
}
allReportActions[key] = actions;
const sortedReportActions = ReportActionUtils.getSortedReportActions(_.toArray(actions), true);
const reportID = CollectionUtils.extractCollectionItemID(key);
lastReportActions[reportID] = _.last(_.toArray(actions));
allSortedReportActions[reportID] = sortedReportActions;
lastReportActions[reportID] = _.first(sortedReportActions);
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised this doesn't impact any other methods here, there isn't any place that uses allReportActions???

Copy link
Contributor

Choose a reason for hiding this comment

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

Also how come the change to lastReportActions? It doesn't seem like it is used in any of your changes

Copy link
Contributor Author

@neil-marcellini neil-marcellini Jun 16, 2023

Choose a reason for hiding this comment

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

Yeah a couple things were surprising when I started looking at this, as you mentioned.

  1. allReportActions was unused (idk why lint didn't catch that)
  2. lastReportActions were not actually the "last" report actions for each report. They don't come pre-sorted in the object, they need to be sorted as we do on the ReportScreen with getSortedReportActions. I figured I should fix that while I'm making changes.

Comment on lines 381 to 395

// Yeah this is a bit ugly. If the latest report action that is not a whisper has been moderated as pending remove, then set the last message text to the text of the latest visible action that is not a whisper.
const lastNonWhisper =
_.find(allSortedReportActions[report.reportID], (action) => {
const isWhisper = (action.whisperedTo || []).length > 0;
return !isWhisper;
}) || {};
if (lodashGet(lastNonWhisper, 'message[0].moderationDecisions[0].decision') === CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE) {
const latestVisibleAction =
_.find(allSortedReportActions[report.reportID], (action) => {
const isWhisper = (action.whisperedTo || []).length > 0;
return ReportActionUtils.shouldReportActionBeVisible(action, action.reportActionID) && !isWhisper;
}) || {};
lastMessageTextFromReport = lodashGet(latestVisibleAction, 'message[0].text', '');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now, we're doing this for every report.
Since this flow is not the main flow can we update the logic so that by default, we don't look for the last non whisper unless we have to?

So basically

Check the last action had a moderation decision

If not, proceed as normal
Otherwise, find the last visible reportAction

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to check the last action that is not a whisper, because otherwise we're looking to see if the whisper is moderated which will always be false.

_.find will stop as soon as it finds a non whisper action, so it's only going to look through n actions where n is the number of whispers in a row from the latest action moving back in time. I think that's ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm yeah, I guess there isn't a great way to avoid this

Copy link
Contributor

@thienlnam thienlnam left a comment

Choose a reason for hiding this comment

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

Just one last comment, but rest looks good

Comment on lines 381 to 395

// Yeah this is a bit ugly. If the latest report action that is not a whisper has been moderated as pending remove, then set the last message text to the text of the latest visible action that is not a whisper.
const lastNonWhisper =
_.find(allSortedReportActions[report.reportID], (action) => {
const isWhisper = (action.whisperedTo || []).length > 0;
return !isWhisper;
}) || {};
if (lodashGet(lastNonWhisper, 'message[0].moderationDecisions[0].decision') === CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE) {
const latestVisibleAction =
_.find(allSortedReportActions[report.reportID], (action) => {
const isWhisper = (action.whisperedTo || []).length > 0;
return ReportActionUtils.shouldReportActionBeVisible(action, action.reportActionID) && !isWhisper;
}) || {};
lastMessageTextFromReport = lodashGet(latestVisibleAction, 'message[0].text', '');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm yeah, I guess there isn't a great way to avoid this

const whisperedTo = lodashGet(props.action, 'whisperedTo', []);
const whisperedTo = props.action.whisperedTo || [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lodash get is unnecessary here and this is faster and just as safe. Tim taught me that.

@thienlnam thienlnam merged commit 469596a into main Jun 16, 2023
@thienlnam thienlnam deleted the neil-moderation-pending-remove branch June 16, 2023 16:32
@melvin-bot melvin-bot bot added the Emergency label Jun 16, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jun 16, 2023

@thienlnam looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@thienlnam
Copy link
Contributor

My bad, forgot the checklist as I was on mobile but I did test this PR locally. @neil-marcellini could you please remove the label as I can't on mobile 🥲

@neil-marcellini
Copy link
Contributor Author

I'm un-assigning @abdulrahuman5196 because we had to get this done quickly and so he wasn't able to test or review.

@neil-marcellini neil-marcellini removed the request for review from abdulrahuman5196 June 16, 2023 16:41
@abdulrahuman5196
Copy link
Contributor

Thank you for notifying. Good to have priority changed merged sooner. I was actually under the impression auth PR was going to be merged yesterday and I planned to test this PR today. Apologies if any delay from my end.

@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/thienlnam in version: 1.3.29-0 🚀

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

@aldo-expensify
Copy link
Contributor

aldo-expensify commented Jun 16, 2023

@neil-marcellini I think this may be causing this deploy blocker: #20940
I think this fixes it: #20949

@aldo-expensify
Copy link
Contributor

@neil-marcellini @dangrous

Do you think we should implement a similar filter for the last report action in Auth: https://github.com/Expensify/Auth/blob/58d8c605f8d820bf6283fb98101798e05287aa26/auth/lib/Report.cpp#L4385-L4416

Right now it doesn't ignore the report action if it has been reported.

@dangrous
Copy link
Contributor

Oh yeah, I think that's correct - we should mirror the change there. Let me know if you agree @neil-marcellini

@neil-marcellini
Copy link
Contributor Author

Yeah I think that would be better. @thienlnam discussed something like that previously but we decided to do the quick and dirty version on the front end. What problem is solved by doing the filtering on the backend?

@aldo-expensify
Copy link
Contributor

What problem is solved by doing the filtering on the backend?

I'm not 100% sure, but it feels like the backend now calculates an incorrect version of the "last message" of a report which we use for LHN, and the front end has to correct it with the code front end code added. It just sounds dirtier to me, and harder to maintain because the last message in the report coming from the backend is not reliable anymore.

@neil-marcellini
Copy link
Contributor Author

Great explanation, I agree!

@aldo-expensify
Copy link
Contributor

I think this #20223 (comment) may be also causing that the report.lastActorAccountID is wrong, see this:

#20949 (comment)

I'll try to fix it in the backend.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 1.3.29-11 🚀

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

Comment on lines +328 to +330
if (lodashGet(reportAction, 'message[0].moderationDecisions[0].decision') === CONST.MODERATION.MODERATOR_DECISION_PENDING_REMOVE) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we are hiding report actions that are pending remove. But didn't handle the same for threads. A report action can be threaded and if that report action is hidden so should the thread report. (Coming from #21497)

Copy link
Contributor

Choose a reason for hiding this comment

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

ah nice catch!

const reportID = CollectionUtils.extractCollectionItemID(key);
lastReportActions[reportID] = _.last(_.toArray(actions));
allSortedReportActions[reportID] = sortedReportActions;
Copy link
Contributor

Choose a reason for hiding this comment

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

We never clean up allSortedReportActions so it keeps gathering garbage between sessions. This confused me a lot since I was able to find reportActions that were not in Onyx. This is also a memory leak.

@neil-marcellini 🙏 fix

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.

7 participants