Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/User Delete activities #552

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
bcf29e1
Profiles: update followers when profile fields change
mattwiebe Oct 31, 2023
e3a78fb
use static
mattwiebe Oct 31, 2023
af3e61c
only try to merge mention inboxes when valid
mattwiebe Nov 1, 2023
3785cee
Add Server Class, known_inboxes method
mediaformat Nov 8, 2023
d64ed73
Add a server dispatch activity
mediaformat Nov 8, 2023
565a6ca
Add a delete wp user action
mediaformat Nov 8, 2023
9e8065a
lint:fix
mediaformat Nov 8, 2023
4d83e1a
Merge branch 'master' into add/ServerActivities
pfefferle Nov 10, 2023
7543884
Add blog user followers to known inboxes
mediaformat Nov 10, 2023
05b4ebf
public function
mediaformat Nov 11, 2023
2bfb930
update send_server_activity
mediaformat Nov 11, 2023
6c548bc
update delete schedulers
mediaformat Nov 11, 2023
41f05ef
get temporary key for deleted user
mediaformat Nov 11, 2023
f101daf
Merge branch 'master' into add/ServerActivities
mediaformat Nov 11, 2023
87d32cb
Merge branch 'master' into add/ServerActivities
mediaformat Nov 13, 2023
06a023e
Rename to Application class
mediaformat Nov 13, 2023
5090e84
Merge branch 'master' into add/ServerActivities
mediaformat Nov 27, 2023
8499aa4
Merge branch 'master' into add/ServerActivities
pfefferle Nov 30, 2023
96b29a3
Merge branch 'master' into add/ServerActivities
pfefferle Dec 18, 2023
76771aa
Merge branch 'master' into add/ServerActivities
pfefferle May 6, 2024
fcbfa74
Fix PHP errors and lint issues
mattwiebe May 7, 2024
ca3d1bc
Update includes/class-scheduler.php
mediaformat May 8, 2024
e894bc6
Rename action and function
mediaformat May 8, 2024
1aa30ed
Use get_all_followers for inboxes
mediaformat May 8, 2024
fb0f679
schedule_actor_delete
mediaformat May 8, 2024
61951f7
has_cap activitypub
mediaformat May 8, 2024
4cef50d
activitypub_send_actor_delete_activity
mediaformat May 8, 2024
6c1fa00
remove Application class
mediaformat May 8, 2024
01b4d09
private key already stored
mediaformat May 8, 2024
22a664e
clean up user, delete signature options key
mediaformat May 8, 2024
aa448d3
get signing keys from options for actor delete activity
mediaformat May 9, 2024
f9fee8c
Send Delete activity to shared_inboxes
mediaformat May 9, 2024
2df226e
set temp signature option
mediaformat May 9, 2024
d1e0074
cleanup
mediaformat May 9, 2024
bf50942
phpcs
mediaformat May 9, 2024
c781662
phpcbf
mediaformat May 9, 2024
39fffc7
Merge branch 'master' into add/ServerActivities
pfefferle May 16, 2024
7af4eb1
Merge branch 'master' into add/ServerActivities
pfefferle May 16, 2024
c9477d7
Merge branch 'master' into add/ServerActivities
pfefferle Jun 4, 2024
dc88d91
Merge branch 'master' into add/ServerActivities
pfefferle Jun 25, 2024
b84286e
init cli
pfefferle Jun 25, 2024
0de423a
add http gone class
pfefferle Jun 26, 2024
2f33377
add http gone
pfefferle Jun 26, 2024
39e6e71
rewrite dispatcher a bit
pfefferle Jun 26, 2024
520c3fb
mark as federated
pfefferle Jun 26, 2024
962e6dd
cleanups
pfefferle Jun 26, 2024
2730907
remove lagacy code
pfefferle Jun 26, 2024
295d5bc
fix instance of check
pfefferle Jun 26, 2024
4fcf151
better $user handling
pfefferle Jun 27, 2024
f319cac
better support of system users
pfefferle Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions includes/class-activity-dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Activitypub\Collection\Users;
use Activitypub\Collection\Followers;
use Activitypub\Transformer\Factory;
use Activitypub\Transformer\Post;
use Activitypub\Application;
use Activitypub\Transformer\Comment;

