From 3662d3defeb0c87ce68215e0b1aa0b59962dd775 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 19 May 2023 04:53:52 -0600 Subject: [PATCH] Update Settings, allow users to disable atom feeds --- app/Http/Controllers/ProfileController.php | 16 +++++++++++ .../Controllers/Settings/PrivacySettings.php | 12 +++++--- ...nable_atom_feed_to_user_settings_table.php | 28 +++++++++++++++++++ resources/views/settings/privacy.blade.php | 18 ++++++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 database/migrations/2023_05_19_102013_add_enable_atom_feed_to_user_settings_table.php diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 408c5be32..df25b2d7b 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -13,6 +13,7 @@ use App\FollowRequest; use App\Profile; use App\Story; use App\User; +use App\UserSetting; use App\UserFilter; use League\Fractal; use App\Services\AccountService; @@ -236,6 +237,21 @@ class ProfileController extends Controller abort_if($aiCheck, 404); + $enabled = Cache::remember('profile:atom:enabled:' . $profile['id'], 84600, function() use ($profile) { + $uid = User::whereProfileId($profile['id'])->first(); + if(!$uid) { + return false; + } + $settings = UserSetting::whereUserId($uid->id)->first(); + if(!$settings) { + return false; + } + + return $settings->show_atom; + }); + + abort_if(!$enabled, 404); + $data = Cache::remember('pf:atom:user-feed:by-id:' . $profile['id'], 900, function() use($pid, $profile) { $items = DB::table('statuses') ->whereProfileId($pid) diff --git a/app/Http/Controllers/Settings/PrivacySettings.php b/app/Http/Controllers/Settings/PrivacySettings.php index 3cee63322..3d1cd4515 100644 --- a/app/Http/Controllers/Settings/PrivacySettings.php +++ b/app/Http/Controllers/Settings/PrivacySettings.php @@ -20,11 +20,13 @@ trait PrivacySettings public function privacy() { - $settings = Auth::user()->settings; - $is_private = Auth::user()->profile->is_private; - $settings['is_private'] = (bool) $is_private; + $user = Auth::user(); + $settings = $user->settings; + $profile = $user->profile; + $is_private = $profile->is_private; + $settings['is_private'] = (bool) $is_private; - return view('settings.privacy', compact('settings')); + return view('settings.privacy', compact('settings', 'profile')); } public function privacyStore(Request $request) @@ -37,6 +39,7 @@ trait PrivacySettings 'public_dm', 'show_profile_follower_count', 'show_profile_following_count', + 'show_atom', ]; $profile->is_suggestable = $request->input('is_suggestable') == 'on'; @@ -80,6 +83,7 @@ trait PrivacySettings Cache::forget('user:account:id:' . $profile->user_id); Cache::forget('profile:follower_count:' . $profile->id); Cache::forget('profile:following_count:' . $profile->id); + Cache::forget('profile:atom:enabled:' . $profile->id); Cache::forget('profile:embed:' . $profile->id); Cache::forget('pf:acct:settings:hidden-followers:' . $profile->id); Cache::forget('pf:acct:settings:hidden-following:' . $profile->id); diff --git a/database/migrations/2023_05_19_102013_add_enable_atom_feed_to_user_settings_table.php b/database/migrations/2023_05_19_102013_add_enable_atom_feed_to_user_settings_table.php new file mode 100644 index 000000000..5aee6d8b8 --- /dev/null +++ b/database/migrations/2023_05_19_102013_add_enable_atom_feed_to_user_settings_table.php @@ -0,0 +1,28 @@ +boolean('show_atom')->default(true); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('user_settings', function (Blueprint $table) { + $table->dropColumn('show_atom'); + }); + } +}; diff --git a/resources/views/settings/privacy.blade.php b/resources/views/settings/privacy.blade.php index 8c4142908..78ead55ee 100644 --- a/resources/views/settings/privacy.blade.php +++ b/resources/views/settings/privacy.blade.php @@ -88,6 +88,24 @@

Display following count on profile

+ @if(!$settings->is_private) +
+ show_atom ? 'checked=""':''}}> + +

Enable your profile atom feed. Only public profiles are eligible.

+ @if($settings->show_atom) +

+ + {{ $profile->permalink('.atom') }} + + +

+ @endif +
+ @endif +