Skip to content

Commit

Permalink
Don't override ActivityPub mentions (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Aug 23, 2024
1 parent 0e3ee0e commit 93918cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ public static function get_possible_mentions() {
*/
public function activitypub_extract_mentions( $mentions, $post_content ) {
$users = self::get_possible_mentions();
preg_match_all( '/@(?:[a-zA-Z0-9_-]+)/', $post_content, $matches );
preg_match_all( '/@(?:[a-zA-Z0-9_@.-]+)/', $post_content, $matches );
foreach ( $matches[0] as $match ) {
if ( isset( $users[ $match ] ) ) {
$mentions[ $match ] = $users[ $match ];
Expand Down
30 changes: 30 additions & 0 deletions tests/test-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,36 @@ public function test_friend_mentions() {
\wp_trash_post( $post_id );
}

public function test_dont_override_activitypub_mentions() {
add_filter( 'activitypub_cache_possible_friend_mentions', '__return_false' );
$post_id = \wp_insert_post(
array(
'post_author' => 1,
'post_content' => '@' . sanitize_title( $this->friend_nicename ) . '@mastodon.social hello',
)
);

$activitypub_post = new \Activitypub\Transformer\Post( get_post( $post_id ) );
$object = $activitypub_post->to_object();

$this->assertNotContains(
array(
'type' => 'Mention',
'href' => $this->actor,
'name' => '@' . $this->friend_nicename,
),
$object->get_tag()
);

$this->assertContains( \get_rest_url( null, '/activitypub/1.0/users/1/followers' ), $object->get_to() );
$this->assertNotContains( $this->actor, $object->get_cc() );

remove_all_filters( 'activitypub_from_post_object' );
remove_all_filters( 'activitypub_cache_possible_friend_mentions' );

\wp_trash_post( $post_id );
}

/**
* Test whether the example domains are skipped.
*/
Expand Down

0 comments on commit 93918cb

Please sign in to comment.