Make WordPress Core

Opened 8 years ago

Last modified 3 days ago

#46017 new defect (bug)

"Mine" comment count isn't updated when replying to or moderating a comment.

Reported by: pento Owned by:
Priority: normal Milestone: Future Release
Component: Comments Version: 5.1
Severity: normal Keywords: needs-testing has-patch has-unit-tests
Cc: Focuses: administration

Description

To reproduce:

  • Visit /wp-admin/edit-comments.php.
  • Click Reply on a comment.
  • Type some text in the comment, click Reply.

The "All" and "Approved" counts update as expected, but the "Mine" count doesn't.

Attachments (2)

edit-comments.diff (360 bytes ) - added by itzmekhokan 8 years ago.
46017.patch (360 bytes ) - added by itzmekhokan 8 years ago.
The "All" and "Approved" commemts counts updated values comes from edit-comments.js.

Download all attachments as: .zip

Change History (13)

@itzmekhokan
8 years ago

The "All" and "Approved" commemts counts updated values comes from edit-comments.js.

#1 @itzmekhokan
8 years ago

  • Keywords has-patch added; needs-patch removed

#2 @garrett-eclipse
8 years ago

  • Keywords needs-testing added

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.


8 years ago

#4 @peterwilsoncc
8 years ago

  • Keywords needs-refresh added

The same bug occurs when a user changes the status (un/approve, trash or spam) of their own comment in via the actions.

As the bug is more than a quick fix, I'm inclined to move it off 5.1 for a later release.

@itzmekhokan your patch works as expected for a reply but misses the other actions. Do you think you'll be able to work on an update? It's no problem if you don't have time.

#5 @peterwilsoncc
8 years ago

  • Milestone 5.1Future Release
  • Summary "Mine" comment count isn't updated when adding a comment."Mine" comment count isn't updated when replying to or moderating a comment.

Dropping this off the milestone, as noted above this occurs for all actions that should modify the "mine" count.

The fix may require modifications to the ajax responses/additional data- attributes in the comment list table.

This ticket was mentioned in Slack in #core-test by mosescursor. View the logs.


11 months ago

This ticket was mentioned in PR #12620 on WordPress/wordpress-develop by @arkaprabhachowdhury.


4 weeks ago
#7

  • Keywords has-unit-tests added; needs-refresh removed

## Summary

  • Updates the "Mine" comment count after replying to a comment through AJAX.
  • Adds current-user ownership metadata to comment moderation AJAX responses.
  • Uses the existing approved and pending deltas to update "Mine" only when the affected comment belongs to the current user.
  • Adds regression coverage for the ownership metadata.

## Why

The comments screen already updates the All, Pending, Approved, Spam, and Trash counts after AJAX actions, but it does not update Mine. Moderation responses also did not expose enough information for the client to know whether the affected comment belonged to the current user.

## Testing

  • npm run test:php -- --group ajax --filter "Tests_Ajax_wpAjax(DeleteComment|DimComment|ReplytoComment)" (18 tests, 132 assertions)
  • npm run test:php -- --group ajax --filter Tests_Ajax_wpAjaxDeleteComment (6 tests, 85 assertions)
  • PHPCBF and PHPCS with phpcs.xml.dist on both touched PHP files
  • JavaScript JSHint passed for src/js/_enqueues/admin/edit-comments.js

This ticket was mentioned in Slack in #core-test by softglaze. View the logs.


4 days ago

This ticket was mentioned in PR #13040 on WordPress/wordpress-develop by @ikamal.


4 days ago
#9

## Summary

  • The comments list table updates the All, Approved, Pending, Spam, and Trash counts via AJAX after replying to or moderating a comment, but the "Mine" count never updates.
  • Adds an isCurrentUserComment flag to the supplemental data returned by _wp_ajax_delete_comment_response() (used by both wp_ajax_delete_comment() for trash/untrash/spam/unspam/delete, and wp_ajax_dim_comment() for approve/unapprove).
  • edit-comments.js uses that flag to bump span.mine-count by the same delta as Pending/Approved when the affected comment belongs to the current user, and unconditionally bumps it by 1 after a reply is added (a reply is always authored by the current user).

