Update FollowerController

This commit is contained in:
Daniel Supernault 2019-12-04 20:24:08 -07:00
parent e9c67e337d
commit ad8fc77e6c
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -24,17 +24,19 @@ class FollowerController extends Controller
{
$this->validate($request, [
'item' => 'required|string',
'force' => 'nullable|boolean',
]);
$force = (bool) $request->input('force', true);
$item = (int) $request->input('item');
$this->handleFollowRequest($item);
if($request->wantsJson()) {
$url = $this->handleFollowRequest($item, $force);
if($request->wantsJson() == true) {
return response()->json(200);
} else {
return redirect()->back();
return redirect($url);
}
}
protected function handleFollowRequest($item)
protected function handleFollowRequest($item, $force)
{
$user = Auth::user()->profile;
@ -87,6 +89,7 @@ class FollowerController extends Controller
}
FollowPipeline::dispatch($follower);
} else {
if($force == true) {
$request = FollowRequest::whereFollowerId($user->id)->whereFollowingId($target->id)->exists();
$follower = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->exists();
if($remote == true && $request && !$follower) {
@ -99,6 +102,7 @@ class FollowerController extends Controller
->whereFollowingId($target->id)
->delete();
}
}
Cache::forget('profile:following:'.$target->id);
Cache::forget('profile:followers:'.$target->id);
@ -107,6 +111,8 @@ class FollowerController extends Controller
Cache::forget('api:local:exp:rec:'.$user->id);
Cache::forget('user:account:id:'.$target->user_id);
Cache::forget('user:account:id:'.$user->user_id);
return $target->url();
}
public function sendFollow($user, $target)