Skip to content

Conversation

@pfefferle
Copy link
Member

@pfefferle pfefferle commented Oct 6, 2025

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:

  • 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

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • See unittests

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Extended inbox support for undoing Like, Create, and Announce activities, with refactored undo logic and improved activity persistence.

obenland and others added 2 commits October 2, 2025 16:22
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.
@pfefferle pfefferle requested a review from Copilot October 6, 2025 13:25
Copy link

Copilot AI left a 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.

pfefferle and others added 4 commits October 6, 2025 15:27
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.
@pfefferle pfefferle changed the base branch from trunk to optimize-validate-object-functions October 6, 2025 14:11
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.
Base automatically changed from optimize-validate-object-functions to trunk October 6, 2025 14:37
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.
@pfefferle pfefferle marked this pull request as ready for review October 6, 2025 18:21
@pfefferle pfefferle requested a review from obenland October 6, 2025 18:21
pfefferle and others added 8 commits October 7, 2025 08:57
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.
@pfefferle pfefferle requested a review from obenland October 7, 2025 07:05
@pfefferle pfefferle requested a review from obenland October 7, 2025 13:45
Added blank lines in docblocks for better readability and consistency in the Collection trait methods.
@pfefferle pfefferle merged commit 9a2ec6c into trunk Oct 7, 2025
13 checks passed
@pfefferle pfefferle deleted the add/inbox-undo branch October 7, 2025 14:50
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.

5 participants