diff --git a/app/Http/Controllers/FollowerController.php b/app/Http/Controllers/FollowerController.php index fae861b88..808effa10 100644 --- a/app/Http/Controllers/FollowerController.php +++ b/app/Http/Controllers/FollowerController.php @@ -26,6 +26,11 @@ class FollowerController extends Controller ]); $item = $request->input('item'); $this->handleFollowRequest($item); + if($request->wantsJson()) { + return response()->json([ + 200 + ], 200); + } return redirect()->back(); } diff --git a/app/Http/Controllers/InternalApiController.php b/app/Http/Controllers/InternalApiController.php index 708543647..c07c3a5dd 100644 --- a/app/Http/Controllers/InternalApiController.php +++ b/app/Http/Controllers/InternalApiController.php @@ -136,34 +136,31 @@ class InternalApiController extends Controller }); $following = array_merge($following, $filters); - $people = Cache::remember('feature:discover:people:'.$pid, 15, function() use ($following) { - return Profile::select('id', 'name', 'username') + $people = Profile::select('id', 'name', 'username') ->with('avatar') - ->inRandomOrder() + ->orderByRaw('rand()') ->whereHas('statuses') ->whereNull('domain') ->whereNotIn('id', $following) ->whereIsPrivate(false) ->take(3) ->get(); - }); - $posts = Cache::remember('feature:discover:posts:'.$pid, 60, function() use ($following) { - return Status::select('id', 'caption', 'profile_id') + $posts = Status::select('id', 'caption', 'profile_id') ->whereNull('in_reply_to_id') ->whereNull('reblog_of_id') ->whereIsNsfw(false) ->whereVisibility('public') ->whereNotIn('profile_id', $following) - ->withCount(['comments', 'likes']) + ->with('media') ->orderBy('created_at', 'desc') ->take(21) ->get(); - }); $res = [ 'people' => $people->map(function($profile) { return [ + 'id' => $profile->id, 'avatar' => $profile->avatarUrl(), 'name' => $profile->name, 'username' => $profile->username, @@ -174,8 +171,6 @@ class InternalApiController extends Controller return [ 'url' => $post->url(), 'thumb' => $post->thumb(), - 'comments_count' => $post->comments_count, - 'likes_count' => $post->likes_count, ]; }) ]; diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index ff9a92eee..233316540 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -37,7 +37,7 @@ class ProfileController extends Controller $settings->show_profile_follower_count = true; $settings->show_profile_following_count = true; } else { - $settings = User::whereUsername($username)->firstOrFail()->settings; + $settings = $user->user->settings; } if ($request->wantsJson() && config('pixelfed.activitypub_enabled')) { @@ -101,7 +101,6 @@ class ProfileController extends Controller } return false; - } protected function blockedProfileCheck(Profile $profile) @@ -145,6 +144,7 @@ class ProfileController extends Controller public function followers(Request $request, $username) { $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; @@ -161,7 +161,10 @@ class ProfileController extends Controller $settings = new \StdClass; $settings->crawlable = false; } else { - $settings = User::whereUsername($username)->firstOrFail()->settings; + $settings = $profile->user->settings; + if(!$settings->show_profile_follower_count && !$owner) { + abort(403); + } } return view('profile.followers', compact('user', 'profile', 'followers', 'owner', 'is_following', 'is_admin', 'settings')); } @@ -185,7 +188,10 @@ class ProfileController extends Controller $settings = new \StdClass; $settings->crawlable = false; } else { - $settings = User::whereUsername($username)->firstOrFail()->settings; + $settings = $profile->user->settings; + if(!$settings->show_profile_follower_count && !$owner) { + abort(403); + } } return view('profile.following', compact('user', 'profile', 'following', 'owner', 'is_following', 'is_admin', 'settings')); } diff --git a/app/Jobs/FollowPipeline/FollowPipeline.php b/app/Jobs/FollowPipeline/FollowPipeline.php index 54489cc29..8e3bc2ed9 100644 --- a/app/Jobs/FollowPipeline/FollowPipeline.php +++ b/app/Jobs/FollowPipeline/FollowPipeline.php @@ -51,7 +51,7 @@ class FollowPipeline implements ShouldQueue $notification->save(); Cache::forever('notification.'.$notification->id, $notification); - + Cache::forget('feature:discover:people:'.$actor->id); $redis = Redis::connection(); $nkey = config('cache.prefix').':user.'.$target->id.'.notifications'; diff --git a/app/Listeners/AuthLogin.php b/app/Listeners/AuthLogin.php index f587c66a7..79e9c5eab 100644 --- a/app/Listeners/AuthLogin.php +++ b/app/Listeners/AuthLogin.php @@ -2,24 +2,18 @@ namespace App\Listeners; -use DB; -use App\User; -use App\UserSetting; +use DB, Cache; +use App\{ + Follower, + User, + UserFilter, + UserSetting +}; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; class AuthLogin { - /** - * Create the event listener. - * - * @return void - */ - public function __construct() - { - // - } - /** * Handle the event. * @@ -36,5 +30,22 @@ class AuthLogin ]); }); } + $this->warmCache($user); + } + + public function warmCache($user) + { + $pid = $user->profile->id; + + Cache::remember('feature:discover:following:'.$pid, 10080, function() use ($pid) { + return Follower::whereProfileId($pid)->pluck('following_id')->toArray(); + }); + + Cache::remember("user:filter:list:$pid", 10080, function() use($pid) { + return UserFilter::whereUserId($pid) + ->whereFilterableType('App\Profile') + ->whereIn('filter_type', ['mute', 'block']) + ->pluck('filterable_id')->toArray(); + }); } } diff --git a/public/js/components.js b/public/js/components.js index 457af0ff0..83390dd02 100644 Binary files a/public/js/components.js and b/public/js/components.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 841ba01b2..2447b3d34 100644 Binary files a/public/mix-manifest.json and b/public/mix-manifest.json differ diff --git a/resources/assets/js/components/DiscoverComponent.vue b/resources/assets/js/components/DiscoverComponent.vue index deb29d873..04182c37d 100644 --- a/resources/assets/js/components/DiscoverComponent.vue +++ b/resources/assets/js/components/DiscoverComponent.vue @@ -16,10 +16,7 @@

{{profile.username}}

{{profile.name}}

-
- - -
+ @@ -36,16 +33,6 @@
-
-
- - {{post.likes_count}} - - - {{post.comments_count}} - -
-
@@ -53,7 +40,7 @@
-

To view more posts, check the home, local or federated timelines.

+

To view more posts, check the home or local timelines.

@@ -68,10 +55,26 @@ export default { } }, mounted() { - this.fetchData(); + this.slowTimeout(); + this.fetchData(); }, methods: { + followUser(id, event) { + axios.post('/i/follow', { + item: id + }).then(res => { + let el = $(event.target); + el.addClass('btn-outline-secondary').removeClass('btn-primary'); + el.text('Unfollow'); + }).catch(err => { + swal( + 'Whoops! Something went wrong...', + 'An error occured, please try again later.', + 'error' + ); + }); + }, fetchData() { axios.get('/api/v2/discover') .then((res) => { @@ -80,16 +83,23 @@ export default { this.posts = data.posts; if(this.people.length > 1) { - $('.section-people .lds-ring').hide(); + $('.section-people .loader').hide(); $('.section-people .row.d-none').removeClass('d-none'); } if(this.posts.length > 1) { - $('.section-explore .lds-ring').hide(); + $('.section-explore .loader').hide(); $('.section-explore .row.d-none').removeClass('d-none'); } }); - } + }, + slowTimeout() { + setTimeout(function() { + let el = $('

').addClass('font-weight-bold').text('This is taking longer than expected to load. Please try reloading the page if this does not load after 30 seconds.'); + $('.section-people .loader').append(el); + $('.section-explore .loader').append(el); + }, 5000); + } } } \ No newline at end of file diff --git a/resources/assets/js/components/PostComments.vue b/resources/assets/js/components/PostComments.vue index d93396c8f..4dbb3f776 100644 --- a/resources/assets/js/components/PostComments.vue +++ b/resources/assets/js/components/PostComments.vue @@ -18,7 +18,7 @@

-

+