Update ApiV1Controller, add collection_ids to /api/v1/statuses endpoint

This commit is contained in:
Daniel Supernault 2022-09-28 23:48:46 -06:00
parent 0a82e9466d
commit 7ae21fc396
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -12,6 +12,8 @@ use Auth, Cache, DB, URL;
use App\{
Avatar,
Bookmark,
Collection,
CollectionItem,
DirectMessage,
Follower,
FollowRequest,
@ -59,6 +61,7 @@ use App\Jobs\VideoPipeline\{
use App\Services\{
AccountService,
CollectionService,
FollowerService,
InstanceService,
LikeService,
@ -2481,7 +2484,8 @@ class ApiV1Controller extends Controller
'sensitive' => 'nullable',
'visibility' => 'string|in:private,unlisted,public',
'spoiler_text' => 'sometimes|max:140',
'place_id' => 'sometimes|integer|min:1|max:128769'
'place_id' => 'sometimes|integer|min:1|max:128769',
'collection_ids' => 'sometimes|array|max:3',
]);
if(config('costar.enabled') == true) {
@ -2618,6 +2622,27 @@ class ApiV1Controller extends Controller
Cache::forget('profile:embed:' . $status->profile_id);
Cache::forget($limitKey);
if($request->has('collection_ids') && $ids) {
$collections = Collection::whereProfileId($user->profile_id)
->find($request->input('collection_ids'))
->each(function($collection) use($status) {
$count = $collection->items()->count();
$item = CollectionItem::firstOrCreate([
'collection_id' => $collection->id,
'object_type' => 'App\Status',
'object_id' => $status->id
],[
'order' => $count,
]);
CollectionService::addItem(
$collection->id,
$status->id,
$count
);
});
}
$res = StatusService::getMastodon($status->id, false);
$res['favourited'] = false;
$res['language'] = 'en';