-
Notifications
You must be signed in to change notification settings - Fork 83
Replace get_remote_metadata_by_actor
with Remote_Actors::fetch_by_uri
#2225
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
Draft
pfefferle
wants to merge
4
commits into
trunk
Choose a base branch
from
change/remote-actor-fetch
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fef0a4a
Refactor Mention class to use Remote_Actors for actor data
pfefferle d51ef79
Refactor actor metadata handling in Interactions
pfefferle d46e93f
Fix mention username rendering and resolve actor URIs
pfefferle 552afb0
Merge branch 'trunk' into change/remote-actor-fetch
pfefferle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,12 @@ class Test_Mention extends \WP_UnitTestCase { | |
*/ | ||
public static $actors = array( | ||
'[email protected]' => array( | ||
'id' => 'https://example.org/users/username', | ||
'url' => 'https://example.org/users/username', | ||
'name' => 'username', | ||
'id' => 'https://example.org/users/username', | ||
'type' => 'Person', | ||
'url' => 'https://example.org/users/username', | ||
'name' => 'username', | ||
'preferredUsername' => 'username', | ||
'inbox' => 'https://example.org/users/username/inbox', | ||
), | ||
); | ||
|
||
|
@@ -34,15 +37,15 @@ class Test_Mention extends \WP_UnitTestCase { | |
*/ | ||
public function set_up() { | ||
parent::set_up(); | ||
add_filter( 'pre_get_remote_metadata_by_actor', array( get_called_class(), 'pre_get_remote_metadata_by_actor' ), 10, 2 ); | ||
add_filter( 'activitypub_pre_http_get_remote_object', array( get_called_class(), 'pre_get_remote_metadata_by_actor' ), 10, 2 ); | ||
add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); | ||
} | ||
|
||
/** | ||
* Tear down the test case. | ||
*/ | ||
public function tear_down() { | ||
remove_filter( 'pre_get_remote_metadata_by_actor', array( get_called_class(), 'pre_get_remote_metadata_by_actor' ) ); | ||
remove_filter( 'activitypub_pre_http_get_remote_object', array( get_called_class(), 'pre_get_remote_metadata_by_actor' ) ); | ||
remove_filter( 'pre_http_request', array( $this, 'pre_http_request' ) ); | ||
parent::tear_down(); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ public static function wpSetUpBeforeClass( $factory ) { | |
public function set_up() { | ||
parent::set_up(); | ||
|
||
\add_filter( 'pre_get_remote_metadata_by_actor', array( __CLASS__, 'get_remote_metadata_by_actor' ), 0, 2 ); | ||
\add_filter( 'activitypub_pre_http_get_remote_object', array( __CLASS__, 'get_remote_metadata_by_actor' ), 0, 2 ); | ||
} | ||
|
||
/** | ||
|
@@ -117,12 +117,14 @@ public static function wpTearDownAfterClass() { | |
*/ | ||
public static function get_remote_metadata_by_actor( $value, $actor ) { | ||
return array( | ||
'name' => 'Example User', | ||
'icon' => array( | ||
'name' => 'Example User', | ||
'type' => 'Person', | ||
'icon' => array( | ||
'url' => 'https://example.com/icon', | ||
), | ||
'url' => $actor, | ||
'id' => 'http://example.org/users/example', | ||
'url' => $actor, | ||
'id' => 'http://example.org/users/example', | ||
'inbox' => $actor . '/inbox', | ||
); | ||
} | ||
|
||
|
@@ -183,7 +185,7 @@ public function test_handle_create_basic() { | |
$this->assertEquals( self::$user_url, $basic_comment['comment_author_url'] ); | ||
$this->assertEquals( 'example', $basic_comment['comment_content'] ); | ||
$this->assertEquals( 'comment', $basic_comment['comment_type'] ); | ||
$this->assertEquals( '', $basic_comment['comment_author_email'] ); | ||
$this->assertEquals( '[email protected]', $basic_comment['comment_author_email'] ); | ||
$this->assertEquals( 0, $basic_comment['comment_parent'] ); | ||
$this->assertEquals( 'https://example.com/123', get_comment_meta( $basic_comment_id, 'source_id', true ) ); | ||
$this->assertEquals( 'https://example.com/example', get_comment_meta( $basic_comment_id, 'source_url', true ) ); | ||
|
@@ -337,7 +339,7 @@ public function test_add_comment_disabled_post() { | |
|
||
// Mock actor metadata. | ||
add_filter( | ||
'pre_get_remote_metadata_by_actor', | ||
'activitypub_pre_http_get_remote_object', | ||
function () { | ||
return array( | ||
'name' => 'Test User', | ||
|
@@ -353,7 +355,7 @@ function () { | |
$this->assertFalse( $result, 'Comment should not be added to disabled post' ); | ||
|
||
// Clean up. | ||
remove_all_filters( 'pre_get_remote_metadata_by_actor' ); | ||
remove_all_filters( 'activitypub_pre_http_get_remote_object' ); | ||
wp_delete_post( $disabled_post_id, true ); | ||
} | ||
|
||
|
@@ -375,7 +377,7 @@ public function test_add_comment_outbox_post() { | |
|
||
// Mock actor metadata. | ||
add_filter( | ||
'pre_get_remote_metadata_by_actor', | ||
'activitypub_pre_http_get_remote_object', | ||
function () { | ||
return array( | ||
'name' => 'Test User', | ||
|
@@ -390,7 +392,7 @@ function () { | |
$result = Interactions::add_comment( $activity ); | ||
$this->assertFalse( $result, 'Comment should not be added to disabled post' ); | ||
|
||
remove_all_filters( 'pre_get_remote_metadata_by_actor' ); | ||
remove_all_filters( 'activitypub_pre_http_get_remote_object' ); | ||
} | ||
|
||
/** | ||
|
@@ -418,7 +420,7 @@ public function test_add_reaction_disabled_post() { | |
|
||
// Mock actor metadata. | ||
add_filter( | ||
'pre_get_remote_metadata_by_actor', | ||
'activitypub_pre_http_get_remote_object', | ||
function () { | ||
return array( | ||
'name' => 'Test User', | ||
|
@@ -434,7 +436,7 @@ function () { | |
$this->assertFalse( $result, 'Reaction should not be added to disabled post' ); | ||
|
||
// Clean up. | ||
remove_all_filters( 'pre_get_remote_metadata_by_actor' ); | ||
remove_all_filters( 'activitypub_pre_http_get_remote_object' ); | ||
wp_delete_post( $disabled_post_id, true ); | ||
} | ||
|
||
|
@@ -453,7 +455,7 @@ public function test_add_reaction_outbox_post() { | |
|
||
// Mock actor metadata. | ||
add_filter( | ||
'pre_get_remote_metadata_by_actor', | ||
'activitypub_pre_http_get_remote_object', | ||
function () { | ||
return array( | ||
'name' => 'Test User', | ||
|
@@ -468,7 +470,7 @@ function () { | |
$result = Interactions::add_reaction( $activity ); | ||
$this->assertFalse( $result, 'Reaction should not be added to disabled post' ); | ||
|
||
remove_all_filters( 'pre_get_remote_metadata_by_actor' ); | ||
remove_all_filters( 'activitypub_pre_http_get_remote_object' ); | ||
} | ||
|
||
/** | ||
|
@@ -560,7 +562,7 @@ public function test_activity_to_comment_author() { | |
); | ||
|
||
// Mock actor metadata. | ||
\add_filter( 'pre_get_remote_metadata_by_actor', array( $this, 'actor_meta_data_comment_author' ), 10, 2 ); | ||
\add_filter( 'activitypub_pre_http_get_remote_object', array( $this, 'actor_meta_data_comment_author' ), 10, 2 ); | ||
|
||
// No name => preferredUsername. | ||
$comment_data = Interactions::activity_to_comment( $activity ); | ||
|
@@ -582,7 +584,7 @@ public function test_activity_to_comment_author() { | |
$comment_data = Interactions::activity_to_comment( $activity ); | ||
$this->assertSame( \__( 'Anonymous', 'activitypub' ), $comment_data['comment_author'] ); | ||
|
||
\remove_filter( 'pre_get_remote_metadata_by_actor', array( $this, 'actor_meta_data_comment_author' ) ); | ||
\remove_filter( 'activitypub_pre_http_get_remote_object', array( $this, 'actor_meta_data_comment_author' ) ); | ||
\update_option( 'require_name_email', '1' ); | ||
} | ||
|
||
|
@@ -597,26 +599,32 @@ public function test_activity_to_comment_author() { | |
public function actor_meta_data_comment_author( $response, $url ) { | ||
if ( 'https://example.com/users/tester_no_name' === $url ) { | ||
$response = array( | ||
'type' => 'Person', | ||
'name' => '', | ||
'preferredUsername' => 'test', | ||
'id' => 'https://example.com/users/test', | ||
'url' => 'https://example.com/@test', | ||
'inbox' => 'https://example.com/users/test/inbox', | ||
); | ||
} | ||
if ( 'https://example.com/users/tester_no_preferredUsername' === $url ) { | ||
$response = array( | ||
'type' => 'Person', | ||
'name' => 'Test User', | ||
'preferredUsername' => '', | ||
'id' => 'https://example.com/users/test', | ||
'url' => 'https://example.com/@test', | ||
'inbox' => 'https://example.com/users/test/inbox', | ||
); | ||
} | ||
if ( 'https://example.com/users/tester_anonymous' === $url ) { | ||
$response = array( | ||
'type' => 'Person', | ||
'name' => '', | ||
'preferredUsername' => '', | ||
'id' => 'https://example.com/users/test', | ||
'url' => 'https://example.com/@test', | ||
'inbox' => 'https://example.com/users/test/inbox', | ||
); | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.