1
0
Fork 0

Merge pull request #418 from pixelfed/frontend-ui-refactor

Update ProfileController
This commit is contained in:
daniel 2018-08-28 12:55:57 -06:00 committed by GitHub
commit c084064f15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 66 additions and 26 deletions

View File

@ -2,21 +2,36 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use Cache;
use App\Follower;
use App\Profile;
use App\Transformer\ActivityPub\ProfileTransformer;
use App\User;
use Auth;
use Illuminate\Http\Request;
use App\UserFilter;
use League\Fractal;
use App\Util\Lexer\Nickname;
use App\Util\Webfinger\Webfinger;
use App\Transformer\ActivityPub\ProfileOutbox;
use App\Transformer\ActivityPub\ProfileTransformer;
class ProfileController extends Controller
{
public function show(Request $request, $username)
{
$user = Profile::whereUsername($username)->firstOrFail();
return $this->buildProfile($request, $user);
}
// TODO: refactor this mess
protected function buildProfile(Request $request, $user)
{
$username = $user->username;
$loggedIn = Auth::check();
$isPrivate = false;
if ($user->remote_url) {
$settings = new \StdClass();
$settings = new \StdClass;
$settings->crawlable = false;
} else {
$settings = User::whereUsername($username)->firstOrFail()->settings;
@ -27,22 +42,27 @@ class ProfileController extends Controller
}
if ($user->is_private == true) {
$can_access = $this->privateProfileCheck($user);
if ($can_access !== true) {
abort(403);
}
$isPrivate = $this->privateProfileCheck($user);
}
// TODO: refactor this mess
$owner = Auth::check() && Auth::id() === $user->user_id;
$is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false;
$is_admin = is_null($user->domain) ? $user->user->is_admin : false;
$timeline = $user->statuses()
if ($loggedIn == true) {
$isPrivate = $this->blockedProfileCheck($user);
}
if ($isPrivate == true) {
return view('profile.private', compact('user'));
} else {
$owner = $loggedIn && Auth::id() === $user->user_id;
$is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false;
$is_admin = is_null($user->domain) ? $user->user->is_admin : false;
$timeline = $user->statuses()
->whereHas('media')
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->orderBy('created_at', 'desc')
->withCount(['comments', 'likes'])
->simplePaginate(21);
}
return view('profile.show', compact('user', 'settings', 'owner', 'is_following', 'is_admin', 'timeline'));
}
@ -64,9 +84,8 @@ class ProfileController extends Controller
if (Auth::check() === false) {
return false;
}
$follower_ids = (array) $profile->followers()->pluck('followers.profile_id');
$pid = Auth::user()->profile->id;
$follower_ids = $profile->followers()->pluck('followers.profile_id')->toArray();
if (!in_array($pid, $follower_ids) && $pid !== $profile->id) {
return false;
}
@ -74,12 +93,26 @@ class ProfileController extends Controller
return true;
}
protected function blockedProfileCheck(Profile $profile)
{
$pid = Auth::user()->profile->id;
$blocks = UserFilter::whereUserId($profile->id)
->whereFilterType('block')
->whereFilterableType('App\Profile')
->pluck('filterable_id')
->toArray();
if (in_array($pid, $blocks)) {
return true;
}
return false;
}
public function showActivityPub(Request $request, $user)
{
$fractal = new Fractal\Manager();
$resource = new Fractal\Resource\Item($user, new ProfileTransformer());
$resource = new Fractal\Resource\Item($user, new ProfileTransformer);
$res = $fractal->createData($resource)->toArray();
return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json');
}
@ -87,22 +120,25 @@ class ProfileController extends Controller
{
$profile = Profile::whereUsername($user)->firstOrFail();
$items = $profile->statuses()->orderBy('created_at', 'desc')->take(10)->get();
return response()->view('atom.user', compact('profile', 'items'))
->header('Content-Type', 'application/atom+xml');
}
public function followers(Request $request, $username)
{
$profile = Profile::whereUsername($username)->firstOrFail();
$profile = $user = Profile::whereUsername($username)->firstOrFail();
// TODO: fix $profile/$user mismatch in profile & follower templates
$user = $profile;
$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;
return view('profile.followers', compact('user', 'profile', 'followers', 'owner', 'is_following', 'is_admin'));
if ($user->remote_url) {
$settings = new \StdClass;
$settings->crawlable = false;
} else {
$settings = User::whereUsername($username)->firstOrFail()->settings;
}
return view('profile.followers', compact('user', 'profile', 'followers', 'owner', 'is_following', 'is_admin', 'settings'));
}
public function following(Request $request, $username)
@ -114,8 +150,13 @@ class ProfileController extends Controller
$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;
return view('profile.following', compact('user', 'profile', 'following', 'owner', 'is_following', 'is_admin'));
if ($user->remote_url) {
$settings = new \StdClass;
$settings->crawlable = false;
} else {
$settings = User::whereUsername($username)->firstOrFail()->settings;
}
return view('profile.following', compact('user', 'profile', 'following', 'owner', 'is_following', 'is_admin', 'settings'));
}
public function savedBookmarks(Request $request, $username)
@ -127,10 +168,9 @@ class ProfileController extends Controller
$settings = User::whereUsername($username)->firstOrFail()->settings;
$owner = true;
$following = false;
$timeline = $user->bookmarks()->withCount(['likes', 'comments'])->orderBy('created_at', 'desc')->simplePaginate(10);
$timeline = $user->bookmarks()->withCount(['likes','comments'])->orderBy('created_at', 'desc')->simplePaginate(10);
$is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false;
$is_admin = is_null($user->domain) ? $user->user->is_admin : false;
return view('profile.show', compact('user', 'settings', 'owner', 'following', 'timeline', 'is_following', 'is_admin'));
}
}