Skip to content

Commit

Permalink
Update ApiV1Controller, add collection_ids to /api/v1/statuses endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Sep 29, 2022
1 parent 0a82e94 commit 7ae21fc
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion app/Http/Controllers/Api/ApiV1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use App\{
Avatar,
Bookmark,
Collection,
CollectionItem,
DirectMessage,
Follower,
FollowRequest,
Expand Down Expand Up @@ -59,6 +61,7 @@

use App\Services\{
AccountService,
CollectionService,
FollowerService,
InstanceService,
LikeService,
Expand Down Expand Up @@ -2481,7 +2484,8 @@ public function statusCreate(Request $request)
'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) {
Expand Down Expand Up @@ -2618,6 +2622,27 @@ public function statusCreate(Request $request)
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';
Expand Down

0 comments on commit 7ae21fc

Please sign in to comment.