pixelfed/app/Util/ActivityPub/Outbox.php

51 lines
1.5 KiB
PHP
Raw Normal View History

2019-12-21 06:15:15 +00:00
<?php
namespace App\Util\ActivityPub;
use App\Profile;
2020-04-12 04:12:28 +00:00
use App\Status;
2019-12-21 06:15:15 +00:00
use League\Fractal;
use App\Http\Controllers\ProfileController;
use App\Transformer\ActivityPub\ProfileOutbox;
2020-04-12 04:12:28 +00:00
use App\Transformer\ActivityPub\Verb\CreateNote;
2019-12-21 06:15:15 +00:00
class Outbox {
2020-04-12 04:12:28 +00:00
public static function get($profile)
2019-12-21 06:15:15 +00:00
{
abort_if(!config('federation.activitypub.enabled'), 404);
abort_if(!config('federation.activitypub.outbox'), 404);
if($profile->status != null) {
return ProfileController::accountCheck($profile);
}
2020-04-12 04:12:28 +00:00
2019-12-21 06:15:15 +00:00
if($profile->is_private) {
2020-04-12 04:12:28 +00:00
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()
->whereVisibility('public')
->orderBy('created_at', 'desc')
->take(10)
->get();
$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']
];
return $outbox;
2019-12-21 06:15:15 +00:00
}
}