Editor: Add emoji reactions as a comment type for Notes#10930
Editor: Add emoji reactions as a comment type for Notes#10930adamsilverstein wants to merge 11 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| } | ||
| } | ||
| }, | ||
| "authentication": [], |
There was a problem hiding this comment.
Why did this changed? Stale from a previous commit?
There was a problem hiding this comment.
yes, I ran the test_build_wp_api_client_fixtures test locally to regenerate fixtures and this was the result. I wrote that test so I'm confident this is correct, but happy to add in a separate PR since its unrelated to the current changes. ideally we should have a check similar to package lock that checks if running the regeneration changes the fixture and reject the merge if so.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Introduce the `reaction` comment type to support emoji reactions on collaborative Notes, replacing the previous `_wp_note_reactions` meta approach. Changes include: - Add `reaction` to avatar comment types. - Exclude reactions from admin comment lists and comment counts. - Extend the REST API Comments Controller to handle reactions: permissions checks, validation (valid emoji slugs, parent must be a note, one emoji per user per note), auto-approval, and content allowed checks. - Add PHPUnit tests for reaction creation, validation, and counting. - Regenerate API fixtures. Props flavor flavor. See #63191. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e8246a7 to
fe19243
Compare
|
I have updated this backport PR to apply the custom comment type approach for storage used in WordPress/gutenberg#75549 which replaces the meta based approach in WordPress/gutenberg#75144. |
Picks up new 'footnotes' meta registered on post types, plus site_logo and site_icon settings exposed via the REST API. Needed so 'git diff --exit-code' in the PHPUnit CI step passes after merging trunk into the backport branch.
…nt_types(). Per review feedback on PR WordPress#10930, introduce wp_get_internal_comment_types() in src/wp-includes/comment.php as the single source of truth for non-comment comment types ('note', 'reaction'). The new helper is filterable so future internal types can be added without touching every call site. Apply it across the existing 'note'/'reaction' guards: * WP_Comments_List_Table: comment_type filter and type__not_in. * get_pending_comments_num(): exclude internal types from pending counts. * wp_update_comment_count_now(): exclude internal types from approved counts. * WP_REST_Comments_Controller: get_items / permissions / prepare / links / duplicate-flood checks across multiple sites. * is_avatar_comment_type(): default avatar comment types. Props westonruter for the suggestion to centralize this list.
…omment_types(). Mirrors the change being proposed for core in WordPress/wordpress-develop#10930. Introduces a single helper that returns the list of internal comment types ('note', 'reaction'), filterable so future additions only need to update one place. Apply it across all the existing 'note'/'reaction' guards in the 7.1 compat layer: * gutenberg_update_get_avatar_comment_type_7_1() — avatar-eligible types. * gutenberg_exclude_block_comments_from_admin_7_1() — admin query exclude. * gutenberg_filter_comment_count_query_exclude_block_comments_7_1() — pending-count SQL guard. * gutenberg_hide_note_from_comment_list_table_7_1() — list table args. * gutenberg_exclude_notes_from_comment_count_7_1() — approved-count SQL. * Gutenberg_REST_Comment_Controller_7_1::is_note_or_reaction() — REST controller's per-request type check (used by permissions, prepare, validation, and links). Props westonruter for the suggestion to centralize this list.
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Expose the curated reaction emoji list (heart, celebration, smile, eyes, rocket) via a filterable helper so REST validation and schema can share a single source. Mirrors gutenberg_get_note_reaction_emojis() from the Gutenberg notes reactions feature. See #63191.
Align the reaction comment type handling with the latest Gutenberg notes reactions PR (WordPress/gutenberg#76767): - Accept emoji slugs as either a curated slug (heart, celebration, smile, eyes, rocket) or a lowercase hex-codepoint sequence (e.g. 1f44d for 👍 or 1f468-200d-1f4bb for 👨💻). Raw emoji bytes are rejected since the comments table is not guaranteed to be utf8mb4 across installs; clients normalize before submitting. - Scope the uniqueness check to active reactions only, so a user can re-add the same emoji after removing (trashing) it on the same note. - Point note's children link at reaction children, not at notes, so embedded children resolve to the reactions on the note. - Add a read-only reaction_emojis schema property exposing the allowed emoji list, so clients can discover accepted slugs via OPTIONS. - Add a reaction_summary field aggregating per-emoji counts on note responses, with reacted/my_reaction_id for the current user. - Pre-fetch reaction summaries in get_items() to avoid N+1 queries when listing many notes. See #63191.
Add tests covering the updated reaction validation, summary, and schema behaviors: - Accept hex-codepoint emoji slugs (e.g. 1f468-200d-1f4bb). - Reject raw emoji bytes. - Allow re-adding a reaction after the previous one is trashed. - reaction_summary aggregates per-emoji counts with the current user's reacted state and reaction ID. - reaction_emojis schema property exposes the curated slug list. - A note's children link targets reactions, not nested notes. Update test_get_item_schema for the two new schema properties, and test_get_note_with_children_link to expect type=reaction for note children. See #63191.
- Fix double-space alignment warning in test file (line 4702). - Extend phpcs:ignore directives in prefetch_reaction_summaries() to cover WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, acknowledging PHPCS cannot count placeholders through the spread operator. See #63191.
There was a problem hiding this comment.
Thanks for the PR!
My investigation suggests there are still a few places where wp_get_internal_comment_types() should be applied. Below is the code that might be affected.
WP_Comment_Query class:
wordpress-develop/src/wp-includes/class-wp-comment-query.php
Lines 774 to 781 in 860e5fa
get_lastcommentmodified() function. The SQL query is missing a comment-type filter. This should probably have been fixed in the WordPress 6.9 release.
wordpress-develop/src/wp-includes/comment.php
Lines 364 to 376 in 860e5fa
| $note_ids = array(); | ||
| foreach ( $query_result as $comment ) { | ||
| if ( 'note' === $comment->comment_type ) { | ||
| $note_ids[] = (int) $comment->comment_ID; | ||
| } | ||
| } |
There was a problem hiding this comment.
| $note_ids = array(); | |
| foreach ( $query_result as $comment ) { | |
| if ( 'note' === $comment->comment_type ) { | |
| $note_ids[] = (int) $comment->comment_ID; | |
| } | |
| } | |
| $note_ids = array_map( 'intval', wp_list_pluck( $query_result, 'comment_ID' ) ); |
Do we need to check for 'note' === $comment->comment_type here? Is it not guaranteed here that all comments are of type note?
| * | ||
| * @param string[] $types List of internal comment type slugs. | ||
| */ | ||
| return (array) apply_filters( 'wp_internal_comment_types', array( 'note', 'reaction' ) ); |
There was a problem hiding this comment.
I'm not sure what benefits this filter would bring to consumers 🤔
There was a problem hiding this comment.
i'm fine removing.
Apply review feedback from WordPress#10930: - Bump `@since 7.0.0` to `@since 7.1.0` on PR-introduced docblocks in comment.php, link-template.php, and class-wp-rest-comments-controller.php. - Remove the `wp_internal_comment_types` filter: as an internal helper, the list does not need to be filterable. - Apply `wp_get_internal_comment_types()` in `WP_Comment_Query` so all internal types (not just `note`) are excluded by default. - Exclude internal comment types from the `get_lastcommentmodified()` SQL queries so notes and reactions no longer affect the last modified date. - Move `wp_get_note_reaction_emojis()` into `WP_REST_Comments_Controller::get_note_reaction_emojis()` as a protected static method while the icon strategy is still in flux. - Simplify the reaction summary prefetch loop in `WP_REST_Comments_Controller::get_items()` with `wp_list_pluck`.
|
Thanks for the review @t-hamano! I've pushed f3b5af251b addressing the feedback:
Locally, the relevant test suites ( |
Summary
Introduces the
reactioncomment type to support emoji reactions on collaborative Notes, replacing the previous_wp_note_reactionsmeta approach from Gutenberg PR #75148 (now closed in favor of #75549).Each reaction is stored as a separate comment with
comment_type = 'reaction'rather than as serialized meta data on the note.Changes
reactionto the allowed avatar comment typesWP_REST_Comments_Controllerto handlereactiontype:edit_comment/edit_postinstead ofmoderate_comments)heart,celebration,smile,eyes,rocket), one emoji per user per notewp-api-generated.jsTrac ticket
See https://core.trac.wordpress.org/ticket/63191
Test plan
heartreaction to the note — should succeed (201)rocket) to the same note — should succeedphpunit --filter=test_create_reaction— all passphpunit tests/phpunit/tests/comment/wpUpdateCommentCountNow.php— all pass🤖 Generated with Claude Code