瀏覽代碼

Refactor following check

Daniel Supernault 3 月之前
父節點
當前提交
8082c004bc
共有 2 個文件被更改,包括 573 次插入569 次删除
  1. 563 563
      app/Http/Controllers/AccountController.php
  2. 10 6
      app/Http/Controllers/PublicApiController.php

文件差異過大導致無法顯示
+ 563 - 563
app/Http/Controllers/AccountController.php


+ 10 - 6
app/Http/Controllers/PublicApiController.php

@@ -788,6 +788,14 @@ class PublicApiController extends Controller
 
 
     private function determineVisibility($profile, $user)
     private function determineVisibility($profile, $user)
     {
     {
+        if (! $user || ! isset($user->profile_id)) {
+            return [];
+        }
+
+        if (! $profile || ! isset($profile['id'])) {
+            return [];
+        }
+
         if ($profile['id'] == $user->profile_id) {
         if ($profile['id'] == $user->profile_id) {
             return ['public', 'unlisted', 'private'];
             return ['public', 'unlisted', 'private'];
         }
         }
@@ -798,17 +806,13 @@ class PublicApiController extends Controller
             }
             }
 
 
             $pid = $user->profile_id;
             $pid = $user->profile_id;
-            $isFollowing = Follower::whereProfileId($pid)
-                ->whereFollowingId($profile['id'])
-                ->exists();
+            $isFollowing = FollowerService::follows($pid, $profile['id']);
 
 
             return $isFollowing ? ['public', 'unlisted', 'private'] : ['public'];
             return $isFollowing ? ['public', 'unlisted', 'private'] : ['public'];
         } else {
         } else {
             if ($user) {
             if ($user) {
                 $pid = $user->profile_id;
                 $pid = $user->profile_id;
-                $isFollowing = Follower::whereProfileId($pid)
-                    ->whereFollowingId($profile['id'])
-                    ->exists();
+                $isFollowing = FollowerService::follows($pid, $profile['id']);
 
 
                 return $isFollowing ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
                 return $isFollowing ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
             } else {
             } else {

部分文件因文件數量過多而無法顯示