From 9b501e9c59aef2ac56571ed620a2746f767ba9de Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Sep 2018 21:59:54 -0600 Subject: [PATCH 1/8] Update ProfileController --- app/Http/Controllers/ProfileController.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 336e596e..80f6bacb 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -50,12 +50,13 @@ class ProfileController extends Controller $isBlocked = $this->blockedProfileCheck($user); } - if ($isPrivate == true || $isBlocked == true) { - return view('profile.private', compact('user')); - } - $owner = $loggedIn && Auth::id() === $user->user_id; $is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false; + + if ($isPrivate == true || $isBlocked == true) { + return view('profile.private', compact('user', 'is_following')); + } + $is_admin = is_null($user->domain) ? $user->user->is_admin : false; $timeline = $user->statuses() ->whereHas('media') @@ -142,6 +143,8 @@ class ProfileController extends Controller { $profile = $user = Profile::whereUsername($username)->firstOrFail(); // TODO: fix $profile/$user mismatch in profile & follower templates + $owner = Auth::check() && Auth::id() === $user->user_id; + $is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false; if($profile->is_private || Auth::check()) { $blocked = $this->blockedProfileCheck($profile); $check = $this->privateProfileCheck($profile, null); @@ -149,8 +152,6 @@ class ProfileController extends Controller return view('profile.private', compact('user')); } } - $owner = Auth::check() && Auth::id() === $user->user_id; - $is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false; $followers = $profile->followers()->orderBy('created_at', 'desc')->simplePaginate(12); $is_admin = is_null($user->domain) ? $user->user->is_admin : false; if ($user->remote_url) { @@ -166,6 +167,8 @@ class ProfileController extends Controller { $profile = $user = Profile::whereUsername($username)->firstOrFail(); // TODO: fix $profile/$user mismatch in profile & follower templates + $owner = Auth::check() && Auth::id() === $user->user_id; + $is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false; if($profile->is_private || Auth::check()) { $blocked = $this->blockedProfileCheck($profile); $check = $this->privateProfileCheck($profile, null); @@ -173,9 +176,6 @@ class ProfileController extends Controller return view('profile.private', compact('user')); } } - $user = $profile; - $owner = Auth::check() && Auth::id() === $user->user_id; - $is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false; $following = $profile->following()->orderBy('created_at', 'desc')->simplePaginate(12); $is_admin = is_null($user->domain) ? $user->user->is_admin : false; if ($user->remote_url) { From 38d6d58dc87358ddbbfc894a20616ca65415b5cc Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Sep 2018 22:00:31 -0600 Subject: [PATCH 2/8] Update FollowerController --- app/Http/Controllers/FollowerController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/FollowerController.php b/app/Http/Controllers/FollowerController.php index a487ac07..da4c96dc 100644 --- a/app/Http/Controllers/FollowerController.php +++ b/app/Http/Controllers/FollowerController.php @@ -34,10 +34,10 @@ class FollowerController extends Controller $isFollowing = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->count(); if($private == true && $isFollowing == 0) { - $follow = new FollowRequest; - $follow->follower_id = $user->id; - $follow->following_id = $target->id; - $follow->save(); + $follow = FollowRequest::firstOrCreate([ + 'follower_id' => $user->id, + 'following_id' => $target->id + ]); } elseif ($isFollowing == 0) { $follower = new Follower(); $follower->profile_id = $user->id; From 13894415ee6a96d3e58569bd62933f1aeaf04e41 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Sep 2018 22:00:54 -0600 Subject: [PATCH 3/8] Update FollowRequest model --- app/FollowRequest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/FollowRequest.php b/app/FollowRequest.php index 2859ad4d..df7757eb 100644 --- a/app/FollowRequest.php +++ b/app/FollowRequest.php @@ -6,6 +6,8 @@ use Illuminate\Database\Eloquent\Model; class FollowRequest extends Model { + protected $fillable = ['follower_id', 'following_id']; + public function follower() { return $this->belongsTo(Profile::class, 'follower_id', 'id'); From b5a4e45ccbcf069bd14087941ee92edb7f8a4fd9 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Sep 2018 22:01:51 -0600 Subject: [PATCH 4/8] Update AccountController --- app/Http/Controllers/AccountController.php | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index acf17a24..62599c6c 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -3,6 +3,9 @@ namespace App\Http\Controllers; use App\EmailVerification; +use App\Follower; +use App\FollowRequest; +use App\Jobs\FollowPipeline\FollowPipeline; use App\Mail\ConfirmEmail; use App\Notification; use App\Profile; @@ -236,4 +239,43 @@ class AccountController extends Controller return redirect()->back(); } + + public function followRequests(Request $request) + { + $pid = Auth::user()->profile->id; + $followers = FollowRequest::whereFollowingId($pid)->orderBy('id','desc')->whereIsRejected(0)->simplePaginate(10); + return view('account.follow-requests', compact('followers')); + } + + public function followRequestHandle(Request $request) + { + $this->validate($request, [ + 'action' => 'required|string|max:10', + 'id' => 'required|integer|min:1' + ]); + + $pid = Auth::user()->profile->id; + $action = $request->input('action') === 'accept' ? 'accept' : 'reject'; + $id = $request->input('id'); + $followRequest = FollowRequest::whereFollowingId($pid)->findOrFail($id); + $follower = $followRequest->follower; + + switch ($action) { + case 'accept': + $follow = new Follower(); + $follow->profile_id = $follower->id; + $follow->following_id = $pid; + $follow->save(); + FollowPipeline::dispatch($follow); + $followRequest->delete(); + break; + + case 'reject': + $followRequest->is_rejected = true; + $followRequest->save(); + break; + } + + return response()->json(['msg' => 'success'], 200); + } } From d2413fe458adca2791fc3f35977481f84d53d0cd Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Sep 2018 22:02:38 -0600 Subject: [PATCH 5/8] Update profile partials --- .../profile/partial/private-info.blade.php | 17 +++++++++++++++++ .../views/profile/partial/user-info.blade.php | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/resources/views/profile/partial/private-info.blade.php b/resources/views/profile/partial/private-info.blade.php index 1e69755f..20a77909 100644 --- a/resources/views/profile/partial/private-info.blade.php +++ b/resources/views/profile/partial/private-info.blade.php @@ -10,6 +10,23 @@
{{$user->username}} + @if(Auth::check() && $is_following == true) + + + + @elseif(Auth::check() && $is_following == false) + + + + @endif
diff --git a/resources/views/profile/partial/user-info.blade.php b/resources/views/profile/partial/user-info.blade.php index 0f51a8e4..5b48ddf8 100644 --- a/resources/views/profile/partial/user-info.blade.php +++ b/resources/views/profile/partial/user-info.blade.php @@ -19,7 +19,7 @@ - @elseif ($is_following == true) + @elseif (Auth::check() && $is_following == true) - @elseif ($is_following == false) + @elseif (Auth::check() && $is_following == false)