pixelfed/app/Util/ActivityPub/Outbox.php

50 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2019-12-21 06:15:15 +00:00
<?php
namespace App\Util\ActivityPub;
use App\Http\Controllers\ProfileController;
use App\Status;
2020-04-12 04:12:28 +00:00
use App\Transformer\ActivityPub\Verb\CreateNote;
use League\Fractal;
2019-12-21 06:15:15 +00:00
class Outbox
{
public static function get($profile)
{
abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
abort_if(! config('federation.activitypub.outbox'), 404);
2019-12-21 06:15:15 +00:00
if ($profile->status != null) {
2019-12-21 06:15:15 +00:00
return ProfileController::accountCheck($profile);
}
2020-04-12 04:12:28 +00:00
if ($profile->is_private) {
return ['error' => '403', 'msg' => 'private profile'];
2019-12-21 06:15:15 +00:00
}
2020-04-12 04:12:28 +00:00
$timeline = $profile
->statuses()
->whereScope('public')
->orderBy('created_at', 'desc')
->take(10)
->get();
2020-04-12 04:12:28 +00:00
$count = Status::whereProfileId($profile->id)->count();
2019-12-21 06:15:15 +00:00
$fractal = new Fractal\Manager();
2020-04-12 04:12:28 +00:00
$resource = new Fractal\Resource\Collection($timeline, new CreateNote());
2019-12-21 06:15:15 +00:00
$res = $fractal->createData($resource)->toArray();
2020-04-12 04:12:28 +00:00
$outbox = [
'@context' => 'https://www.w3.org/ns/activitystreams',
'_debug' => 'Outbox only supports latest 10 objects, pagination is not supported',
'id' => $profile->permalink('/outbox'),
'type' => 'OrderedCollection',
'totalItems' => $count,
'orderedItems' => $res['data'],
2020-04-12 04:12:28 +00:00
];
2019-12-21 06:15:15 +00:00
return $outbox;
}
2021-05-12 00:17:03 +00:00
}