Match spammed and trashed comments when deduplicating incoming reactions#3532
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes reaction deduplication for incoming Like and Announce activities by ensuring the “already seen” lookup also matches comments that have been marked as spam or moved to the trash, preventing duplicate reaction comments on retried deliveries (follow-up to #3468, addressing #3215).
Changes:
- Extend
Comment::object_id_to_comment()with an optional$argsparameter to pass additionalWP_Comment_Queryarguments (while still enforcingmeta_key/meta_value). - Update Like and Announce handlers to dedupe using
status => 'any', so spammed/trashed reaction comments are still detected. - Add PHPUnit regression tests covering dedupe behavior when the original Like comment is spammed or trashed.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
tests/phpunit/tests/includes/handler/class-test-like.php |
Adds regression tests ensuring duplicate Likes are skipped even if the original comment is spam/trashed. |
includes/handler/class-like.php |
Dedupe lookup now includes comments of any status when checking for an existing Like reaction. |
includes/handler/class-announce.php |
Dedupe lookup now includes comments of any status when checking for an existing Announce/repost reaction. |
includes/class-comment.php |
Adds optional $args to object_id_to_comment() to support status-aware lookups. |
.github/changelog/fix-reaction-dedup-spam-blind |
Changelog entry describing the user-visible fix for spam/trashed reaction dedupe. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #3215 (follow-up to #3468).
Proposed changes:
Comment::object_id_to_comment()usesWP_Comment_Querywith the default status, which core interprets ascomment_approved IN ('0','1')— pending and approved only. A like that was marked as spam (e.g. by Akismet) or moved to the trash was therefore invisible to the dedupe from Fix: Prevent duplicate Like comments from repeated deliveries #3468, and every retried delivery of the same activity created a fresh comment. That matches the reports in Getting repeated comments from a single Mastodon "like" #3215, where duplicates kept appearing even with Fix: Prevent duplicate Like comments from repeated deliveries #3468 applied.Comment::object_id_to_comment()gains an optional$argsparameter for additionalWP_Comment_Queryarguments;meta_key/meta_valuecannot be overridden. Existing callers are unaffected (byte-identical query without the new argument).status => 'any'. The Create handler andInteractions::update_comment()lookups drive update-vs-insert decisions, where matching spammed comments could resurrect spam, so they deliberately keep the default behavior.Other information:
Both new regression tests were verified to fail against trunk and pass with the fix. The spam variant varies the comment author name between deliveries, since WordPress' native author/content duplicate check also matches spam comments and would otherwise mask a dedupe regression — mirroring the mangled emoji author names from the issue reports.
Testing instructions:
Test_Like::test_handle_like_duplicate_skipped_when_original_is_spamandtest_handle_like_duplicate_skipped_when_original_is_trashed.Changelog entry
Changelog entry is committed in
.github/changelog/fix-reaction-dedup-spam-blind.Changelog Entry Details
Significance
Type
Message