## Why
"Mine" (class-wp-comments-list-table.php) counts comments where comment->user_id === get_current_user_id(), independent of moderation. Approve/Unapprove alone never changes this count since Mine already includes both pending and approved comments; only entering/leaving Spam/Trash does — which is what the JS change reflects.

Fixes #46017

## Testing

  • php -l on the touched PHP file.
  • node --check on the touched JS file.
  • Manually verified in the browser: replying to and moderating (approve/unapprove/spam/unspam/trash/untrash) a comment authored by the current user updates the "Mine" tab count; actions on other users' comments leave it unchanged.

## Test plan

  • [ ] Visit /wp-admin/edit-comments.php as a user who has authored comments.
  • [ ] Reply to one of your own comments — "Mine" count increments.
  • [ ] Approve/Unapprove one of your own comments — "Mine" count stays the same (comment just moves between Pending/Approved).
  • [ ] Spam, Trash, and their Undo actions on your own comments — "Mine" count decrements/increments accordingly.
  • [ ] Moderate a comment authored by a different user — "Mine" count does not change.

#10 @ikamal
4 days ago

Opened a PR: PR #13040 — "Comments: Update the "Mine" count after AJAX moderation and reply actions."

The 2017 patch (46017.patch / edit-comments.diff) only updated the count from commentReply.show(), i.e. the reply case. It didn't touch delAfter/dimAfter, so approve, unapprove, spam, unspam, trash, and untrash still left "Mine" stale — the exact gap peterwilsoncc flagged in comment 4 ("your patch works as expected for a reply but misses the other actions").

This PR instead adds an isCurrentUserComment flag to the supplemental data returned by _wp_ajax_delete_comment_response() (shared by wp_ajax_delete_comment() for trash/untrash/spam/unspam/delete and wp_ajax_dim_comment() for approve/unapprove), so edit-comments.js knows whether the affected comment belongs to the current user for every moderation action, not just replies.

Test report (/wp-admin/edit-comments.php, logged in as the comment author):

  • Reply to your own comment → "Mine" count increments. ✓
  • Approve / Unapprove your own comment → "Mine" count unchanged (comment just moves between Pending and Approved, and Mine already counts both). ✓
  • Spam your own comment, then Undo → "Mine" decrements, then increments back. ✓
  • Trash your own comment, then Undo → "Mine" decrements, then increments back. ✓
  • Moderate a comment authored by a different user → "Mine" count does not change. ✓

php -l and node --check clean on both touched files.

@ugyensupport commented on PR #13040:


3 days ago
#11

Tested this patch — works as intended. ✅

Applied the two-file change to a local WordPress install and exercised the actual wpList AJAX path (not just the HTTP endpoints) on edit-comments.php, with a set of comments owned by the logged-in user plus one comment by a different user.

Action Expected "Mine" Result
---:---::---:
Spam an approved comment I own 4 → 3
Undo (unspam) 3 → 4
Trash a pending comment I own 4 → 3
Undo (untrash) 3 → 4
Unapprove → Approve my comment stays 4
Spam another user's comment stays 4
Reply to my comment 4 → 5

All other tab counts stayed correct, and after a full page reload the server-rendered "Mine" count matched the AJAX-updated value exactly — no drift. The negative case (moderating another user's comment) confirms the isCurrentUserComment guard works.

The logic holds because "Mine" resolves to get_comments() with the default status = 'all' (comment_approved IN ('0','1') — pending + approved, excluding spam/trash), so mineDiff = pendingDiff + approvedDiff is exactly the change in Mine membership.

One suggestion: it'd be worth adding a small PHPUnit test asserting supplemental['isCurrentUserComment'] is 1 for an owned comment and 0 otherwise, to guard the PHP half against regressions.

Note: See TracTickets for help on using tickets.