Parcourir la source

Merge pull request #5895 from eufelipemateus/feat-remove-follow

[Improvement] Add button remove follow
daniel il y a 2 mois
Parent
commit
92482c24cd

+ 36 - 0
app/Http/Controllers/Api/ApiV1Controller.php

@@ -4563,6 +4563,42 @@ class ApiV1Controller extends Controller
         );
     }
 
+    public function accountRemoveFollowById(Request $request, $target_id)
+    {
+        abort_if(! $request->user(), 403);
+
+        $pid =  $request->user()->profile_id;
+
+        if (intval($pid) === intval($target_id)) {
+            return $this->json(['error' => 'Request invalid! target_id is same user id.'], 500);
+        }
+
+        Follower::whereProfileId($target_id)
+            ->whereFollowingId($pid)
+            ->delete();
+
+        RelationshipService::refresh($pid, $target_id);
+
+        UnfollowPipeline::dispatch($pid, $pid)->onQueue('high');
+
+        RelationshipService::refresh($pid, $target_id);
+        Cache::forget('profile:following:'.$target_id);
+        Cache::forget('profile:followers:'.$target_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:'.$pid);
+        Cache::forget('profile:follower_count:'.$target_id);
+        Cache::forget('profile:follower_count:'.$pid);
+        Cache::forget('profile:following_count:'.$target_id);
+        Cache::forget('profile:following_count:'.$pid);
+        AccountService::del($pid);
+        AccountService::del($target_id);
+
+
+        return $this->json([]);
+    }
     /**
      *  GET /api/v1/statuses/{id}/pin
      */

+ 1 - 0
resources/lang/en/settings.php

@@ -135,6 +135,7 @@ return [
     'relationships.unfollow' =>                                                 'Unfollow',
     'relationships.mute' =>                                                     'Mute',
     'relationships.block' =>                                                    'Block',
+    'relationships.removeFollow' =>                                             'Remove  Follow',
     'relationships.mute_successful' =>                                          'Mute Successful',
     'relationships.you_have_successfully_muted_that_user' =>                    'You have successfully muted that user',
     'relationships.block_successful' =>                                         'Block Successful',

+ 1 - 0
resources/lang/pt/settings.php

@@ -135,6 +135,7 @@ return [
     'relationships.unfollow' =>                                                 'Deixar de seguir',
     'relationships.mute' =>                                                     'Silenciar',
     'relationships.block' =>                                                    'Bloquear',
+    'relationships.removeFollow' =>                                             'Remover Seguidor',
     'relationships.mute_successful' =>                                          'Silenciamento bem-sucedido',
     'relationships.you_have_successfully_muted_that_user' =>                    'Você silenciou com sucesso esse usuário',
     'relationships.block_successful' =>                                         'Bloqueio bem-sucedido',

+ 11 - 0
resources/views/settings/relationships/home.blade.php

@@ -71,6 +71,7 @@
 			<td class="text-center">
 				<a class="btn btn-outline-primary btn-sm py-0 action-btn" href="#" data-id="{{$follower->id}}" data-action="mute">{{__('settings.relationships.mute')}}</a>
 				<a class="btn btn-outline-danger btn-sm py-0 action-btn" href="#" data-id="{{$follower->id}}" data-action="block">{{__('settings.relationships.block')}}</a>
+                <a class="btn btn-outline-secondary btn-sm py-0 action-btn" href="#" data-id="{{$follower->id}}" data-action="removeFollow">{{__('settings.relationships.removeFollow')}}</a>
 			</td>
 			@endif
 		</tr>
@@ -152,6 +153,16 @@
 						'success'
 						);
 				});
+                break;
+                case 'removeFollow':
+                axios.post('/api/v1/accounts/' + id + '/removeFollow').then(res => {
+                    swal(
+                        '{{__('settings.relationships.unfollow_successful')}}',
+                        '{{__('settings.relationships.you_have_successfully_unfollowed_that_user')}}',
+                        'success'
+                        );
+                });
+
 			}
 			setTimeout(function() {
 				window.location.href = window.location.href;

+ 1 - 0
routes/api.php

@@ -108,6 +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}/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);

+ 1 - 0
routes/web-api.php

@@ -68,6 +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::get('statuses/{id}', 'PublicApiController@getStatus');
                 Route::post('statuses/{id}/pin', 'PublicApiController@statusPin');
                 Route::post('statuses/{id}/unpin', 'PublicApiController@statusUnpin');