浏览代码

Update remove_from_followers api endpoint

Daniel Supernault 2 月之前
父节点
当前提交
5a3a1cf76c

+ 20 - 16
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);
         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);
             return $this->json(['error' => 'Request invalid! target_id is same user id.'], 500);
         }
         }
 
 
-        Follower::whereProfileId($target_id)
+        $exists = Follower::whereProfileId($id)
             ->whereFollowingId($pid)
             ->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:following:'.$pid);
         Cache::forget('profile:followers:'.$pid);
         Cache::forget('profile:followers:'.$pid);
         Cache::forget('api:local:exp:rec:'.$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('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:follower_count:'.$pid);
-        Cache::forget('profile:following_count:'.$target_id);
+        Cache::forget('profile:following_count:'.$id);
         Cache::forget('profile:following_count:'.$pid);
         Cache::forget('profile:following_count:'.$pid);
         AccountService::del($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
      *  GET /api/v1/statuses/{id}/pin

+ 1 - 1
resources/views/settings/relationships/home.blade.php

@@ -155,7 +155,7 @@
 				});
 				});
                 break;
                 break;
                 case 'removeFollow':
                 case 'removeFollow':
-                axios.post('/api/v1/accounts/' + id + '/removeFollow').then(res => {
+                axios.post('/api/pixelfed/v1/accounts/' + id + '/remove_from_followers').then(res => {
                     swal(
                     swal(
                         '{{__('settings.relationships.unfollow_successful')}}',
                         '{{__('settings.relationships.unfollow_successful')}}',
                         '{{__('settings.relationships.you_have_successfully_unfollowed_that_user')}}',
                         '{{__('settings.relationships.you_have_successfully_unfollowed_that_user')}}',

+ 1 - 1
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}/unfollow', 'Api\ApiV1Controller@accountUnfollowById')->middleware($middleware);
         Route::post('accounts/{id}/block', 'Api\ApiV1Controller@accountBlockById')->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}/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}/pin', 'Api\ApiV1Controller@accountEndorsements')->middleware($middleware);
         Route::post('accounts/{id}/unpin', '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);
         Route::post('accounts/{id}/mute', 'Api\ApiV1Controller@accountMuteById')->middleware($middleware);

+ 1 - 1
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::get('accounts/{id}/statuses', 'PublicApiController@accountStatuses');
                 Route::post('accounts/{id}/block', 'Api\ApiV1Controller@accountBlockById');
                 Route::post('accounts/{id}/block', 'Api\ApiV1Controller@accountBlockById');
                 Route::post('accounts/{id}/unblock', 'Api\ApiV1Controller@accountUnblockById');
                 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::get('statuses/{id}', 'PublicApiController@getStatus');
                 Route::post('statuses/{id}/pin', 'PublicApiController@statusPin');
                 Route::post('statuses/{id}/pin', 'PublicApiController@statusPin');
                 Route::post('statuses/{id}/unpin', 'PublicApiController@statusUnpin');
                 Route::post('statuses/{id}/unpin', 'PublicApiController@statusUnpin');