fix tests
This commit is contained in:
parent
d4fb683965
commit
7f3059427d
2 changed files with 30 additions and 21 deletions
|
@ -30,11 +30,11 @@ class Activity_Dispatcher {
|
|||
* Send Activities to followers and mentioned users.
|
||||
*
|
||||
* @param WP_Post $wp_post The ActivityPub Post.
|
||||
* @param string $activity_type The Activity-Type.
|
||||
* @param string $type The Activity-Type.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function send_user_activity( WP_Post $wp_post, $activity_type ) {
|
||||
public static function send_user_activity( WP_Post $wp_post, $type ) {
|
||||
// check if a migration is needed before sending new posts
|
||||
Migration::maybe_migrate();
|
||||
|
||||
|
@ -42,22 +42,23 @@ class Activity_Dispatcher {
|
|||
return;
|
||||
}
|
||||
|
||||
$post = new Post( $wp_post );
|
||||
$object = Post::transform( $wp_post )->to_object();
|
||||
|
||||
$activitypub_activity = new Activity( $activity_type );
|
||||
$activitypub_activity->from_post( $post );
|
||||
$activity = new Activity();
|
||||
$activity->set_type( $type );
|
||||
$activity->set_object( $object );
|
||||
|
||||
$user_id = $wp_post->post_author;
|
||||
$follower_inboxes = Followers::get_inboxes( $user_id );
|
||||
$mentioned_inboxes = Mention::get_inboxes( $activitypub_activity->get_cc() );
|
||||
$mentioned_inboxes = Mention::get_inboxes( $activity->get_cc() );
|
||||
|
||||
$inboxes = array_merge( $follower_inboxes, $mentioned_inboxes );
|
||||
$inboxes = array_unique( $inboxes );
|
||||
|
||||
$array = $activity->to_json();
|
||||
$json = $activity->to_json();
|
||||
|
||||
foreach ( $inboxes as $inbox ) {
|
||||
safe_remote_post( $inbox, $array, $user_id );
|
||||
safe_remote_post( $inbox, $json, $user_id );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,11 +66,11 @@ class Activity_Dispatcher {
|
|||
* Send Activities to followers and mentioned users.
|
||||
*
|
||||
* @param WP_Post $wp_post The ActivityPub Post.
|
||||
* @param string $activity_type The Activity-Type.
|
||||
* @param string $type The Activity-Type.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function send_blog_activity( WP_Post $wp_post, $activity_type ) {
|
||||
public static function send_blog_activity( WP_Post $wp_post, $type ) {
|
||||
// check if a migration is needed before sending new posts
|
||||
Migration::maybe_migrate();
|
||||
|
||||
|
@ -77,22 +78,26 @@ class Activity_Dispatcher {
|
|||
return;
|
||||
}
|
||||
|
||||
$post = new Post( $wp_post, User_Factory::BLOG_USER_ID );
|
||||
$user = User_Factory::get_user( User_Factory::BLOG_USER_ID );
|
||||
|
||||
$activitypub_activity = new Activity( $activity_type );
|
||||
$activitypub_activity->from_post( $post );
|
||||
$object = Post::transform( $wp_post )->to_object();
|
||||
$object->set_attributed_to( $user->get_id() );
|
||||
|
||||
$activity = new Activity();
|
||||
$activity->set_type( $type );
|
||||
$activity->set_object( $object );
|
||||
|
||||
$user_id = User_Factory::BLOG_USER_ID;
|
||||
$follower_inboxes = Followers::get_inboxes( $user_id );
|
||||
$mentioned_inboxes = Mention::get_inboxes( $activitypub_activity->get_cc() );
|
||||
$mentioned_inboxes = Mention::get_inboxes( $activity->get_cc() );
|
||||
|
||||
$inboxes = array_merge( $follower_inboxes, $mentioned_inboxes );
|
||||
$inboxes = array_unique( $inboxes );
|
||||
|
||||
$array = $activity->to_json();
|
||||
$json = $activity->to_json();
|
||||
|
||||
foreach ( $inboxes as $inbox ) {
|
||||
safe_remote_post( $inbox, $array, $user_id );
|
||||
safe_remote_post( $inbox, $json, $user_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,27 @@
|
|||
<?php
|
||||
namespace Activitypub;
|
||||
|
||||
use Activitypub\Http;
|
||||
use Activitypub\Activity\Activity;
|
||||
use Activitypub\Collection\Followers;
|
||||
|
||||
/**
|
||||
* Returns the ActivityPub default JSON-context
|
||||
*
|
||||
* @return array the activitypub context
|
||||
*/
|
||||
function get_context() {
|
||||
$context = Model\Activity::CONTEXT;
|
||||
$context = Activity::CONTEXT;
|
||||
|
||||
return \apply_filters( 'activitypub_json_context', $context );
|
||||
}
|
||||
|
||||
function safe_remote_post( $url, $body, $user_id ) {
|
||||
return \Activitypub\Http::post( $url, $body, $user_id );
|
||||
return Http::post( $url, $body, $user_id );
|
||||
}
|
||||
|
||||
function safe_remote_get( $url ) {
|
||||
return \Activitypub\Http::get( $url );
|
||||
return Http::get( $url );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,7 +110,7 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
|
|||
* @return array The followers.
|
||||
*/
|
||||
function get_followers( $user_id ) {
|
||||
return Collection\Followers::get_followers( $user_id );
|
||||
return Followers::get_followers( $user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +121,7 @@ function get_followers( $user_id ) {
|
|||
* @return int The number of followers.
|
||||
*/
|
||||
function count_followers( $user_id ) {
|
||||
return Collection\Followers::count_followers( $user_id );
|
||||
return Followers::count_followers( $user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue