From 0153ed6d64ae7f97748ff7cf395f1196b27ae653 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 21 Jul 2021 02:00:57 -0600 Subject: [PATCH 1/2] Update Timeline, make text-only posts opt-in by default --- app/Http/Controllers/PublicApiController.php | 18 ++- app/Http/Controllers/SettingsController.php | 29 ++++ .../views/settings/partial/sidebar.blade.php | 125 +++++++++--------- resources/views/settings/timeline.blade.php | 30 +++++ routes/web.php | 3 + 5 files changed, 140 insertions(+), 65 deletions(-) create mode 100644 resources/views/settings/timeline.blade.php diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index bf94e2552..15e50feb8 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -16,6 +16,7 @@ use App\{ UserFilter }; use Auth, Cache; +use Illuminate\Support\Facades\Redis; use Carbon\Carbon; use League\Fractal; use App\Transformer\Api\{ @@ -401,6 +402,11 @@ class PublicApiController extends Controller } $filtered = $user ? UserFilterService::filters($user->profile_id) : []; + $textOnlyPosts = Redis::zscore('pf:tl:top', $pid) !== false; + $textOnlyReplies = Redis::zscore('pf:tl:replies', $pid) !== false; + $types = $textOnlyPosts ? + ['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'] : + ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album']; if($min || $max) { $dir = $min ? '>' : '<'; @@ -425,12 +431,14 @@ class PublicApiController extends Controller 'created_at', 'updated_at' ) - ->whereIn('type', ['text','photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) + ->whereIn('type', $types) + ->when(!$textOnlyReplies, function($q, $textOnlyReplies) { + return $q->whereNull('in_reply_to_id'); + }) ->with('profile', 'hashtags', 'mentions') ->where('id', $dir, $id) ->whereIn('profile_id', $following) ->whereNotIn('profile_id', $filtered) - ->whereNull('in_reply_to_id') ->whereIn('visibility',['public', 'unlisted', 'private']) ->orderBy('created_at', 'desc') ->limit($limit) @@ -456,11 +464,13 @@ class PublicApiController extends Controller 'created_at', 'updated_at' ) - ->whereIn('type', ['text','photo', 'photo:album', 'video', 'video:album', 'photo:video:album']) + ->whereIn('type', $types) + ->when(!$textOnlyReplies, function($q, $textOnlyReplies) { + return $q->whereNull('in_reply_to_id'); + }) ->with('profile', 'hashtags', 'mentions') ->whereIn('profile_id', $following) ->whereNotIn('profile_id', $filtered) - ->whereNull('in_reply_to_id') ->whereIn('visibility',['public', 'unlisted', 'private']) ->orderBy('created_at', 'desc') ->simplePaginate($limit); diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index e84ae0987..5f53fc727 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -8,6 +8,7 @@ use App\ProfileSponsor; use App\Report; use App\UserFilter; use Auth, Cookie, DB, Cache, Purify; +use Illuminate\Support\Facades\Redis; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Str; @@ -223,5 +224,33 @@ class SettingsController extends Controller return redirect(route('settings'))->with('status', 'Sponsor settings successfully updated!');; } + public function timelineSettings(Request $request) + { + $pid = $request->user()->profile_id; + $top = Redis::zscore('pf:tl:top', $pid) != false; + $replies = Redis::zscore('pf:tl:replies', $pid) != false; + return view('settings.timeline', compact('top', 'replies')); + } + + public function updateTimelineSettings(Request $request) + { + $pid = $request->user()->profile_id; + $top = $request->has('top') && $request->input('top') === 'on'; + $replies = $request->has('replies') && $request->input('replies') === 'on'; + + if($top) { + Redis::zadd('pf:tl:top', $pid, $pid); + } else { + Redis::zrem('pf:tl:top', $pid, $pid); + } + + if($replies) { + Redis::zadd('pf:tl:replies', $pid, $pid); + } else { + Redis::zrem('pf:tl:replies', $pid, $pid); + } + return redirect(route('settings.timeline')); + } + } diff --git a/resources/views/settings/partial/sidebar.blade.php b/resources/views/settings/partial/sidebar.blade.php index ac50f93e4..2be95ca2a 100644 --- a/resources/views/settings/partial/sidebar.blade.php +++ b/resources/views/settings/partial/sidebar.blade.php @@ -1,63 +1,66 @@ -
- +
diff --git a/resources/views/settings/timeline.blade.php b/resources/views/settings/timeline.blade.php new file mode 100644 index 000000000..a3b0c3646 --- /dev/null +++ b/resources/views/settings/timeline.blade.php @@ -0,0 +1,30 @@ +@extends('settings.template') + +@section('section') + +
+

Timeline Settings

+
+
+
+ @csrf +
+ + +

Show text-only posts from accounts you follow. (Home timeline only)

+
+
+ + +

Show replies from accounts you follow. (Home timeline only)

+
+ +
+
+
+ +
+
+
+ +@endsection diff --git a/routes/web.php b/routes/web.php index 514efbaf5..2300a5ca8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -426,6 +426,9 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('/', 'ImportController@mastodon')->name('settings.import.mastodon'); }); }); + + Route::get('timeline', 'SettingsController@timelineSettings')->name('settings.timeline'); + Route::post('timeline', 'SettingsController@updateTimelineSettings'); }); Route::group(['prefix' => 'site'], function () { From aa5b090af8dd89354f33fb330bb29dbb060e668c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 21 Jul 2021 02:03:16 -0600 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f81099c4d..1349f6060 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ - Updated StatusCard, add text support. ([ed14ee48](https://github.com/pixelfed/pixelfed/commit/ed14ee48)) - Updated PublicApiController, filter out text replies on home timeline. ([86219b57](https://github.com/pixelfed/pixelfed/commit/86219b57)) - Updated RemotePost.vue, improve text only post UI. ([b0257be2](https://github.com/pixelfed/pixelfed/commit/b0257be2)) +- Updated Timeline, make text-only posts opt-in by default. ([0153ed6d](https://github.com/pixelfed/pixelfed/commit/0153ed6d)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.0 (2021-06-01)](https://github.com/pixelfed/pixelfed/compare/v0.10.10...v0.11.0)