-
Notifications
You must be signed in to change notification settings - Fork 83
Add undo support for Like and Announce activities #2295
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
Conversation
Performance improvements: - Replace array_diff() + array_keys() with isset() checks (faster, no temporary arrays) - Simplify object validation from empty() || !is_array() to !isset() || !is_array() - Remove unnecessary is_wp_error() checks (request is always WP_REST_Request) Code quality improvements: - Rename $json_params to $activity for better readability - Align validation patterns across all handlers for consistency - Improve docblock formatting in REST controllers All existing tests pass.
Extended the inbox collection to support undoing Like, Create, and Announce activities, in addition to Follow. Refactored undo logic into the Inbox collection and updated the handler to use this new method. Also updated the list of activity types persisted in the inbox to include Like and Announce.
Updated the handle_undo method to check for WP_Error when processing the result from Inbox_Collection::undo. This ensures $success is only true if the operation succeeded and did not return a WP_Error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR extends undo support for ActivityPub to handle Like, Create, and Announce activities in addition to Follow activities. The main change refactors undo logic from the handler into the Inbox collection class for better organization and maintainability.
- Refactored undo logic from handler to Inbox collection for better code organization
- Extended activity type persistence to include Like and Announce activities
- Added new method
get_by_guid()to support undo operations
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| includes/handler/class-undo.php | Simplified handler by delegating undo logic to Inbox collection and removed validation |
| includes/handler/class-inbox.php | Added Like and Announce to persisted activity types filter |
| includes/collection/class-inbox.php | Added undo method and get_by_guid helper to handle undo operations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Simplifies the retrieval of the remote actor and user ID for 'Follow' activities by using post meta values instead of parsing the activity JSON. This reduces complexity and potential errors in the process.
Added a check to ensure that the 'object' parameter in the Undo handler contains the required attributes ('id', 'type', 'actor', 'object') when it is an array. This improves input validation and prevents processing of incomplete objects.
…8n in advanced settings (#2290)
Updated the Undo handler to allow 'object' to be either an array with an 'id' or a string, removing the requirement for 'type', 'actor', and 'object' fields in the object array. Adjusted and expanded related unit tests to reflect the new validation logic.
Refactored Inbox::undo to avoid accessing post meta if the post is not found, preventing errors. Updated the test to include an 'id' field in the 'object' array for better coverage.
Improves the Inbox::undo method to better handle error cases and unsupported activity types, and refactors the Undo handler tests to simulate real ActivityPub flows for Follow, Like, Create, and Announce activities. The tests now add activities to the inbox and invoke handlers directly, ensuring more accurate coverage and validation of Undo logic.
Co-authored-by: Konstantin Obenland <[email protected]>
Streamlines Undo handler tests by removing unnecessary setup, direct inbox simulation, and redundant activity creation. Updates comment undo tests to use direct comment creation and metadata, and adjusts validation test cases to expect failures for missing required fields. Renames and simplifies data providers for clarity.
Updated Undo handler tests to simulate ActivityPub activities (Follow, Like, Announce, etc.) through the inbox and handler methods, rather than directly manipulating followers or comments. This improves test realism and coverage for activity-based flows, and updates validation tests to reflect current requirements.
Updated the error message to specify the activity type when Undo is not supported, providing clearer feedback to users.
Added blank lines after return statements in the switch cases of the Inbox class for improved code readability.
Renamed variable $post to $inbox_item in the Inbox::undo method for improved clarity and consistency. No functional changes were made.
Renamed variable $post to $remote_actor in the 'Follow' case to better reflect its purpose and improve code readability. Updated all related references accordingly.
Co-authored-by: Konstantin Obenland <[email protected]>
Added blank lines in docblocks for better readability and consistency in the Collection trait methods.
Extended the inbox collection to support undoing Like, Create, and Announce activities, in addition to Follow. Refactored undo logic into the Inbox collection and updated the handler to use this new method. Also updated the list of activity types persisted in the inbox to include Like and Announce.
Supersedes #2284
See #2278
Proposed changes:
get_by_guid()to support undo operationsOther information:
Testing instructions:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Extended inbox support for undoing Like, Create, and Announce activities, with refactored undo logic and improved activity persistence.