diff --git a/CHANGELOG.md b/CHANGELOG.md index ba6f9bb52..10c67ff83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed * Undefined array key warnings in various places +* @-mentions in federated comments being displayed with a line break * Fetching replies from the same instance for Enable Mastodon Apps * Image captions not being included in the ActivityPub representation when the image is attached to the post diff --git a/includes/transformer/class-comment.php b/includes/transformer/class-comment.php index f689b8cf2..9b1ec64ff 100644 --- a/includes/transformer/class-comment.php +++ b/includes/transformer/class-comment.php @@ -45,44 +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(); - $at_replies = ''; - $reply_context = $this->extract_reply_context( array() ); - - foreach ( $reply_context as $acct => $url ) { - $at_replies .= sprintf( - '%s ', - esc_url( $url ), - esc_html( $acct ) - ); - } - - $at_replies = trim( $at_replies ); - - if ( $at_replies ) { - $content = sprintf( '
%s
%s', $at_replies, $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. * @@ -107,8 +69,18 @@ protected function get_attributed_to() { * @return string The content. */ protected function get_content() { - $comment = $this->wp_object; - $content = $comment->comment_content; + $comment = $this->wp_object; + $content = $comment->comment_content; + $mentions = ''; + + foreach ( $this->extract_reply_context() as $acct => $url ) { + $mentions .= sprintf( + '%s ', + esc_url( $url ), + esc_html( $acct ) + ); + } + $content = $mentions . $content; /** * Filter the content of the comment. @@ -258,11 +230,11 @@ function ( $comment_id ) { * Collect all other Users that participated in this comment-thread * to send them a notification about the new reply. * - * @param array $mentions The already mentioned ActivityPub users. + * @param array $mentions Optional. The already mentioned ActivityPub users. Default empty array. * * @return array The list of all Repliers. */ - public function extract_reply_context( $mentions ) { + public function extract_reply_context( $mentions = array() ) { // Check if `$this->wp_object` is a WP_Comment. if ( 'WP_Comment' !== get_class( $this->wp_object ) ) { return $mentions; @@ -364,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(), + ); + } } diff --git a/readme.txt b/readme.txt index bdec5591f..e47085bc2 100644 --- a/readme.txt +++ b/readme.txt @@ -138,6 +138,7 @@ For reasons of data protection, it is not possible to see the followers of other * Changed: Hide ActivityPub post meta keys from the custom Fields UI * Changed: Bumped minimum required PHP version to 7.2 * Fixed: Undefined array key warnings in various places +* Fixed: @-mentions in federated comments being displayed with a line break * Fixed: Fetching replies from the same instance for Enable Mastodon Apps * Fixed: Image captions not being included in the ActivityPub representation when the image is attached to the post diff --git a/tests/includes/transformer/class-test-comment.php b/tests/includes/transformer/class-test-comment.php index a4a3efd73..f7dd29559 100644 --- a/tests/includes/transformer/class-test-comment.php +++ b/tests/includes/transformer/class-test-comment.php @@ -89,7 +89,7 @@ public function test_content_with_reply_context() { $content = $object->get_content(); // Test that reply context is added. - $this->assertEquals( '@remote@example.net @author@remote.example
This is a comment
', $content ); + $this->assertSame( '@remote@example.net @author@remote.example This is a comment
', $content ); // Clean up. wp_delete_comment( $reply_comment_id, true );