| @@ -7,12 +7,12 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace Activitypub\Handler; |
| 9 | 9 | |
| 10 | 10 | use Activitypub\Collection\Interactions; |
| 11 | +use Activitypub\Collection\Posts; | |
| 11 | 12 | use Activitypub\Collection\Remote_Actors; |
| 12 | -use Activitypub\Collection\Remote_Posts; | |
| 13 | -use Activitypub\Http; | |
| 14 | 13 | |
| 14 | +use function Activitypub\get_remote_metadata_by_actor; | |
| 15 | 15 | use function Activitypub\is_activity_reply; |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Handle Update requests. |
| @@ -94,9 +94,9 @@ | ||
| 94 | 94 | } elseif ( ! empty( $comment_data['comment_ID'] ) ) { |
| 95 | 95 | $result = \get_comment( $comment_data['comment_ID'] ); |
| 96 | 96 | } |
| 97 | 97 | } elseif ( \get_option( 'activitypub_create_posts', false ) ) { |
| 98 | - $result = Remote_Posts::update( $activity, $user_ids ); | |
| 98 | + $result = Posts::update( $activity, $user_ids ); | |
| 99 | 99 | |
| 100 | 100 | if ( \is_wp_error( $result ) && 'activitypub_post_not_found' === $result->get_error_code() ) { |
| 101 | 101 | $updated = false; |
| 102 | 102 | } |
| @@ -126,34 +126,15 @@ | ||
| 126 | 126 | * @param array $activity The Activity object. |
| 127 | 127 | * @param int[]|null $user_ids The user IDs. Always null for Update activities. |
| 128 | 128 | */ |
| 129 | 129 | public static function update_actor( $activity, $user_ids ) { |
| 130 | - /* | |
| 131 | - * Prefer the actor data embedded in the activity object, as it contains | |
| 132 | - * the fresh data sent by the remote server. | |
| 133 | - */ | |
| 134 | - $actor = $activity['object'] ?? null; | |
| 130 | + // Update cache. | |
| 131 | + $actor = get_remote_metadata_by_actor( $activity['actor'], false ); | |
| 135 | 132 | |
| 136 | - /* | |
| 137 | - * The object may be a string IRI instead of an embedded object, | |
| 138 | - * in which case we need to fetch the actor data remotely. | |
| 139 | - * We use Http::get_remote_object() directly instead of | |
| 140 | - * get_remote_metadata_by_actor() because the latter returns the | |
| 141 | - * stale locally cached copy via fetch_by_uri(). | |
| 142 | - */ | |
| 143 | - if ( ! \is_array( $actor ) || ! isset( $actor['id'] ) ) { | |
| 144 | - $object = Http::get_remote_object( $activity['actor'], false ); | |
| 145 | - | |
| 146 | - if ( ! \is_wp_error( $object ) && \is_array( $object ) ) { | |
| 147 | - $actor = $object; | |
| 148 | - } | |
| 149 | - } | |
| 150 | - | |
| 151 | - if ( \is_array( $actor ) && isset( $actor['id'] ) ) { | |
| 133 | + if ( ! $actor || \is_wp_error( $actor ) || ! isset( $actor['id'] ) ) { | |
| 134 | + $state = new \WP_Error( 'activitypub_update_failed', 'Update failed: could not fetch actor data' ); | |
| 135 | + } else { | |
| 152 | 136 | $state = Remote_Actors::upsert( $actor ); |
| 153 | - } else { | |
| 154 | - $state = new \WP_Error( 'activitypub_update_failed', 'Update failed: missing or invalid actor object in Update activity' ); | |
| 155 | - $actor = array(); | |
| 156 | 137 | } |
| 157 | 138 | |
| 158 | 139 | /** |
| 159 | 140 | * Fires after an ActivityPub Update activity has been handled. |