From 95799c5c70549389e5c622b77e84c58b2454ca6a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 27 Nov 2018 01:41:32 -0700 Subject: [PATCH 1/7] Update FollowPipeline --- app/Jobs/FollowPipeline/FollowPipeline.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'; From 1aa8354f5a05307ddcdcf2dfdce7db11179470ed Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 27 Nov 2018 01:42:08 -0700 Subject: [PATCH 2/7] Update ProfileController --- app/Http/Controllers/ProfileController.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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')); } From 1073892c665c4136b42d0bf9e4455c44a8c0e57f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 27 Nov 2018 01:42:31 -0700 Subject: [PATCH 3/7] Update FollowerController --- app/Http/Controllers/FollowerController.php | 5 +++++ 1 file changed, 5 insertions(+) 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(); } From 77569b7e8e7decedbc9aab97e92d7a494d44cac4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 27 Nov 2018 01:54:10 -0700 Subject: [PATCH 4/7] Update AuthLogin listener --- app/Listeners/AuthLogin.php | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) 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(); + }); } } From 2254ecf27d69623e5808c0d97be02e8178e43a86 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 27 Nov 2018 01:55:10 -0700 Subject: [PATCH 5/7] Update InternalApiController --- app/Http/Controllers/InternalApiController.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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, ]; }) ]; From 9a7d13ebf2fe62de82da49875cb6df3398f797d6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 27 Nov 2018 01:56:22 -0700 Subject: [PATCH 6/7] Update DiscoverComponent --- .../js/components/DiscoverComponent.vue | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) 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 From 7494d97bbd4b4a7480a90f64892760a91cb19b9a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 27 Nov 2018 01:58:39 -0700 Subject: [PATCH 7/7] Update compiled assets --- public/js/components.js | Bin 424608 -> 424511 bytes public/mix-manifest.json | Bin 321 -> 321 bytes .../assets/js/components/PostComments.vue | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/components.js b/public/js/components.js index 457af0ff0a56de263e6d2dfe4baca6cf5f2a5447..83390dd025cd03ed9fca8e7d5e8a60a13a8d5584 100644 GIT binary patch delta 950 zcmZuwO=uKJ6sCK+Cay8T7!o&b)JhrGZl=;RNpK|5NKn*e@ep?tvZ&eJ&U9s_wWq4L zyC!BBn>{G(f(Vf|JTxAJy(}xNKRGlk#IPWESa9*I2;Mw+R6KaungrCtLOpo(>U-~f z@8i|&w>@ibdhY$J898^b4yV?P9qITYs%7A=p__2^z19Ks8)yp*jT@agZZ)JmCwyOA zn2K0vGTU=0x8gXaXQchZyh)C)KN4#O9wz8%@^$wfVAoI=Jidc;vSuuJ z`dsUTn-7g6$!XjPpWQ^iHJwyBCp0Y&rE5RSjhycBX zx>lZOyN&ip%`&MVq9#p?Ca+L$;lq5Rb2VO)p5UgW%xX9bo`~!~MA9UAFTbG!p$(WQ zp&f8g(>NUkTS|!e*?d{P8$2ZAzMTj8k!*HMIUAk?<$$otVR$YXXXCrM%KHEUT zaaow$&z}F_btfY&`8N8=#G}dKN8QP@cdc9Ioe)b!o*W7e!xf@``SWDOi?BMZ46$`vfaT*&n# z?9543aJYasA@_~Sfz-QQQ)?=a4$_WC-T~k{0BaRO!Hoge|7Z=n0 zY`D3eF(rj+#MbvaDSR`Lj$TBUHm&$AnW9k)=ckgNT6#0p;#bLH%RYGWg`V3sSS%FW zk-=d?J=#~Gjo7;6kNx70Y07kE8D&Q5kD-+wgQ-mT`!XuRiwEfYboVs+vp-$EjLNO) zkz44;ZX-N*t^hAL>)X@m6?EYDOlh_b9lbhDkDbl#-MO<#jaamAkbYb^tHDjuqz1HA R?}t0}?9j#+eOb@0{Rh)UMM?kw delta 724 zcmaKqO-vI(6vxwccl%u-P@q_`9l&(yZtJ3a=mBElM*=4|#xDZ6w$pZDw~O0_Qq77H zBF4lheTO+92?-uJ5ll^bGI&xG56aPtO-xKYang9yrA7`O%;cZ^X5PI2o4k2D-$Uy^ zLfao~m87?WA`A1hAJju0lA33d@UEfgOc!`v&S&9lSO_M`HQY%433|CHv zzw}Xqy(1T_T`Ro5(Xm()musTUlHHQS5>>5Xt{f;LYnTos?S#F ztk;neE|t%B>6hUzd3Nf5e;w!Qo`xr`4fwp|gtv2kUq(|Dt;lCIT}5CkMwvec&{I767l+MwdC70YOuG#D(!>v!)6$I;AhU)jYutQAAw)}P4yz*+|RAF$DW9dgKf`%#Xmg=wmhfW zI<2mAV@6Ic)O(Y`X{<{IPJ_qWRkg3tQVWA_VJV5o`U>4oo+|W2HC3U-O-KK=D-adi zsr@Jni(+H1fCn?_0ReHc_4(W#v-)C;xq75NHsnm14myig4q{F6sKg*LT4Drh#u^}U Iuf**92JETwUjP6A diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 841ba01b298e779953a8e06bdf58009ccdf6543e..2447b3d34d5d7d826b265156f899892972212b3b 100644 GIT binary patch delta 29 kcmX@ebdYI+p>VR1MM`3Fa$>5vxj|ZzNm6Q(=|q>m0FloMLjV8( delta 29 kcmX@ebdYI+p|FX8rKLftiFs