소스 검색

Update ComposeController, add collection support to compose endpoint

Daniel Supernault 3 년 전
부모
커밋
ec2cfaf54e
1개의 변경된 파일18개의 추가작업 그리고 1개의 파일을 삭제
  1. 18 1
      app/Http/Controllers/ComposeController.php

+ 18 - 1
app/Http/Controllers/ComposeController.php

@@ -7,6 +7,8 @@ use Auth, Cache, DB, Storage, URL;
 use Carbon\Carbon;
 use App\{
 	Avatar,
+	Collection,
+	CollectionItem,
 	Hashtag,
 	Like,
 	Media,
@@ -449,7 +451,8 @@ class ComposeController extends Controller
 			'place' => 'nullable',
 			'comments_disabled' => 'nullable',
 			'tagged' => 'nullable',
-			'license' => 'nullable|integer|min:1|max:16'
+			'license' => 'nullable|integer|min:1|max:16',
+			'collections' => 'sometimes|array|min:1|max:5',
 			// 'optimize_media' => 'nullable'
 		]);
 
@@ -572,6 +575,20 @@ class ComposeController extends Controller
 			MediaTagService::sendNotification($mt);
 		}
 
+		if($request->filled('collections')) {
+			$collections = Collection::whereProfileId($profile->id)
+				->find($request->input('collections'))
+				->each(function($collection) use($status) {
+					CollectionItem::firstOrCreate([
+						'collection_id' => $collection->id,
+						'object_type' => 'App\Status',
+						'object_id' => $status->id
+					], [
+						'order' => $collection->items()->count()
+					]);
+				});
+		}
+
 		NewStatusPipeline::dispatch($status);
 		Cache::forget('user:account:id:'.$profile->user_id);
 		Cache::forget('_api:statuses:recent_9:'.$profile->id);