Browse Source

Update AccountController. Fixes #582

Daniel Supernault 6 years ago
parent
commit
10cfb02a9e
1 changed files with 22 additions and 0 deletions
  1. 22 0
      app/Http/Controllers/AccountController.php

+ 22 - 0
app/Http/Controllers/AccountController.php

@@ -203,6 +203,16 @@ class AccountController extends Controller
           'filter_type'     => 'mute',
         ]);
 
+        $pid = $user->id;
+        Cache::remember("user:filter:list:$pid", 1440, function() use($pid) {
+          $private = Profile::whereIsPrivate(true)->where('id', '!=', $pid)->pluck('id');
+          $filters = UserFilter::whereUserId($pid)
+                    ->whereFilterableType('App\Profile')
+                    ->whereIn('filter_type', ['mute', 'block'])
+                    ->pluck('filterable_id')->toArray();
+          return array_merge($private->toArray(), $filters);
+        });
+
         return redirect()->back();
     }
 
@@ -224,6 +234,9 @@ class AccountController extends Controller
         switch ($type) {
           case 'user':
             $profile = Profile::findOrFail($item);
+            if ($profile->id == $user->id) {
+                return abort(403);
+            }
             $class = get_class($profile);
             $filterable['id'] = $profile->id;
             $filterable['type'] = $class;
@@ -244,6 +257,15 @@ class AccountController extends Controller
           'filter_type'     => 'block',
         ]);
 
+        $pid = $user->id;
+        Cache::remember("user:filter:list:$pid", 1440, function() use($pid) {
+          $private = Profile::whereIsPrivate(true)->where('id', '!=', $pid)->pluck('id');
+          $filters = UserFilter::whereUserId($pid)
+                    ->whereFilterableType('App\Profile')
+                    ->whereIn('filter_type', ['mute', 'block'])
+                    ->pluck('filterable_id')->toArray();
+          return array_merge($private->toArray(), $filters);
+        });
         return redirect()->back();
     }