[PLUGIN][ActivityPub] Federate Actor of types other than Person
Fix some other minor bugs
This commit is contained in:
parent
25b2847201
commit
bdeb3bcff5
@ -128,8 +128,7 @@ class Collection extends Component
|
|||||||
[
|
[
|
||||||
Actor::PERSON => ['person', 'people'],
|
Actor::PERSON => ['person', 'people'],
|
||||||
Actor::GROUP => ['group', 'groups'],
|
Actor::GROUP => ['group', 'groups'],
|
||||||
Actor::ORGANIZATION => ['org', 'orgs', 'organization', 'organizations', 'organisation', 'organisations'],
|
Actor::ORGANISATION => ['org', 'orgs', 'organization', 'organizations', 'organisation', 'organisations'],
|
||||||
Actor::BUSINESS => ['business', 'businesses'],
|
|
||||||
Actor::BOT => ['bot', 'bots'],
|
Actor::BOT => ['bot', 'bots'],
|
||||||
] as $type => $match) {
|
] as $type => $match) {
|
||||||
if (array_intersect(explode(',', $term[1]), $match) !== []) {
|
if (array_intersect(explode(',', $term[1]), $match) !== []) {
|
||||||
|
@ -61,7 +61,7 @@ class Feeds extends FeedController
|
|||||||
public function home(Request $request): array
|
public function home(Request $request): array
|
||||||
{
|
{
|
||||||
Common::ensureLoggedIn();
|
Common::ensureLoggedIn();
|
||||||
$data = $this->query('note-from:subscribed-person,subscribed-group,subscribed-organization,subscribed-business');
|
$data = $this->query('note-from:subscribed-person,subscribed-group,subscribed-organisation');
|
||||||
return [
|
return [
|
||||||
'_template' => 'collection/notes.html.twig',
|
'_template' => 'collection/notes.html.twig',
|
||||||
'page_title' => _m('Home'),
|
'page_title' => _m('Home'),
|
||||||
|
@ -42,7 +42,6 @@ use App\Util\Exception\RedirectException;
|
|||||||
use App\Util\Exception\ServerException;
|
use App\Util\Exception\ServerException;
|
||||||
use App\Util\Form\ActorForms;
|
use App\Util\Form\ActorForms;
|
||||||
use App\Util\Nickname;
|
use App\Util\Nickname;
|
||||||
use Component\Collection\Util\ActorControllerTrait;
|
|
||||||
use Component\Collection\Util\Controller\FeedController;
|
use Component\Collection\Util\Controller\FeedController;
|
||||||
use Component\Group\Entity\GroupMember;
|
use Component\Group\Entity\GroupMember;
|
||||||
use Component\Group\Entity\LocalGroup;
|
use Component\Group\Entity\LocalGroup;
|
||||||
@ -53,28 +52,6 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
|
|
||||||
class Group extends FeedController
|
class Group extends FeedController
|
||||||
{
|
{
|
||||||
use ActorControllerTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* View a group providing its id
|
|
||||||
*
|
|
||||||
* @param int $id The id of the group to be shown
|
|
||||||
*
|
|
||||||
* @throws ClientException
|
|
||||||
*
|
|
||||||
* @return array Containing both the template to be used and the group actor
|
|
||||||
*/
|
|
||||||
public function groupViewId(Request $request, int $id)
|
|
||||||
{
|
|
||||||
return $this->handleActorById(
|
|
||||||
$id,
|
|
||||||
fn ($actor) => [
|
|
||||||
'_template' => 'group/view.html.twig',
|
|
||||||
'actor' => $actor,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View a group feed by its nickname
|
* View a group feed by its nickname
|
||||||
*
|
*
|
||||||
|
@ -40,7 +40,6 @@ class Group extends Component
|
|||||||
public function onAddRoute(RouteLoader $r): bool
|
public function onAddRoute(RouteLoader $r): bool
|
||||||
{
|
{
|
||||||
$r->connect(id: 'group_create', uri_path: '/group/new', target: [C\Group::class, 'groupCreate']);
|
$r->connect(id: 'group_create', uri_path: '/group/new', target: [C\Group::class, 'groupCreate']);
|
||||||
$r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\Group::class, 'groupViewId']);
|
|
||||||
$r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\Group::class, 'groupViewNickname'], options: ['is_system_path' => false]);
|
$r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\Group::class, 'groupViewNickname'], options: ['is_system_path' => false]);
|
||||||
$r->connect(id: 'group_settings', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}/settings', target: [C\Group::class, 'groupSettings'], options: ['is_system_path' => false]);
|
$r->connect(id: 'group_settings', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}/settings', target: [C\Group::class, 'groupSettings'], options: ['is_system_path' => false]);
|
||||||
return Event::next;
|
return Event::next;
|
||||||
|
@ -61,6 +61,20 @@ use Plugin\ActivityPub\Util\Model;
|
|||||||
*/
|
*/
|
||||||
class Actor extends Model
|
class Actor extends Model
|
||||||
{
|
{
|
||||||
|
private static array $_gs_actor_type_to_as2_actor_type = [
|
||||||
|
GSActor::PERSON => 'Person',
|
||||||
|
GSActor::GROUP => 'Group',
|
||||||
|
GSActor::ORGANISATION => 'Organization',
|
||||||
|
GSActor::BOT => 'Application',
|
||||||
|
];
|
||||||
|
private static array $_as2_actor_type_to_gs_actor_type = [
|
||||||
|
'Person' => GSActor::PERSON,
|
||||||
|
'Group' => GSActor::GROUP,
|
||||||
|
'Organization' => GSActor::ORGANISATION,
|
||||||
|
'Application' => GSActor::BOT,
|
||||||
|
'Service' => null,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an Entity from an ActivityStreams 2.0 JSON string
|
* Create an Entity from an ActivityStreams 2.0 JSON string
|
||||||
* This will persist a new GSActor, ActivityPubRSA, and ActivityPubActor
|
* This will persist a new GSActor, ActivityPubRSA, and ActivityPubActor
|
||||||
@ -77,8 +91,8 @@ class Actor extends Model
|
|||||||
'fullname' => !empty($person->get('name')) ? $person->get('name') : null,
|
'fullname' => !empty($person->get('name')) ? $person->get('name') : null,
|
||||||
'created' => new DateTime($person->get('published') ?? 'now'),
|
'created' => new DateTime($person->get('published') ?? 'now'),
|
||||||
'bio' => $person->get('summary'),
|
'bio' => $person->get('summary'),
|
||||||
'is_local' => false,
|
'is_local' => false, // duh!
|
||||||
'type' => GSActor::PERSON,
|
'type' => self::$_as2_actor_type_to_gs_actor_type[$person->get('type')],
|
||||||
'roles' => UserRoles::USER,
|
'roles' => UserRoles::USER,
|
||||||
'modified' => new DateTime(),
|
'modified' => new DateTime(),
|
||||||
];
|
];
|
||||||
@ -184,7 +198,7 @@ class Actor extends Model
|
|||||||
$uri = $object->getUri(Router::ABSOLUTE_URL);
|
$uri = $object->getUri(Router::ABSOLUTE_URL);
|
||||||
$attr = [
|
$attr = [
|
||||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
'type' => 'Person',
|
'type' => self::$_gs_actor_type_to_as2_actor_type[$object->getType()],
|
||||||
'id' => $uri,
|
'id' => $uri,
|
||||||
'inbox' => Router::url('activitypub_actor_inbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL),
|
'inbox' => Router::url('activitypub_actor_inbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL),
|
||||||
'outbox' => Router::url('activitypub_actor_outbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL),
|
'outbox' => Router::url('activitypub_actor_outbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL),
|
||||||
|
@ -243,9 +243,8 @@ class Actor extends Entity
|
|||||||
|
|
||||||
public const PERSON = 1;
|
public const PERSON = 1;
|
||||||
public const GROUP = 2;
|
public const GROUP = 2;
|
||||||
public const ORGANIZATION = 3;
|
public const ORGANISATION = 3;
|
||||||
public const BUSINESS = 4;
|
public const BOT = 4;
|
||||||
public const BOT = 5;
|
|
||||||
|
|
||||||
public static function cacheKeys(int|self $actor_id, mixed $other = null): array
|
public static function cacheKeys(int|self $actor_id, mixed $other = null): array
|
||||||
{
|
{
|
||||||
@ -422,13 +421,10 @@ class Actor extends Entity
|
|||||||
if (Event::handle('StartGetActorUri', [$this, $type, &$uri]) === Event::next) {
|
if (Event::handle('StartGetActorUri', [$this, $type, &$uri]) === Event::next) {
|
||||||
switch ($this->type) {
|
switch ($this->type) {
|
||||||
case self::PERSON:
|
case self::PERSON:
|
||||||
case self::ORGANIZATION:
|
case self::ORGANISATION:
|
||||||
case self::BUSINESS:
|
|
||||||
case self::BOT:
|
case self::BOT:
|
||||||
$uri = Router::url('actor_view_id', ['id' => $this->getId()], $type);
|
|
||||||
break;
|
|
||||||
case self::GROUP:
|
case self::GROUP:
|
||||||
$uri = Router::url('group_actor_view_id', ['id' => $this->getId()], $type);
|
$uri = Router::url('actor_view_id', ['id' => $this->getId()], $type);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new BugFoundException('Actor type added but `Actor::getUri` was not updated');
|
throw new BugFoundException('Actor type added but `Actor::getUri` was not updated');
|
||||||
@ -448,8 +444,7 @@ class Actor extends Entity
|
|||||||
if (Event::handle('StartGetActorUrl', [$this, $type, &$url]) === Event::next) {
|
if (Event::handle('StartGetActorUrl', [$this, $type, &$url]) === Event::next) {
|
||||||
switch ($this->type) {
|
switch ($this->type) {
|
||||||
case self::PERSON:
|
case self::PERSON:
|
||||||
case self::ORGANIZATION:
|
case self::ORGANISATION:
|
||||||
case self::BUSINESS:
|
|
||||||
case self::BOT:
|
case self::BOT:
|
||||||
$url = Router::url('actor_view_nickname', ['nickname' => $this->getNickname()], $type);
|
$url = Router::url('actor_view_nickname', ['nickname' => $this->getNickname()], $type);
|
||||||
break;
|
break;
|
||||||
@ -538,7 +533,6 @@ class Actor extends Entity
|
|||||||
* @method bool isPerson()
|
* @method bool isPerson()
|
||||||
* @method bool isGroup()
|
* @method bool isGroup()
|
||||||
* @method bool isOrganization()
|
* @method bool isOrganization()
|
||||||
* @method bool isBusiness()
|
|
||||||
* @method bool isBot()
|
* @method bool isBot()
|
||||||
*/
|
*/
|
||||||
public function __call(string $name, array $arguments): mixed
|
public function __call(string $name, array $arguments): mixed
|
||||||
|
Loading…
Reference in New Issue
Block a user