From 5a3a1cf76c619ea24d4aa64a0a35b710b43ad94d Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 2 May 2025 01:26:36 -0600 Subject: [PATCH] Update remove_from_followers api endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 36 ++++++++++--------- .../settings/relationships/home.blade.php | 2 +- routes/api.php | 2 +- routes/web-api.php | 2 +- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 8e4bf9661..0e6317197 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -4563,41 +4563,45 @@ class ApiV1Controller extends Controller ); } - public function accountRemoveFollowById(Request $request, $target_id) + public function accountRemoveFollowById(Request $request, $id) { abort_if(! $request->user(), 403); - $pid = $request->user()->profile_id; + $pid = $request->user()->profile_id; - if (intval($pid) === intval($target_id)) { + if ($pid === $id) { return $this->json(['error' => 'Request invalid! target_id is same user id.'], 500); } - Follower::whereProfileId($target_id) + $exists = Follower::whereProfileId($id) ->whereFollowingId($pid) - ->delete(); + ->first(); + + abort_unless($exists, 404); + + $exists->delete(); - RelationshipService::refresh($pid, $target_id); + RelationshipService::refresh($pid, $id); + RelationshipService::refresh($pid, $id); - UnfollowPipeline::dispatch($pid, $pid)->onQueue('high'); + UnfollowPipeline::dispatch($id, $pid)->onQueue('high'); - RelationshipService::refresh($pid, $target_id); - Cache::forget('profile:following:'.$target_id); - Cache::forget('profile:followers:'.$target_id); + Cache::forget('profile:following:'.$id); + Cache::forget('profile:followers:'.$id); Cache::forget('profile:following:'.$pid); Cache::forget('profile:followers:'.$pid); Cache::forget('api:local:exp:rec:'.$pid); - Cache::forget('user:account:id:'.$target_id); + Cache::forget('user:account:id:'.$id); Cache::forget('user:account:id:'.$pid); - Cache::forget('profile:follower_count:'.$target_id); + Cache::forget('profile:follower_count:'.$id); Cache::forget('profile:follower_count:'.$pid); - Cache::forget('profile:following_count:'.$target_id); + Cache::forget('profile:following_count:'.$id); Cache::forget('profile:following_count:'.$pid); AccountService::del($pid); - AccountService::del($target_id); - + AccountService::del($id); - return $this->json([]); + $res = RelationshipService::get($id, $pid); + return $this->json($res); } /** * GET /api/v1/statuses/{id}/pin diff --git a/resources/views/settings/relationships/home.blade.php b/resources/views/settings/relationships/home.blade.php index 1c16a31ca..9d4c4fed4 100644 --- a/resources/views/settings/relationships/home.blade.php +++ b/resources/views/settings/relationships/home.blade.php @@ -155,7 +155,7 @@ }); break; case 'removeFollow': - axios.post('/api/v1/accounts/' + id + '/removeFollow').then(res => { + axios.post('/api/pixelfed/v1/accounts/' + id + '/remove_from_followers').then(res => { swal( '{{__('settings.relationships.unfollow_successful')}}', '{{__('settings.relationships.you_have_successfully_unfollowed_that_user')}}', diff --git a/routes/api.php b/routes/api.php index 8b320fffa..bd6fd127e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -108,7 +108,7 @@ Route::group(['prefix' => 'api'], function () use ($middleware) { Route::post('accounts/{id}/unfollow', 'Api\ApiV1Controller@accountUnfollowById')->middleware($middleware); Route::post('accounts/{id}/block', 'Api\ApiV1Controller@accountBlockById')->middleware($middleware); Route::post('accounts/{id}/unblock', 'Api\ApiV1Controller@accountUnblockById')->middleware($middleware); - Route::post('accounts/{id}/removeFollow', 'Api\ApiV1Controller@accountRemoveFollowById')->middleware($middleware); + Route::post('accounts/{id}/remove_from_followers', 'Api\ApiV1Controller@accountRemoveFollowById')->middleware($middleware); Route::post('accounts/{id}/pin', 'Api\ApiV1Controller@accountEndorsements')->middleware($middleware); Route::post('accounts/{id}/unpin', 'Api\ApiV1Controller@accountEndorsements')->middleware($middleware); Route::post('accounts/{id}/mute', 'Api\ApiV1Controller@accountMuteById')->middleware($middleware); diff --git a/routes/web-api.php b/routes/web-api.php index ab386f52d..db8e55ebd 100644 --- a/routes/web-api.php +++ b/routes/web-api.php @@ -68,7 +68,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('accounts/{id}/statuses', 'PublicApiController@accountStatuses'); Route::post('accounts/{id}/block', 'Api\ApiV1Controller@accountBlockById'); Route::post('accounts/{id}/unblock', 'Api\ApiV1Controller@accountUnblockById'); - Route::post('accounts/{id}/removeFollow', 'Api\ApiV1Controller@accountRemoveFollowById'); + Route::post('accounts/{id}/remove_from_followers', 'Api\ApiV1Controller@accountRemoveFollowById'); Route::get('statuses/{id}', 'PublicApiController@getStatus'); Route::post('statuses/{id}/pin', 'PublicApiController@statusPin'); Route::post('statuses/{id}/unpin', 'PublicApiController@statusUnpin');