add changes also to the object

This commit is contained in:
Matthias Pfefferle 2023-02-02 02:36:29 +01:00
parent 365d5dd499
commit de32cb7b73
5 changed files with 46 additions and 14 deletions

View file

@ -59,7 +59,7 @@ class Activity_Dispatcher {
// get latest version of post
$user_id = $activitypub_post->get_post_author();
$activitypub_activity = new \Activitypub\Model\Activity( $activity_type, \Activitypub\Model\Activity::TYPE_FULL );
$activitypub_activity = new \Activitypub\Model\Activity( $activity_type );
$activitypub_activity->from_post( $activitypub_post );
$inboxes = \Activitypub\get_follower_inboxes( $user_id, $activitypub_activity->get_cc() );

View file

@ -9,7 +9,27 @@ namespace Activitypub\Model;
* @see https://www.w3.org/TR/activitypub/
*/
class Activity {
private $context = array( 'https://www.w3.org/ns/activitystreams' );
private $context = array(
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
array(
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
'PropertyValue' => 'schema:PropertyValue',
'schema' => 'http://schema.org#',
'pt' => 'https://joinpeertube.org/ns#',
'toot' => 'http://joinmastodon.org/ns#',
'value' => 'schema:value',
'Hashtag' => 'as:Hashtag',
'featured' => array(
'@id' => 'toot:featured',
'@type' => '@id',
),
'featuredTags' => array(
'@id' => 'toot:featuredTags',
'@type' => '@id',
),
),
);
private $published = '';
private $id = '';
private $type = 'Create';
@ -18,15 +38,9 @@ class Activity {
private $cc = array();
private $object = null;
const TYPE_SIMPLE = 'simple';
const TYPE_FULL = 'full';
const TYPE_NONE = 'none';
public function __construct( $type = 'Create', $context = self::TYPE_SIMPLE ) {
if ( 'none' === $context ) {
public function __construct( $type = 'Create', $context = true ) {
if ( true !== $context ) {
$this->context = null;
} elseif ( 'full' === $context ) {
$this->context = \Activitypub\get_context();
}
$this->type = \ucfirst( $type );

View file

@ -87,6 +87,9 @@ class Post {
),
);
private $to = array( 'https://www.w3.org/ns/activitystreams#Public' );
private $cc = array();
/**
* Constructor
*
@ -94,6 +97,7 @@ class Post {
*/
public function __construct( $post ) {
$this->post = \get_post( $post );
$this->add_to( \get_rest_url( null, '/activitypub/1.0/users/' . intval( $this->get_post_author() ) . '/followers' ) );
}
/**
@ -117,6 +121,20 @@ class Post {
if ( \strncasecmp( $method, 'set', 3 ) === 0 ) {
$this->$var = $params[0];
}
if ( \strncasecmp( $method, 'add', 3 ) === 0 ) {
if ( ! is_array( $this->$var ) ) {
$this->$var = $params[0];
}
if ( is_array( $params[0] ) ) {
$this->$var = array_merge( $this->$var, $params[0] );
} else {
array_push( $this->$var, $params[0] );
}
$this->$var = array_unique( $this->$var );
}
}
/**
@ -138,8 +156,8 @@ class Post {
'contentMap' => array(
\strstr( \get_locale(), '_', true ) => $this->get_content(),
),
'to' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
'cc' => array( 'https://www.w3.org/ns/activitystreams#Public' ),
'to' => $this->get_to(),
'cc' => $this->get_cc(),
'attachment' => $this->get_attachments(),
'tag' => $this->get_tags(),
);

View file

@ -356,7 +356,7 @@ class Inbox {
$inbox = \Activitypub\get_inbox_by_actor( $object['actor'] );
// send "Accept" activity
$activity = new \Activitypub\Model\Activity( 'Accept', \Activitypub\Model\Activity::TYPE_SIMPLE );
$activity = new \Activitypub\Model\Activity( 'Accept' );
$activity->set_object( $object );
$activity->set_actor( \get_author_posts_url( $user_id ) );
$activity->set_to( $object['actor'] );

View file

@ -19,7 +19,7 @@ class Test_Activitypub_Activity extends WP_UnitTestCase {
$activitypub_post = new \Activitypub\Model\Post( $post );
$activitypub_activity = new \Activitypub\Model\Activity( 'Create', \Activitypub\Model\Activity::TYPE_FULL );
$activitypub_activity = new \Activitypub\Model\Activity( 'Create' );
$activitypub_activity->from_post( $activitypub_post );
$this->assertContains( \get_rest_url( null, '/activitypub/1.0/users/1/followers' ), $activitypub_activity->get_to() );