mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-23 16:24:29 +00:00
Update FollowerController
This commit is contained in:
parent
e9c67e337d
commit
ad8fc77e6c
1 changed files with 21 additions and 15 deletions
|
@ -23,18 +23,20 @@ class FollowerController extends Controller
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'item' => 'required|string',
|
'item' => 'required|string',
|
||||||
|
'force' => 'nullable|boolean',
|
||||||
]);
|
]);
|
||||||
|
$force = (bool) $request->input('force', true);
|
||||||
$item = (int) $request->input('item');
|
$item = (int) $request->input('item');
|
||||||
$this->handleFollowRequest($item);
|
$url = $this->handleFollowRequest($item, $force);
|
||||||
if($request->wantsJson()) {
|
if($request->wantsJson() == true) {
|
||||||
return response()->json(200);
|
return response()->json(200);
|
||||||
} else {
|
} else {
|
||||||
return redirect()->back();
|
return redirect($url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handleFollowRequest($item)
|
protected function handleFollowRequest($item, $force)
|
||||||
{
|
{
|
||||||
$user = Auth::user()->profile;
|
$user = Auth::user()->profile;
|
||||||
|
|
||||||
|
@ -87,17 +89,19 @@ class FollowerController extends Controller
|
||||||
}
|
}
|
||||||
FollowPipeline::dispatch($follower);
|
FollowPipeline::dispatch($follower);
|
||||||
} else {
|
} else {
|
||||||
$request = FollowRequest::whereFollowerId($user->id)->whereFollowingId($target->id)->exists();
|
if($force == true) {
|
||||||
$follower = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->exists();
|
$request = FollowRequest::whereFollowerId($user->id)->whereFollowingId($target->id)->exists();
|
||||||
if($remote == true && $request && !$follower) {
|
$follower = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->exists();
|
||||||
$this->sendFollow($user, $target);
|
if($remote == true && $request && !$follower) {
|
||||||
|
$this->sendFollow($user, $target);
|
||||||
|
}
|
||||||
|
if($remote == true && $follower) {
|
||||||
|
$this->sendUndoFollow($user, $target);
|
||||||
|
}
|
||||||
|
Follower::whereProfileId($user->id)
|
||||||
|
->whereFollowingId($target->id)
|
||||||
|
->delete();
|
||||||
}
|
}
|
||||||
if($remote == true && $follower) {
|
|
||||||
$this->sendUndoFollow($user, $target);
|
|
||||||
}
|
|
||||||
Follower::whereProfileId($user->id)
|
|
||||||
->whereFollowingId($target->id)
|
|
||||||
->delete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache::forget('profile:following:'.$target->id);
|
Cache::forget('profile:following:'.$target->id);
|
||||||
|
@ -107,6 +111,8 @@ class FollowerController extends Controller
|
||||||
Cache::forget('api:local:exp:rec:'.$user->id);
|
Cache::forget('api:local:exp:rec:'.$user->id);
|
||||||
Cache::forget('user:account:id:'.$target->user_id);
|
Cache::forget('user:account:id:'.$target->user_id);
|
||||||
Cache::forget('user:account:id:'.$user->user_id);
|
Cache::forget('user:account:id:'.$user->user_id);
|
||||||
|
|
||||||
|
return $target->url();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendFollow($user, $target)
|
public function sendFollow($user, $target)
|
||||||
|
|
Loading…
Reference in a new issue