Skip to content
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

Comments: Show @-mentions in line with reply #1137

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
simplify code even more
pfefferle committed Jan 10, 2025
commit ef6ce3ca00f30a0a25b5dae46bcb3055c4cd63f6
34 changes: 12 additions & 22 deletions includes/transformer/class-comment.php
Original file line number Diff line number Diff line change
@@ -45,27 +45,6 @@ public function change_wp_user_id( $user_id ) {
$this->wp_object->user_id = $user_id;
}

/**
* Transforms the WP_Comment object to an ActivityPub Object.
*
* @see \Activitypub\Activity\Base_Object
*
* @return \Activitypub\Activity\Base_Object The ActivityPub Object.
*/
public function to_object() {
$object = parent::to_object();
$content = $this->get_content();

$object->set_content( $content );
$object->set_content_map(
array(
$this->get_locale() => $content,
)
);

return $object;
}

/**
* Returns the User-URL of the Author of the Post.
*
@@ -96,7 +75,7 @@ protected function get_content() {

foreach ( $this->extract_reply_context() as $acct => $url ) {
$mentions .= sprintf(
'<a class="u-mention mention" href="%s">%s</a> ',
'<a rel="mention" class="u-url mention" href="%s">%s</a> ',
esc_url( $url ),
esc_html( $acct )
);
@@ -357,4 +336,15 @@ public function get_to() {
get_rest_url_by_path( $path ),
);
}

/**
* Returns the content map for the comment.
*
* @return array The content map for the comment.
*/
public function get_content_map() {
return array(
$this->get_locale() => $this->get_content(),
);
}
}
2 changes: 1 addition & 1 deletion tests/includes/transformer/class-test-comment.php
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ public function test_content_with_reply_context() {
$content = $object->get_content();

// Test that reply context is added.
$this->assertSame( '<p><a class="u-mention mention" href="https://example.net/@remote">@remote@example.net</a> <a class="u-mention mention" href="https://remote.example/@author">@author@remote.example</a> This is a comment</p>', $content );
$this->assertSame( '<p><a rel="mention" class="u-url mention" href="https://example.net/@remote">@remote@example.net</a> <a rel="mention" class="u-url mention" href="https://remote.example/@author">@author@remote.example</a> This is a comment</p>', $content );

// Clean up.
wp_delete_comment( $reply_comment_id, true );