forked from mirror/pixelfed
commit
e1f985a13e
3 changed files with 82 additions and 83 deletions
|
@ -11,6 +11,7 @@
|
||||||
### Changed
|
### Changed
|
||||||
- Updated EmailService, added new domains [#1690](https://github.com/pixelfed/pixelfed/pull/1690)
|
- Updated EmailService, added new domains [#1690](https://github.com/pixelfed/pixelfed/pull/1690)
|
||||||
- Updated quill.js to v1.3.7 [#1692](https://github.com/pixelfed/pixelfed/pull/1690)
|
- Updated quill.js to v1.3.7 [#1692](https://github.com/pixelfed/pixelfed/pull/1690)
|
||||||
|
- Cache ProfileController [#1700](https://github.com/pixelfed/pixelfed/pull/1700)
|
||||||
|
|
||||||
## Deprecated
|
## Deprecated
|
||||||
- Remove deprecated profile following/followers [#1697](https://github.com/pixelfed/pixelfed/pull/1697)
|
- Remove deprecated profile following/followers [#1697](https://github.com/pixelfed/pixelfed/pull/1697)
|
||||||
|
|
|
@ -20,80 +20,93 @@ class ProfileController extends Controller
|
||||||
{
|
{
|
||||||
public function show(Request $request, $username)
|
public function show(Request $request, $username)
|
||||||
{
|
{
|
||||||
$user = Profile::whereUsername($username)->firstOrFail();
|
$user = Profile::whereNull('domain')
|
||||||
if($user->domain) {
|
->whereNull('status')
|
||||||
return redirect($user->remote_url);
|
->whereUsername($username)
|
||||||
}
|
->firstOrFail();
|
||||||
if($user->status != null) {
|
if($request->wantsJson() && config('federation.activitypub.enabled')) {
|
||||||
return $this->accountCheck($user);
|
return $this->showActivityPub($request, $user);
|
||||||
} else {
|
|
||||||
return $this->buildProfile($request, $user);
|
|
||||||
}
|
}
|
||||||
|
return $this->buildProfile($request, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: refactor this mess
|
|
||||||
protected function buildProfile(Request $request, $user)
|
protected function buildProfile(Request $request, $user)
|
||||||
{
|
{
|
||||||
$username = $user->username;
|
$username = $user->username;
|
||||||
$loggedIn = Auth::check();
|
$loggedIn = Auth::check();
|
||||||
$isPrivate = false;
|
$isPrivate = false;
|
||||||
$isBlocked = false;
|
$isBlocked = false;
|
||||||
|
if(!$loggedIn) {
|
||||||
|
$key = 'profile:settings:' . $user->id;
|
||||||
|
$ttl = now()->addHours(6);
|
||||||
|
$settings = Cache::remember($key, $ttl, function() use($user) {
|
||||||
|
return $user->user->settings;
|
||||||
|
});
|
||||||
|
|
||||||
if($user->status != null) {
|
if ($user->is_private == true) {
|
||||||
return ProfileController::accountCheck($user);
|
abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user->remote_url) {
|
$owner = false;
|
||||||
$settings = new \StdClass;
|
$is_following = false;
|
||||||
$settings->crawlable = false;
|
|
||||||
$settings->show_profile_follower_count = true;
|
$is_admin = $user->user->is_admin;
|
||||||
$settings->show_profile_following_count = true;
|
$profile = $user;
|
||||||
|
$settings = [
|
||||||
|
'crawlable' => $settings->crawlable,
|
||||||
|
'following' => [
|
||||||
|
'count' => $settings->show_profile_following_count,
|
||||||
|
'list' => $settings->show_profile_following
|
||||||
|
],
|
||||||
|
'followers' => [
|
||||||
|
'count' => $settings->show_profile_follower_count,
|
||||||
|
'list' => $settings->show_profile_followers
|
||||||
|
]
|
||||||
|
];
|
||||||
|
return view('profile.show', compact('profile', 'settings'));
|
||||||
} else {
|
} else {
|
||||||
$settings = $user->user->settings;
|
$key = 'profile:settings:' . $user->id;
|
||||||
}
|
$ttl = now()->addHours(6);
|
||||||
|
$settings = Cache::remember($key, $ttl, function() use($user) {
|
||||||
|
return $user->user->settings;
|
||||||
|
});
|
||||||
|
|
||||||
if ($request->wantsJson() && config('federation.activitypub.enabled')) {
|
if ($user->is_private == true) {
|
||||||
return $this->showActivityPub($request, $user);
|
$isPrivate = $this->privateProfileCheck($user, $loggedIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user->is_private == true) {
|
|
||||||
$isPrivate = $this->privateProfileCheck($user, $loggedIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($loggedIn == true) {
|
|
||||||
$isBlocked = $this->blockedProfileCheck($user);
|
$isBlocked = $this->blockedProfileCheck($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) {
|
||||||
|
$requested = Auth::check() ? FollowRequest::whereFollowerId(Auth::user()->profile_id)
|
||||||
|
->whereFollowingId($user->id)
|
||||||
|
->exists() : false;
|
||||||
|
return view('profile.private', compact('user', 'is_following', 'requested'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$is_admin = is_null($user->domain) ? $user->user->is_admin : false;
|
||||||
|
$profile = $user;
|
||||||
|
$settings = [
|
||||||
|
'crawlable' => $settings->crawlable,
|
||||||
|
'following' => [
|
||||||
|
'count' => $settings->show_profile_following_count,
|
||||||
|
'list' => $settings->show_profile_following
|
||||||
|
],
|
||||||
|
'followers' => [
|
||||||
|
'count' => $settings->show_profile_follower_count,
|
||||||
|
'list' => $settings->show_profile_followers
|
||||||
|
]
|
||||||
|
];
|
||||||
|
return view('profile.show', compact('profile', 'settings'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$owner = $loggedIn && Auth::id() === $user->user_id;
|
|
||||||
$is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false;
|
|
||||||
|
|
||||||
if ($isPrivate == true || $isBlocked == true) {
|
|
||||||
$requested = Auth::check() ? FollowRequest::whereFollowerId(Auth::user()->profile_id)
|
|
||||||
->whereFollowingId($user->id)
|
|
||||||
->exists() : false;
|
|
||||||
return view('profile.private', compact('user', 'is_following', 'requested'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$is_admin = is_null($user->domain) ? $user->user->is_admin : false;
|
|
||||||
$profile = $user;
|
|
||||||
$settings = [
|
|
||||||
'crawlable' => $settings->crawlable,
|
|
||||||
'following' => [
|
|
||||||
'count' => $settings->show_profile_following_count,
|
|
||||||
'list' => $settings->show_profile_following
|
|
||||||
],
|
|
||||||
'followers' => [
|
|
||||||
'count' => $settings->show_profile_follower_count,
|
|
||||||
'list' => $settings->show_profile_followers
|
|
||||||
]
|
|
||||||
];
|
|
||||||
return view('profile.show', compact('user', 'profile', 'settings', 'owner', 'is_following', 'is_admin'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function permalinkRedirect(Request $request, $username)
|
public function permalinkRedirect(Request $request, $username)
|
||||||
{
|
{
|
||||||
$user = Profile::whereUsername($username)->firstOrFail();
|
$user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||||
$settings = User::whereUsername($username)->firstOrFail()->settings;
|
|
||||||
|
|
||||||
if ($request->wantsJson() && config('federation.activitypub.enabled')) {
|
if ($request->wantsJson() && config('federation.activitypub.enabled')) {
|
||||||
return $this->showActivityPub($request, $user);
|
return $this->showActivityPub($request, $user);
|
||||||
|
@ -136,34 +149,19 @@ class ProfileController extends Controller
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function accountCheck(Profile $profile)
|
|
||||||
{
|
|
||||||
switch ($profile->status) {
|
|
||||||
case 'disabled':
|
|
||||||
case 'suspended':
|
|
||||||
case 'delete':
|
|
||||||
return view('profile.disabled');
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
# code...
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return abort(404);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function showActivityPub(Request $request, $user)
|
public function showActivityPub(Request $request, $user)
|
||||||
{
|
{
|
||||||
abort_if(!config('federation.activitypub.enabled'), 404);
|
abort_if(!config('federation.activitypub.enabled'), 404);
|
||||||
|
abort_if($user->domain, 404);
|
||||||
if($user->status != null) {
|
$key = 'profile:ap:' . $user->id;
|
||||||
return ProfileController::accountCheck($user);
|
$ttl = now()->addHours(6);
|
||||||
}
|
|
||||||
$fractal = new Fractal\Manager();
|
return Cache::remember($key, $ttl, function() use($user) {
|
||||||
$resource = new Fractal\Resource\Item($user, new ProfileTransformer);
|
$fractal = new Fractal\Manager();
|
||||||
$res = $fractal->createData($resource)->toArray();
|
$resource = new Fractal\Resource\Item($user, new ProfileTransformer);
|
||||||
return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json');
|
$res = $fractal->createData($resource)->toArray();
|
||||||
|
return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showAtomFeed(Request $request, $user)
|
public function showAtomFeed(Request $request, $user)
|
||||||
|
|
|
@ -29,14 +29,14 @@ trait PrivacySettings
|
||||||
|
|
||||||
public function privacyStore(Request $request)
|
public function privacyStore(Request $request)
|
||||||
{
|
{
|
||||||
$settings = Auth::user()->settings;
|
$settings = $request->user()->settings;
|
||||||
$profile = Auth::user()->profile;
|
$profile = $request->user()->profile;
|
||||||
$fields = [
|
$fields = [
|
||||||
'is_private',
|
'is_private',
|
||||||
'crawlable',
|
'crawlable',
|
||||||
'show_profile_follower_count',
|
'show_profile_follower_count',
|
||||||
'show_profile_following_count',
|
'show_profile_following_count',
|
||||||
];
|
];
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$form = $request->input($field);
|
$form = $request->input($field);
|
||||||
if ($field == 'is_private') {
|
if ($field == 'is_private') {
|
||||||
|
@ -65,7 +65,7 @@ trait PrivacySettings
|
||||||
}
|
}
|
||||||
$settings->save();
|
$settings->save();
|
||||||
}
|
}
|
||||||
|
Cache::forget('profile:settings:' . $profile->id);
|
||||||
return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!');
|
return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue