Skip to content

Conversation

pfefferle
Copy link
Member

@pfefferle pfefferle commented Sep 25, 2025

Introduces fetch_by_acct to retrieve remote actor posts by acct identifier, resolving via Webfinger and fetching remotely if not found locally. Adds fetch_by_various to select between URI and acct-based fetching. Comprehensive tests for both methods are included, covering local, remote, and error scenarios.

In preparation to #2225

This PR introduces the least invasive change needed to cache all Actors in the ap_actor post type. It also adds the necessary functions to update the rest of the code and deprecates get_remote_metadata_by_actor.

Proposed changes:

  • Introduces fetch_by_acct method to retrieve actors via webfinger resolution of acct identifiers
  • Adds fetch_by_various method as a unified interface to select between URI and acct-based fetching
  • Updates get_remote_metadata_by_actor to use the new fetch_by_various method instead of direct HTTP calls

Other information:

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

Testing instructions:

  • Check unit tests

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

Added support for fetching actors by account identifiers and improved reliability of actor retrieval.

Introduces fetch_by_acct to retrieve remote actor posts by acct identifier, resolving via Webfinger and fetching remotely if not found locally. Adds fetch_by_various to select between URI and acct-based fetching. Comprehensive tests for both methods are included, covering local, remote, and error scenarios.
Improves input validation in Remote_Actors by checking if the identifier matches the expected username pattern before calling fetch_by_acct. Returns a WP_Error with status 400 if the identifier is invalid.
Replaces Http::get_remote_object with Remote_Actors::fetch_by_various for fetching remote actor metadata. Adds error handling for WP_Error and decodes the actor's post_content as JSON before returning. Also adds a phpcs ignore comment for unused variables.
@pfefferle pfefferle changed the title Add fetch_by_acct and fetch_by_various methods to Remote_Actors Add fetch_by_acct and fetch_by_various methods to Remote_Actors Sep 25, 2025
Copy link

@Copilot 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 adds new methods to fetch remote actors by different identifier types, enhancing the flexibility of actor retrieval in the ActivityPub plugin.

  • Introduces fetch_by_acct method to retrieve actors via webfinger resolution of acct identifiers
  • Adds fetch_by_various method as a unified interface to select between URI and acct-based fetching
  • Updates get_remote_metadata_by_actor to use the new fetch_by_various method instead of direct HTTP calls

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
includes/collection/class-remote-actors.php Implements new fetch_by_acct and fetch_by_various methods with webfinger resolution
includes/functions.php Updates get_remote_metadata_by_actor to use new actor fetching methods
tests/includes/collection/class-test-remote-actors.php Adds comprehensive test coverage for new methods including error scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@pfefferle pfefferle marked this pull request as ready for review September 25, 2025 10:39
@pfefferle
Copy link
Member Author

pfefferle commented Sep 25, 2025

I’m a bit surprised that replacing the logic of get_remote_metadata_by_actor was so easy. It was almost too easy 🥸

@pfefferle pfefferle self-assigned this Sep 25, 2025
Copy link
Member

@obenland obenland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat

@pfefferle pfefferle merged commit 5616349 into trunk Sep 25, 2025
13 checks passed
@pfefferle pfefferle deleted the add/fetch-by-acct branch September 25, 2025 13:56
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.

3 participants