Skip to content

Commit

Permalink
Address some of things found in #633 (#634)
Browse files Browse the repository at this point in the history
* Address some of things found in #633

* Improve "state"
  • Loading branch information
janboddez authored Jan 5, 2024
1 parent 4c297ac commit 6e5cb57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 7 additions & 3 deletions includes/collection/class-interactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function () {
*
* @param array $activity The activity-object
*
* @return array|false The commentdata or false on failure
* @return array|string|int|\WP_Error|false The commentdata or false on failure
*/
public static function update_comment( $activity ) {
$meta = get_remote_metadata_by_actor( $activity['actor'] );
Expand Down Expand Up @@ -135,14 +135,18 @@ function () {
);
\add_filter( 'wp_kses_allowed_html', array( self::class, 'allowed_comment_html' ), 10, 2 );

$comment = \wp_update_comment( $commentdata, true );
$state = \wp_update_comment( $commentdata, true );

\remove_filter( 'wp_kses_allowed_html', array( self::class, 'allowed_comment_html' ), 10 );
\remove_filter( 'pre_option_require_name_email', '__return_false' );
// re-add flood control
\add_action( 'check_comment_flood', 'check_comment_flood_db', 10, 4 );

return $comment;
if ( 1 === $state ) {
return $commentdata;
} else {
return $state; // Either `false` or a `WP_Error` instance or `0` or `1`!
}
}

/**
Expand Down
11 changes: 7 additions & 4 deletions includes/handler/class-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ public static function handle_update( $array ) {
* @return void
*/
public static function update_interaction( $activity ) {
$state = Interactions::update_comment( $activity );
$reaction = null;
$commentdata = Interactions::update_comment( $activity );
$reaction = null;

if ( $state && ! \is_wp_error( $reaction ) ) {
$reaction = \get_comment( $state );
if ( ! empty( $commentdata['comment_ID'] ) ) {
$state = 1;
$reaction = \get_comment( $commentdata['comment_ID'] );
} else {
$state = $commentdata;
}

\do_action( 'activitypub_handled_update', $activity, null, $state, $reaction );
Expand Down

0 comments on commit 6e5cb57

Please sign in to comment.