Save actor that we received an event from to post meta
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 50s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m8s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m5s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m8s

This commit is contained in:
André Menrath 2025-01-02 20:03:53 +01:00
parent 674552513b
commit 5f41ccdc42
4 changed files with 9 additions and 8 deletions

View file

@ -70,6 +70,6 @@ class Create {
return; return;
} }
$transmogrifier->save( $activity['object'] ); $transmogrifier->save( $activity['object'], $activity['actor'] );
} }
} }

View file

@ -42,7 +42,6 @@ class Update {
} }
// Check that we are actually following this actor. // Check that we are actually following this actor.
if ( ! Event_Sources::actor_is_event_source( $activity['actor'] ) ) { if ( ! Event_Sources::actor_is_event_source( $activity['actor'] ) ) {
return; return;
} }
@ -67,6 +66,6 @@ class Update {
return; return;
} }
$transmogrifier->save( $activity['object'] ); $transmogrifier->save( $activity['object'], $activity['actor'] );
} }
} }

View file

@ -97,7 +97,7 @@ class Event_Source extends Actor {
* Get the Event Source by the ActivityPub ID. * Get the Event Source by the ActivityPub ID.
* *
* @param string $actor_id The ActivityPub actor ID. * @param string $actor_id The ActivityPub actor ID.
* @return Event_Source|false The Event Source Actor, if a WordPress Post representing it is found, false otherwise. * @return Event_Source|WP_Error|false The Event Source Actor, if a WordPress Post representing it is found, false otherwise.
*/ */
public static function get_by_id( $actor_id ) { public static function get_by_id( $actor_id ) {
$post = self::get_wp_post_by_activitypub_actor_id( $actor_id ); $post = self::get_wp_post_by_activitypub_actor_id( $actor_id );

View file

@ -26,7 +26,7 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
*/ */
abstract class Base { abstract class Base {
/** /**
* The current GatherPress Event object. * The current Event object.
* *
* @var Event * @var Event
*/ */
@ -40,11 +40,12 @@ abstract class Base {
abstract protected function save_event(); abstract protected function save_event();
/** /**
* Save the ActivityPub event object as GatherPress Event. * Save the ActivityPub event object within WordPress.
* *
* @param array $activitypub_event The ActivityPub event as associative array. * @param array $activitypub_event The ActivityPub event as associative array.
* @param ?string $actor The ActivityPub ID of the actor which we received the event from.
*/ */
public function save( $activitypub_event ) { public function save( $activitypub_event, $actor ) {
$activitypub_event = Event::init_from_array( $activitypub_event ); $activitypub_event = Event::init_from_array( $activitypub_event );
if ( is_wp_error( $activitypub_event ) ) { if ( is_wp_error( $activitypub_event ) ) {
@ -57,6 +58,7 @@ abstract class Base {
if ( $post_id ) { if ( $post_id ) {
update_post_meta( $post_id, '_event_bridge_for_activitypub_is_remote_cached', true ); update_post_meta( $post_id, '_event_bridge_for_activitypub_is_remote_cached', true );
update_post_meta( $post_id, '_event_bridge_for_activitypub_event_source', sanitize_url( $actor ) );
update_post_meta( $post_id, 'activitypub_content_visibility', constant( 'ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL' ) ?? '' ); update_post_meta( $post_id, 'activitypub_content_visibility', constant( 'ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL' ) ?? '' );
} }
} }