More Group meta-data to play nicely with existing platforms (#441)
* more group friendly settings * change http code * Fix Actor-Type * fix check if value is set * only ignore null * better posting_restricted_to_mods handling * remove user namespace from moderators endpoint thanks for the feedback @mattwiebe
This commit is contained in:
parent
dd29775ae4
commit
0d635d5dd1
6 changed files with 122 additions and 18 deletions
|
@ -28,6 +28,7 @@ class Activity extends Base_Object {
|
||||||
'toot' => 'http://joinmastodon.org/ns#',
|
'toot' => 'http://joinmastodon.org/ns#',
|
||||||
'webfinger' => 'https://webfinger.net/#',
|
'webfinger' => 'https://webfinger.net/#',
|
||||||
'litepub' => 'http://litepub.social/ns#',
|
'litepub' => 'http://litepub.social/ns#',
|
||||||
|
'lemmy' => 'https://join-lemmy.org/ns#',
|
||||||
'value' => 'schema:value',
|
'value' => 'schema:value',
|
||||||
'Hashtag' => 'as:Hashtag',
|
'Hashtag' => 'as:Hashtag',
|
||||||
'featured' => array(
|
'featured' => array(
|
||||||
|
@ -42,7 +43,13 @@ class Activity extends Base_Object {
|
||||||
'@id' => 'as:alsoKnownAs',
|
'@id' => 'as:alsoKnownAs',
|
||||||
'@type' => '@id',
|
'@type' => '@id',
|
||||||
),
|
),
|
||||||
|
'moderators' => array(
|
||||||
|
'@id' => 'lemmy:moderators',
|
||||||
|
'@type' => '@id',
|
||||||
|
),
|
||||||
|
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods',
|
||||||
'discoverable' => 'toot:discoverable',
|
'discoverable' => 'toot:discoverable',
|
||||||
|
'indexable' => 'toot:indexable',
|
||||||
'sensitive' => 'as:sensitive',
|
'sensitive' => 'as:sensitive',
|
||||||
'resource' => 'webfinger:resource',
|
'resource' => 'webfinger:resource',
|
||||||
),
|
),
|
||||||
|
|
|
@ -644,7 +644,7 @@ class Base_Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if value is still empty, ignore it for the array and continue.
|
// if value is still empty, ignore it for the array and continue.
|
||||||
if ( $value ) {
|
if ( isset( $value ) ) {
|
||||||
$array[ snake_to_camel_case( $key ) ] = $value;
|
$array[ snake_to_camel_case( $key ) ] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,14 +55,18 @@ class Application_User extends Blog_User {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_attachment() {
|
public function get_attachment() {
|
||||||
return array();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_featured_tags() {
|
public function get_featured_tags() {
|
||||||
return array();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_featured() {
|
public function get_featured() {
|
||||||
return array();
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_moderators() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use Activitypub\Collection\Users;
|
||||||
|
|
||||||
use function Activitypub\is_single_user;
|
use function Activitypub\is_single_user;
|
||||||
use function Activitypub\is_user_disabled;
|
use function Activitypub\is_user_disabled;
|
||||||
|
use function Activitypub\get_rest_url_by_path;
|
||||||
|
|
||||||
class Blog_User extends User {
|
class Blog_User extends User {
|
||||||
/**
|
/**
|
||||||
|
@ -21,7 +22,7 @@ class Blog_User extends User {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $type = 'Group';
|
protected $type = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is Account discoverable?
|
* Is Account discoverable?
|
||||||
|
@ -45,6 +46,21 @@ class Blog_User extends User {
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the type of the object.
|
||||||
|
*
|
||||||
|
* If the Blog is in "single user" mode, return "Person" insted of "Group".
|
||||||
|
*
|
||||||
|
* @return string The type of the object.
|
||||||
|
*/
|
||||||
|
public function get_type() {
|
||||||
|
if ( is_single_user() ) {
|
||||||
|
return 'Person';
|
||||||
|
} else {
|
||||||
|
return 'Group';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the User-Name.
|
* Get the User-Name.
|
||||||
*
|
*
|
||||||
|
@ -188,25 +204,26 @@ class Blog_User extends User {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_attachment() {
|
public function get_attachment() {
|
||||||
return array();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_canonical_url() {
|
public function get_canonical_url() {
|
||||||
return \home_url();
|
return \home_url();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function get_moderators() {
|
||||||
* Get the type of the object.
|
if ( is_single_user() || 'Group' !== $this->get_type() ) {
|
||||||
*
|
return null;
|
||||||
* If the Blog is in "single user" mode, return "Person" insted of "Group".
|
|
||||||
*
|
|
||||||
* @return string The type of the object.
|
|
||||||
*/
|
|
||||||
public function get_type() {
|
|
||||||
if ( is_single_user() ) {
|
|
||||||
return 'Person';
|
|
||||||
} else {
|
|
||||||
return $this->type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return get_rest_url_by_path( 'collections/moderators' );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_posting_restricted_to_mods() {
|
||||||
|
if ( 'Group' === $this->get_type() ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,15 @@ class User extends Actor {
|
||||||
*/
|
*/
|
||||||
protected $featured;
|
protected $featured;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moderators endpoint.
|
||||||
|
*
|
||||||
|
* @see https://join-lemmy.org/docs/contributors/05-federation.html
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $moderators;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The User-Type
|
* The User-Type
|
||||||
*
|
*
|
||||||
|
@ -46,10 +55,19 @@ class User extends Actor {
|
||||||
/**
|
/**
|
||||||
* If the User is discoverable.
|
* If the User is discoverable.
|
||||||
*
|
*
|
||||||
|
* @see https://docs.joinmastodon.org/spec/activitypub/#discoverable
|
||||||
|
*
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
protected $discoverable = true;
|
protected $discoverable = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the User is indexable.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $indexable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The WebFinger Resource.
|
* The WebFinger Resource.
|
||||||
*
|
*
|
||||||
|
@ -57,6 +75,15 @@ class User extends Actor {
|
||||||
*/
|
*/
|
||||||
protected $resource;
|
protected $resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restrict posting to mods
|
||||||
|
*
|
||||||
|
* @see https://join-lemmy.org/docs/contributors/05-federation.html
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $posting_restricted_to_mods = null;
|
||||||
|
|
||||||
public static function from_wp_user( $user_id ) {
|
public static function from_wp_user( $user_id ) {
|
||||||
if ( is_user_disabled( $user_id ) ) {
|
if ( is_user_disabled( $user_id ) ) {
|
||||||
return new WP_Error(
|
return new WP_Error(
|
||||||
|
@ -272,4 +299,16 @@ class User extends Actor {
|
||||||
public function get_canonical_url() {
|
public function get_canonical_url() {
|
||||||
return $this->get_url();
|
return $this->get_url();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_streams() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_indexable() {
|
||||||
|
if ( \get_option( 'blog_public', 1 ) ) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Activitypub\Rest;
|
namespace Activitypub\Rest;
|
||||||
|
|
||||||
|
use WP_Error;
|
||||||
use WP_REST_Server;
|
use WP_REST_Server;
|
||||||
use WP_REST_Response;
|
use WP_REST_Response;
|
||||||
use Activitypub\Transformer\Post;
|
use Activitypub\Transformer\Post;
|
||||||
|
@ -56,6 +57,18 @@ class Collection {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
\register_rest_route(
|
||||||
|
ACTIVITYPUB_REST_NAMESPACE,
|
||||||
|
'/collections/moderators',
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::READABLE,
|
||||||
|
'callback' => array( self::class, 'moderators_get' ),
|
||||||
|
'permission_callback' => '__return_true',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,6 +171,30 @@ class Collection {
|
||||||
return new WP_REST_Response( $response, 200 );
|
return new WP_REST_Response( $response, 200 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moderators endpoint
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request The request object.
|
||||||
|
*
|
||||||
|
* @return WP_REST_Response The response object.
|
||||||
|
*/
|
||||||
|
public static function moderators_get( $request ) {
|
||||||
|
$response = array(
|
||||||
|
'@context' => Activity::CONTEXT,
|
||||||
|
'id' => get_rest_url_by_path( 'collections/moderators' ),
|
||||||
|
'type' => 'OrderedCollection',
|
||||||
|
'orderedItems' => array(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$users = User_Collection::get_collection();
|
||||||
|
|
||||||
|
foreach ( $users as $user ) {
|
||||||
|
$response['orderedItems'][] = $user->get_url();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new WP_REST_Response( $response, 200 );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The supported parameters
|
* The supported parameters
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue