diff --git a/app/FollowRequest.php b/app/FollowRequest.php index 2859ad4d2..df7757ebb 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'); diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index acf17a247..62599c6c5 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); + } } diff --git a/app/Http/Controllers/FollowerController.php b/app/Http/Controllers/FollowerController.php index a487ac079..da4c96dc9 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; diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 336e596e8..80f6bacbd 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) { diff --git a/resources/views/account/activity.blade.php b/resources/views/account/activity.blade.php index 2354b7ef0..a8c0879ad 100644 --- a/resources/views/account/activity.blade.php +++ b/resources/views/account/activity.blade.php @@ -5,15 +5,18 @@
-
diff --git a/resources/views/account/follow-requests.blade.php b/resources/views/account/follow-requests.blade.php new file mode 100644 index 000000000..a6c4845e0 --- /dev/null +++ b/resources/views/account/follow-requests.blade.php @@ -0,0 +1,72 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+ +
+
+
    + @foreach($followers as $follow) +
  • + + + + + {{$follow->follower->username}} {{__('wants to follow you')}} + {{$follow->created_at->diffForHumans(null, true, true)}} + + +
    + + +
    +
    +
  • + @endforeach +
+ +
+ {{$followers->links()}} +
+ +
+
+@endsection + +@push('scripts') + +@endpush diff --git a/resources/views/profile/partial/private-info.blade.php b/resources/views/profile/partial/private-info.blade.php index 1e69755f1..20a779098 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 0f51a8e4b..5b48ddf86 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)