1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-27 02:06:52 +00:00
pixelfed/app/Util/ActivityPub/Outbox.php

52 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
{
2021-05-12 00:17:03 +00:00
abort_if(!config_cache('federation.activitypub.enabled'), 404);
2019-12-21 06:15:15 +00:00
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()
->whereScope('public')
2020-04-12 04:12:28 +00:00
->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
}
2021-05-12 00:17:03 +00:00
}