|
7 | 7 |
|
8 | 8 | namespace Activitypub\Integration; |
9 | 9 |
|
| 10 | +use Activitypub\Activity\Actor; |
10 | 11 | use Activitypub\Collection\Actors; |
11 | 12 | use Activitypub\Collection\Extra_Fields; |
12 | 13 | use Activitypub\Collection\Followers; |
@@ -362,82 +363,38 @@ private static function api_post_status( $post_id ) { |
362 | 363 | /** |
363 | 364 | * Get account for actor. |
364 | 365 | * |
365 | | - * @param string|\Activitypub\Activity\Actor $actor_or_uri The Actor object or URI. |
| 366 | + * @param string|Actor $actor_or_uri The Actor object or URI. |
366 | 367 | * |
367 | 368 | * @return Account|null The account. |
368 | 369 | */ |
369 | 370 | private static function get_account_for_actor( $actor_or_uri ) { |
370 | 371 | // If it's already an Actor object, use it directly. |
371 | | - if ( $actor_or_uri instanceof \Activitypub\Activity\Actor ) { |
| 372 | + if ( $actor_or_uri instanceof Actor ) { |
372 | 373 | return self::actor_to_account( $actor_or_uri ); |
373 | 374 | } |
374 | 375 |
|
375 | 376 | if ( ! \is_string( $actor_or_uri ) || empty( $actor_or_uri ) ) { |
376 | 377 | return null; |
377 | 378 | } |
378 | 379 |
|
379 | | - // Try to get cached actor first. |
380 | | - $actor = Remote_Actors::get_by_uri( $actor_or_uri ); |
381 | | - if ( $actor && ! \is_wp_error( $actor ) ) { |
382 | | - $actor_object = Remote_Actors::get_actor( $actor ); |
383 | | - if ( $actor_object && ! \is_wp_error( $actor_object ) ) { |
384 | | - return self::actor_to_account( $actor_object ); |
385 | | - } |
386 | | - } |
387 | | - |
388 | | - // Fall back to fetching remote metadata. |
389 | | - $data = get_remote_metadata_by_actor( $actor_or_uri ); |
390 | | - |
391 | | - if ( ! $data || \is_wp_error( $data ) ) { |
| 380 | + // Fetch actor from cache or remote. |
| 381 | + $actor_post = Remote_Actors::fetch_by_uri( $actor_or_uri ); |
| 382 | + if ( ! $actor_post || \is_wp_error( $actor_post ) ) { |
392 | 383 | return null; |
393 | 384 | } |
394 | 385 |
|
395 | | - $account = new Account(); |
396 | | - |
397 | | - $acct = Webfinger_Util::uri_to_acct( $actor_or_uri ); |
398 | | - if ( ! $acct || \is_wp_error( $acct ) ) { |
| 386 | + $actor = Remote_Actors::get_actor( $actor_post ); |
| 387 | + if ( ! $actor || \is_wp_error( $actor ) ) { |
399 | 388 | return null; |
400 | 389 | } |
401 | 390 |
|
402 | | - if ( \str_starts_with( $acct, 'acct:' ) ) { |
403 | | - $acct = \substr( $acct, 5 ); |
404 | | - } |
405 | | - |
406 | | - $account->id = $acct; |
407 | | - $account->username = $acct; |
408 | | - $account->acct = $acct; |
409 | | - $account->display_name = $data['name'] ?? ''; |
410 | | - $account->url = $actor_or_uri; |
411 | | - |
412 | | - if ( ! empty( $data['summary'] ) ) { |
413 | | - $account->note = $data['summary']; |
414 | | - } |
415 | | - |
416 | | - if ( |
417 | | - isset( $data['icon']['type'] ) && |
418 | | - isset( $data['icon']['url'] ) && |
419 | | - 'Image' === $data['icon']['type'] |
420 | | - ) { |
421 | | - $account->avatar = $data['icon']['url']; |
422 | | - $account->avatar_static = $data['icon']['url']; |
423 | | - } |
424 | | - |
425 | | - if ( isset( $data['image'] ) ) { |
426 | | - $account->header = $data['image']['url']; |
427 | | - $account->header_static = $data['image']['url']; |
428 | | - } |
429 | | - if ( ! isset( $data['published'] ) ) { |
430 | | - $data['published'] = 'now'; |
431 | | - } |
432 | | - $account->created_at = new \DateTime( $data['published'] ); |
433 | | - |
434 | | - return $account; |
| 391 | + return self::actor_to_account( $actor ); |
435 | 392 | } |
436 | 393 |
|
437 | 394 | /** |
438 | 395 | * Convert an Actor object to an Account. |
439 | 396 | * |
440 | | - * @param \Activitypub\Activity\Actor $actor The actor object. |
| 397 | + * @param Actor $actor The actor object. |
441 | 398 | * |
442 | 399 | * @return Account The account. |
443 | 400 | */ |
|
0 commit comments