diff --git a/includes/handler/class-follow.php b/includes/handler/class-follow.php index d0cab72..c76e2cf 100644 --- a/includes/handler/class-follow.php +++ b/includes/handler/class-follow.php @@ -75,11 +75,11 @@ class Follow { * @return void */ public static function send_follow_response( $user_id, $inbox, $object, $type ) { - // send activity $activity = new Activity(); + $activity->set_type( $type ); $activity->set_object( $object ); - $activity->set_actor( $user_id ); + $activity->set_actor( Users::get_by_id( $user_id )->get_url() ); $activity->set_to( $object['actor'] ); $activity->set_id( $user_id . '#accept-' . \preg_replace( '~^https?://~', '', $object['actor'] ) . '-' . \time() ); diff --git a/includes/model/class-follow-request.php b/includes/model/class-follow-request.php index fee8171..310cb11 100644 --- a/includes/model/class-follow-request.php +++ b/includes/model/class-follow-request.php @@ -43,6 +43,12 @@ class Follow_Request extends Base_Object { */ protected $_actor; + /** + * The status: 'approved', 'pending', 'rejected'
+ * @var string + */ + protected $_status; + /** * @param int $id * @return Follow_Request $follow_request @@ -110,6 +116,7 @@ class Follow_Request extends Base_Object { $follow_request = new static(); $follow_request->set_id( $post->guid ); $follow_request->set__id( $post->ID ); + $follow_request->set__status( $post->post_status ); $follow_request->set_type( 'Follow' ); return $follow_request; @@ -238,8 +245,6 @@ class Follow_Request extends Base_Object { $user_id = get_post_meta( $this->get__id(), 'activitypub_user_id', true ); } - $user = Users::get_by_id( $user_id ); - if ( ! $follower_id ) { $follower_id = $this->get_follower_id(); } @@ -250,6 +255,7 @@ class Follow_Request extends Base_Object { $follow_object = array( 'id' => $this->get_id(), 'type' => $this->get_type(), + 'actor' => get_post_field( 'guid', $follower_id ), ); do_action( 'activitypub_send_follow_response', $user_id, $follower_inbox, $follow_object, $type ); diff --git a/includes/table/class-follow-requests.php b/includes/table/class-follow-requests.php index 079e03d..7feeeaf 100644 --- a/includes/table/class-follow-requests.php +++ b/includes/table/class-follow-requests.php @@ -256,7 +256,7 @@ class Follow_Requests extends WP_List_Table { break; case 'reject': $follow_request->reject(); - wp_die( 'rejected' ); + wp_die( 'rejected' ); break; case 'delete': $follow_request->delete(); @@ -352,7 +352,10 @@ class Follow_Requests extends WP_List_Table { $follow_requests = array( $follow_requests ); } foreach ( $follow_requests as $follow_request ) { - Follow_Request::from_wp_id( $follow_request )->reject(); + $follow_request = Follow_Request::from_wp_id( $follow_request ); + if ( $follow_request->can_handle_follow_request() && $follow_request->get__status() != 'rejected' ) { + $follow_request->reject(); + } } break; case 'approve': @@ -360,7 +363,10 @@ class Follow_Requests extends WP_List_Table { $follow_requests = array( $follow_requests ); } foreach ( $follow_requests as $follow_request ) { - Follow_Request::from_wp_id( $follow_request )->approve(); + $follow_request = Follow_Request::from_wp_id( $follow_request ); + if ( $follow_request->can_handle_follow_request() && $follow_request->get__status() != 'approved' ) { + $follow_request->approve(); + } } break; }