From 43cef2829638d94a84330decc15c60f93bbc7275 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 29 Sep 2019 00:36:02 -0600 Subject: [PATCH] Add /api/v1/statuses/{id}/reblog endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 33 ++++++++++++++++++-- routes/web.php | 2 ++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 6314cd0de..bd94df4ab 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Str; use App\Util\ActivityPub\Helpers; +use App\Util\Media\Filter; use Laravel\Passport\Passport; use Auth, Cache, DB, URL; use App\{ @@ -33,7 +34,7 @@ use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Pagination\IlluminatePaginatorAdapter; use App\Http\Controllers\StatusController; use App\Jobs\LikePipeline\LikePipeline; -use App\Util\Media\Filter; +use App\Jobs\SharePipeline\SharePipeline; use App\Jobs\StatusPipeline\NewStatusPipeline; use App\Jobs\StatusPipeline\StatusDelete; use App\Jobs\FollowPipeline\FollowPipeline; @@ -43,7 +44,6 @@ use App\Jobs\VideoPipeline\{ VideoPostProcess, VideoThumbnail }; - use App\Services\NotificationService; class ApiV1Controller extends Controller @@ -1582,4 +1582,33 @@ class ApiV1Controller extends Controller return response()->json(['Status successfully deleted.']); } + + /** + * POST /api/v1/statuses/{id}/reblog + * + * @param integer $id + * + * @return StatusTransformer + */ + public function statusShare(Request $request, $id) + { + abort_if(!$request->user(), 403); + + $user = $request->user(); + $status = Status::findOrFail($id); + + $share = Status::firstOrCreate([ + 'profile_id' = $user->profile_id, + 'reblog_of_id' = $status->id, + 'in_reply_to_profile_id' = $status->profile_id + ]); + + if($share->wasRecentlyCreated == true) { + SharePipeline::dispatch($share); + } + + $resource = new Fractal\Resource\Item($share, new StatusTransformer()); + $res = $this->fractal->createData($resource)->toArray(); + return response()->json($res); + } } \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index c534bcde8..81ee42325 100644 --- a/routes/web.php +++ b/routes/web.php @@ -126,6 +126,8 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('conversations', 'Api\ApiV1Controller@conversations')->middleware('auth:api'); Route::get('timelines/public', 'Api\ApiV1Controller@timelinePublic'); Route::post('statuses', 'Api\ApiV1Controller@statusCreate')->middleware('auth:api'); + Route::delete('statuses/{id}', 'Api\ApiV1Controller@statusDelete')->middleware('auth:api'); + Route::post('statuses/{id}/reblog', 'Api\ApiV1Controller@statusShare')->middleware('auth:api'); // Route::get('likes', 'ApiController@hydrateLikes'); // Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api');