-
Notifications
You must be signed in to change notification settings - Fork 83
Add relay mode for ActivityPub federation #2560
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
base: trunk
Are you sure you want to change the base?
Conversation
Refactors the relay mode implementation for better code organization: - Moves relay_mode_changed() method from Relay class to Options class where other option-related hooks are handled - Removes Relay::init() method as it's no longer needed - Removes Relay::init() call from activitypub.php - Reorganizes tests: relay mode option tests moved to Test_Options, Blog actor type test moved to Test_Blog - Keeps only core relay functionality tests (should_relay, forward_activity) in Test_Relay This follows the existing pattern where Options class handles option change hooks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…tion Changes the relay implementation to hook into activitypub_handled_* actions rather than modifying handlers directly: - Adds Relay::init() method that hooks into handled_create, handled_update, handled_delete, and handled_announce actions - Adds Relay::handle_activity() method that checks conditions and relays - Uses existing is_activity_public() function instead of custom implementation - Removes forwarding code from individual handlers - Updates tests to test handle_activity method instead of should_relay
Improvements to the relay implementation: - Check relay mode in init() to only add hooks when relay is enabled - Pass activity array directly to forward_activity instead of converting to object - Remove manual ID generation for Announce, let outbox handle it - Update tests to match new implementation
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 adds relay mode functionality to enable the ActivityPub blog actor to forward public activities to all followers. However, the implementation has critical bugs that will cause fatal errors when the handlers execute. The handlers attempt to call Relay::should_relay() and Relay::forward_activity() methods that don't exist in the Relay class.
Key Changes
- Add relay mode toggle in advanced settings with comprehensive warnings about resource usage
- Implement relay functionality using action hooks that fire after activities are handled
- Change blog actor type from Group/Person to Service when relay mode is enabled
- Automatic option management: sets blog-only mode and 'relay' identifier when enabled, restores on disable
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| includes/class-relay.php | NEW - Implements relay functionality by hooking into activitypub_handled_* actions to wrap and forward public activities as Announce activities |
| includes/class-options.php | Adds relay_mode_changed() hook handler to automatically configure blog-only mode and relay identifier when relay mode is toggled |
| includes/model/class-blog.php | Changes blog actor type to 'Service' when relay mode is enabled (before Person/Group logic) |
| includes/handler/class-create.php | BROKEN - Calls non-existent Relay::should_relay() and Relay::forward_activity() methods |
| includes/handler/class-update.php | BROKEN - Calls non-existent Relay::should_relay() and Relay::forward_activity() methods |
| includes/handler/class-delete.php | BROKEN - Calls non-existent Relay::should_relay() and Relay::forward_activity() methods |
| includes/handler/class-announce.php | BROKEN - Calls non-existent Relay::should_relay() and Relay::forward_activity() methods |
| includes/wp-admin/class-settings.php | Registers the activitypub_relay_mode boolean setting |
| includes/wp-admin/class-advanced-settings-fields.php | Adds UI field for relay mode with detailed warnings about implications |
| activitypub.php | Adds Relay::init() to initialization sequence |
| tests/phpunit/tests/includes/class-test-relay.php | NEW - Comprehensive test coverage for relay functionality (6 test cases) |
| tests/phpunit/tests/includes/class-test-options.php | Tests for automatic option management when relay mode is toggled |
| tests/phpunit/tests/includes/model/class-test-blog.php | Tests that blog actor type changes to Service in relay mode |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
The activitypub_relay_mode setting was registered with the 'activitypub' option group, but the advanced settings form uses 'activitypub_advanced'. This caused the setting to not be saved when the form was submitted.
- Hide 'Change Profile ID' field from Blog Profile settings when relay mode is active - Prevent blog identifier from being changed via sanitize callback when relay mode is enabled - Ensures the identifier stays as 'relay' when relay mode is on
Changed 'activitypub_relay_mode' option to use string values ('0' and '1') instead of booleans in both the settings field and related tests. This ensures consistent handling and comparison of the option throughout the codebase.
When relay mode is active, remove all settings sections and fields except moderation from the Settings page using WordPress globals to simplify the interface and prevent changes to incompatible options.
67aaaa6 to
ccdd6ed
Compare
|
@obenland the idea was, to use the plugin, to run a WordPress (or Full-Article) relay, that can be added as default for at least WordPress.com blogs. The question is how well that scales on high load. |
so how would a WordPress plugin dev implement a relay? 😉
Proposed changes:
This PR adds relay mode functionality to the ActivityPub plugin. When enabled, the blog actor automatically forwards all public activities it receives to all its followers, functioning as an ActivityPub relay server.
Other information:
Testing instructions:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Add relay mode to forward public activities to all followers.