use function Activitypub\is_single_user;
Expand All @@ -33,6 +33,7 @@ public static function init() {
\add_action( 'activitypub_send_activity', array( self::class, 'send_activity' ), 10, 2 );
\add_action( 'activitypub_send_activity', array( self::class, 'send_activity_or_announce' ), 10, 2 );
\add_action( 'activitypub_send_update_profile_activity', array( self::class, 'send_profile_update' ), 10, 1 );
\add_action( 'activitypub_send_server_activity', array( self::class, 'send_server_activity' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -174,8 +175,21 @@ private static function send_activity_to_followers( $activity, $user_id, $wp_obj
foreach ( $inboxes as $inbox ) {
safe_remote_post( $inbox, $json, $user_id );
}
}

set_wp_object_state( $wp_object, 'federated' );
/**
* Send an Activity to all known (shared_)inboxes.
*
* @param Activity $activity The ActivityPub Activity.
*
* @return void
*/
public static function send_server_activity( $activity, $user_id = Users::APPLICATION_USER_ID ) {
$json = $activity->to_json();
$inboxes = Application::known_inboxes();
foreach ( $inboxes as $inbox ) {
safe_remote_post( $inbox, $json, $user_id );
}
}

/**
Expand Down
34 changes: 34 additions & 0 deletions includes/class-application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Activitypub;

use Activitypub\Collection\Followers;
use Activitypub\Collection\Users;

use function Activitypub\is_user_disabled;

/**
* ActivityPub Application Class
*
* @author Django Doucet
*/
class Application {

public static function known_inboxes() {
mediaformat marked this conversation as resolved.
Show resolved Hide resolved
$authors = get_users(
array(
'capability' => 'publish_posts',
)
);
$follower_inboxes_all = [];
foreach ( $authors as $user ) {
$follower_inboxes = Followers::get_inboxes( $user->ID );
$follower_inboxes_all = array_merge( $follower_inboxes, $follower_inboxes_all );
}
if ( ! is_user_disabled( Users::BLOG_USER_ID ) ) {
$follower_inboxes = Followers::get_inboxes( Users::BLOG_USER_ID );
$follower_inboxes_all = array_merge( $follower_inboxes, $follower_inboxes_all );
}
return array_unique( array_filter( $follower_inboxes_all ) );
}
}
41 changes: 40 additions & 1 deletion includes/class-scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use Activitypub\Transformer\Post;
use Activitypub\Collection\Users;
use Activitypub\Collection\Followers;
use Activitypub\Activity\Activity;

use function Activitypub\was_comment_sent;
use function Activitypub\get_private_key_for;
use function Activitypub\is_user_type_disabled;
use function Activitypub\was_comment_sent;
use function Activitypub\should_comment_be_federated;
use function Activitypub\get_remote_metadata_by_actor;

Expand Down Expand Up @@ -63,6 +65,7 @@ function ( $comment_id ) {
// Follower Cleanups
\add_action( 'activitypub_update_followers', array( self::class, 'update_followers' ) );
\add_action( 'activitypub_cleanup_followers', array( self::class, 'cleanup_followers' ) );
\add_action( 'admin_init', array( self::class, 'schedule_migration' ) );

// profile updates for blog options
if ( ! is_user_type_disabled( 'blog' ) ) {
Expand All @@ -75,6 +78,8 @@ function ( $comment_id ) {

// profile updates for user options
if ( ! is_user_type_disabled( 'user' ) ) {
mediaformat marked this conversation as resolved.
Show resolved Hide resolved
\add_action( 'delete_user', array( self::class, 'schedule_profile_delete' ), 10, 3 );
\add_action( 'deleted_user', array( self::class, 'schedule_user_delete' ), 10, 3 );
pfefferle marked this conversation as resolved.
Show resolved Hide resolved
\add_action( 'wp_update_user', array( self::class, 'user_update' ) );
\add_action( 'updated_user_meta', array( self::class, 'user_meta_update' ), 10, 3 );
// @todo figure out a feasible way of updating the header image since it's not unique to any user.
Expand Down Expand Up @@ -330,4 +335,38 @@ public static function schedule_profile_update( $user_id ) {
array( $user_id )
);
}

/**
* Send an Actor Delete activity.
* @param int $user_id The user ID to Delete.
*/
public static function schedule_profile_delete( $user_id ) {
$user = get_userdata( $user_id );
if ( $user->has_cap( 'publish_posts' ) ) {
$temp_private_key = get_private_key_for( $user->ID );
add_option( 'activitypub_temp_sig_' . $user->ID, $temp_private_key );

$author_url = \get_author_posts_url( $user->ID );

$activity = new Activity();
$activity->set_id( $author_url . '#delete' );
$activity->set_type( 'Delete' );
$activity->set_actor( $author_url );
$activity->set_object( $author_url );
$activity->set_to( [ 'https://www.w3.org/ns/activitystreams#Public' ] );
mediaformat marked this conversation as resolved.
Show resolved Hide resolved

\wp_schedule_single_event( \time(), 'activitypub_send_server_activity', array( $activity, $user_id ) );
}
}

/**
* Delete actor related options.
* @param int $user_id The deleted user ID.
*/
public static function schedule_user_delete( $user_id ) {
$user = get_userdata( $user_id );
if ( $user->has_cap( 'publish_posts' ) ) {
mediaformat marked this conversation as resolved.
Show resolved Hide resolved
delete_option( 'activitypub_temp_sig_' . $user_id );
}
}
}
6 changes: 5 additions & 1 deletion includes/class-signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ protected static function check_legacy_key_pair_for( $user_id ) {
*/
public static function generate_signature( $user_id, $http_method, $url, $date, $digest = null ) {
$user = Users::get_by_id( $user_id );
$key = self::get_private_key_for( $user->get__id() );
if ( ! is_wp_error( $user ) ) {
$key = self::get_private_key_for( $user->get__id() );
} else {
$key = get_option( 'activitypub_temp_sig_' . $user_id, true );
mediaformat marked this conversation as resolved.
Show resolved Hide resolved
}

$url_parts = \wp_parse_url( $url );

Expand Down
Loading