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

Reader: Fix comments being misplaced after parent comment is moderated #18094

Merged
merged 10 commits into from
Mar 9, 2022

Conversation

dvdchr
Copy link
Contributor

@dvdchr dvdchr commented Mar 7, 2022

Fixes #18081

This PR fixes the orphaned comments issue by "hiding" (or showing) the comment's replies after it is moderated. This follows the behavior on the web where the comment's thread is entirely hidden when it is not approved (or shown if it is).

Some implementation notes:

  • I added visibleOnReader property on Comment to control whether the comment should be visible on the thread. This is because the comment thread is displayed with NSFetchedResultsController.
  • The visibleOnReader property is assigned whenever the user visits the comment thread. Note that the screen downloads the comments every time the page is visited, so the value is guaranteed to be correct whenever the user visits the thread.
  • Lastly, since comments can now be moderated directly from the thread, the comment's replies will be locally updated to have their visibility hidden or shown, matching the ancestor comment that's moderated.
    • Previously, the logic for the comment thread is we show all approved comments regardless of whether the parent/ancestor comment is unapproved/spammed/trashed.
  • Additional note on why adding visibleOnReader instead of calling refreshAndSync after each moderation:
    • The behavior of refreshAndSync is that it downloads all comments and removes all the non-approved ones.
    • After moderating a comment, we offer an option for the user to undo the operation. If we call refreshAndSync after unapproving a comment, it will be deleted from Core Data and we'll have no way to undo the deletion of that one specific comment.

Also, I've noticed some additional issues in Reader Comments that is not addressed in this PR:

  • While in the comment threads, I've noticed some warnings in the console related to cell prefetching:
    [Assert] UITableView internal inconsistency: prefetchedCells (5) and indexPathsForPrefetchedCells (6) are out of sync.
    
  • The number of comments in Comments Snippet and in the Reader List may not match the actual number of comments displayed in the comment thread. The tricky part is the web also displays the same number... so this will need to be investigated separately.

To test:

Prepare a post with comments structured as described in #18081:

A
B
\__ C
     \__ D
E

Scenario 1: Moderating from Reader Comments

  • Go to Reader Comments, and open the comment thread.
  • Unapprove comment B by tapping on the contextual menu.
  • 🔍 Verify comments B, C, and D are hidden.
  • Tap the "Undo" button on the snack bar to revert the operation.
  • 🔍 Verify that comments B, C, and D are now shown.

Scenario 2: Moderating from My Sites while the comment thread is opened

  • Go to Reader Comments, and open the comment thread.
  • Verify that you can see comments B, C, and D.
  • Tap on the My Sites tab > Comments, and unapprove comment B.
  • Go back to the Reader tab.
  • 🔍 Verify comments B, C, and D are hidden.

Regression Notes

  1. Potential unintended areas of impact
    Comments not being displayed correctly in the comment threads.

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Manually tested the changes.

  3. What automated tests I added (or what prevented me from doing so)
    N/A.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@dvdchr dvdchr added this to the 19.4 ❄️ milestone Mar 7, 2022
@dvdchr dvdchr self-assigned this Mar 7, 2022
@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Mar 7, 2022

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 7, 2022

You can test the Jetpack changes on this Pull Request by downloading it from AppCenter here with build number: pr18094-7cd760d. IPA is available here. If you need access to this, you can ask a maintainer to add you.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Mar 7, 2022

You can test the WordPress changes on this Pull Request by downloading it from AppCenter here with build number: pr18094-7cd760d. IPA is available here. If you need access to this, you can ask a maintainer to add you.

@dvdchr dvdchr requested a review from ScoutHarris March 7, 2022 23:40
@mokagio
Copy link
Contributor

mokagio commented Mar 8, 2022

The build for the last commit failed because of a CI issue. I restarted it.

@dvdchr dvdchr changed the base branch from release/19.4 to trunk March 9, 2022 00:43
Copy link
Contributor

@ScoutHarris ScoutHarris left a comment

Choose a reason for hiding this comment

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

It'd be nice to add a release note. Otherwise 👍 .

:shipit:

@ScoutHarris ScoutHarris modified the milestones: 19.4 ❄️, 19.5 Mar 9, 2022
@dvdchr dvdchr enabled auto-merge March 9, 2022 11:46
@dvdchr dvdchr merged commit 7824f15 into trunk Mar 9, 2022
@dvdchr dvdchr deleted the fix/18081-orphaned-comments branch March 9, 2022 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reader comments are misplaced after moderation
4 participants