| @@ -6,10 +6,10 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace Activitypub\Handler; |
| 9 | 9 | |
| 10 | +use Activitypub\Comment; | |
| 10 | 11 | use Activitypub\Collection\Interactions; |
| 11 | -use Activitypub\Comment; | |
| 12 | 12 | |
| 13 | 13 | use function Activitypub\object_to_uri; |
| 14 | 14 | |
| 15 | 15 | /** |
| @@ -26,12 +26,12 @@ | ||
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * Handles "Like" requests. |
| 29 | 29 | * |
| 30 | - * @param array $like The Activity array. | |
| 31 | - * @param int|int[] $user_ids The user ID(s). | |
| 30 | + * @param array $like The Activity array. | |
| 31 | + * @param int $user_id The ID of the local blog user. | |
| 32 | 32 | */ |
| 33 | - public static function handle_like( $like, $user_ids ) { | |
| 33 | + public static function handle_like( $like, $user_id ) { | |
| 34 | 34 | if ( ! Comment::is_comment_type_enabled( 'like' ) ) { |
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | 37 | |
| @@ -40,36 +40,29 @@ | ||
| 40 | 40 | if ( empty( $url ) ) { |
| 41 | 41 | return; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - /* | |
| 45 | - * Dedupe on the Like activity ID (its source_id), not the liked object, so repeat | |
| 46 | - * deliveries stay idempotent even when a mangled author name defeats WordPress's own | |
| 47 | - * duplicate check. Match any status, so a like that was marked as spam or trashed | |
| 48 | - * still counts as seen. See https://github.com/Automattic/wordpress-activitypub/issues/3215. | |
| 49 | - */ | |
| 50 | - $exists = Comment::object_id_to_comment( \esc_url_raw( object_to_uri( $like ) ), array( 'status' => 'any' ) ); | |
| 44 | + $exists = Comment::object_id_to_comment( esc_url_raw( $url ) ); | |
| 51 | 45 | if ( $exists ) { |
| 52 | 46 | return; |
| 53 | 47 | } |
| 54 | 48 | |
| 55 | - $success = false; | |
| 56 | - $result = Interactions::add_reaction( $like ); | |
| 49 | + $state = Interactions::add_reaction( $like ); | |
| 50 | + $reaction = null; | |
| 57 | 51 | |
| 58 | - if ( $result && ! \is_wp_error( $result ) ) { | |
| 59 | - $success = true; | |
| 60 | - $result = \get_comment( $result ); | |
| 52 | + if ( $state && ! is_wp_error( $state ) ) { | |
| 53 | + $reaction = get_comment( $state ); | |
| 61 | 54 | } |
| 62 | 55 | |
| 63 | 56 | /** |
| 64 | - * Fires after an ActivityPub Like activity has been handled. | |
| 57 | + * Fires after a Like has been handled. | |
| 65 | 58 | * |
| 66 | - * @param array $like The ActivityPub activity data. | |
| 67 | - * @param int[] $user_ids The local user IDs. | |
| 68 | - * @param bool $success True on success, false otherwise. | |
| 69 | - * @param array|false|int|string|\WP_Comment|\WP_Error $result The WP_Comment object of the created like comment, or null if creation failed. | |
| 59 | + * @param array $like The Activity array. | |
| 60 | + * @param int $user_id The ID of the local blog user. | |
| 61 | + * @param mixed $state The state of the reaction. | |
| 62 | + * @param mixed $reaction The reaction object. | |
| 70 | 63 | */ |
| 71 | - \do_action( 'activitypub_handled_like', $like, (array) $user_ids, $success, $result ); | |
| 64 | + do_action( 'activitypub_handled_like', $like, $user_id, $state, $reaction ); | |
| 72 | 65 | } |
| 73 | 66 | |
| 74 | 67 | /** |
| 75 | 68 | * Set the object to the object ID. |