send user and blog activities

and set the blog to "single-mode"
This commit is contained in:
Matthias Pfefferle 2023-05-25 13:55:18 +02:00
parent f8b93760df
commit 3feef1e8cf
3 changed files with 33 additions and 2 deletions

View file

@ -28,6 +28,7 @@ function init() {
\defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' );
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<strong>[ap_title]</strong>\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" );
\defined( 'ACTIVITYPUB_SECURE_MODE' ) || \define( 'ACTIVITYPUB_SECURE_MODE', apply_filters( 'activitypub_secure_mode', $value = false ) );
\defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) || \define( 'ACTIVITYPUB_SINGLE_USER_MODE', false );
\define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

View file

@ -3,6 +3,7 @@ namespace Activitypub;
use Activitypub\Model\Post;
use Activitypub\Model\Activity;
use Activitypub\User_Factory;
use Activitypub\Collection\Followers;
use function Activitypub\safe_remote_post;
@ -66,12 +67,32 @@ class Activity_Dispatcher {
// check if a migration is needed before sending new posts
Migration::maybe_migrate();
if ( ! is_single_user_mode() ) {
// send User-Activity
self::send_user_activity( $activitypub_post, $activity_type );
}
// send Blog-User-Activity
self::send_user_activity( $activitypub_post, $activity_type, User_Factory::BLOG_USER_ID );
}
public static function send_user_activity( Post $activitypub_post, $activity_type, $user_id = null ) {
if ( $user_id ) {
$user = User_Factory::get_by_id( $user_id );
$actor = $user->get_url();
} else {
// get latest version of post
$user_id = $activitypub_post->get_post_author();
$actor = null;
}
$activitypub_activity = new Activity( $activity_type );
$activitypub_activity->from_post( $activitypub_post );
if ( $actor ) {
$activitypub_activity->set_actor( $actor );
}
$follower_inboxes = Followers::get_inboxes( $user_id );
$mentioned_inboxes = Mention::get_inboxes( $activitypub_activity->get_cc() );

View file

@ -267,3 +267,12 @@ function is_activitypub_request() {
return false;
}
/**
* Check if the current site is in single-user mode.
*
* @return boolean
*/
function is_single_user_mode() {
return ACTIVITYPUB_SINGLE_USER_MODE;
}