[PLUGIN][ActivityPub] Federate Actor of types other than Person

Fix some other minor bugs
This commit is contained in:
Diogo Peralta Cordeiro 2022-01-19 02:22:29 +00:00
parent 25b2847201
commit bdeb3bcff5
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
6 changed files with 24 additions and 41 deletions

View File

@ -128,8 +128,7 @@ class Collection extends Component
[
Actor::PERSON => ['person', 'people'],
Actor::GROUP => ['group', 'groups'],
Actor::ORGANIZATION => ['org', 'orgs', 'organization', 'organizations', 'organisation', 'organisations'],
Actor::BUSINESS => ['business', 'businesses'],
Actor::ORGANISATION => ['org', 'orgs', 'organization', 'organizations', 'organisation', 'organisations'],
Actor::BOT => ['bot', 'bots'],
] as $type => $match) {
if (array_intersect(explode(',', $term[1]), $match) !== []) {

View File

@ -61,7 +61,7 @@ class Feeds extends FeedController
public function home(Request $request): array
{
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 [
'_template' => 'collection/notes.html.twig',
'page_title' => _m('Home'),

View File

@ -42,7 +42,6 @@ use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException;
use App\Util\Form\ActorForms;
use App\Util\Nickname;
use Component\Collection\Util\ActorControllerTrait;
use Component\Collection\Util\Controller\FeedController;
use Component\Group\Entity\GroupMember;
use Component\Group\Entity\LocalGroup;
@ -53,28 +52,6 @@ use Symfony\Component\HttpFoundation\Request;
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 File

@ -40,7 +40,6 @@ class Group extends Component
public function onAddRoute(RouteLoader $r): bool
{
$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_settings', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}/settings', target: [C\Group::class, 'groupSettings'], options: ['is_system_path' => false]);
return Event::next;

View File

@ -61,6 +61,20 @@ use Plugin\ActivityPub\Util\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
* 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,
'created' => new DateTime($person->get('published') ?? 'now'),
'bio' => $person->get('summary'),
'is_local' => false,
'type' => GSActor::PERSON,
'is_local' => false, // duh!
'type' => self::$_as2_actor_type_to_gs_actor_type[$person->get('type')],
'roles' => UserRoles::USER,
'modified' => new DateTime(),
];
@ -184,7 +198,7 @@ class Actor extends Model
$uri = $object->getUri(Router::ABSOLUTE_URL);
$attr = [
'@context' => 'https://www.w3.org/ns/activitystreams',
'type' => 'Person',
'type' => self::$_gs_actor_type_to_as2_actor_type[$object->getType()],
'id' => $uri,
'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),

View File

@ -243,9 +243,8 @@ class Actor extends Entity
public const PERSON = 1;
public const GROUP = 2;
public const ORGANIZATION = 3;
public const BUSINESS = 4;
public const BOT = 5;
public const ORGANISATION = 3;
public const BOT = 4;
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) {
switch ($this->type) {
case self::PERSON:
case self::ORGANIZATION:
case self::BUSINESS:
case self::ORGANISATION:
case self::BOT:
$uri = Router::url('actor_view_id', ['id' => $this->getId()], $type);
break;
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;
default:
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) {
switch ($this->type) {
case self::PERSON:
case self::ORGANIZATION:
case self::BUSINESS:
case self::ORGANISATION:
case self::BOT:
$url = Router::url('actor_view_nickname', ['nickname' => $this->getNickname()], $type);
break;
@ -538,7 +533,6 @@ class Actor extends Entity
* @method bool isPerson()
* @method bool isGroup()
* @method bool isOrganization()
* @method bool isBusiness()
* @method bool isBot()
*/
public function __call(string $name, array $arguments): mixed