From 25f00b1dc7e2a148a650bf7cdb521d3a7f2ad686 Mon Sep 17 00:00:00 2001 From: Ghostie Date: Sun, 12 Jan 2025 16:51:59 -0500 Subject: [PATCH] Added support for custom notification sounds --- app/Http/Controllers/ProfileController.php | 16 ++++++++++++++++ app/Models/User.php | 7 +++++++ resources/views/partials/layout.blade.php | 2 +- resources/views/users/edit.blade.php | 8 +++++++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index baba677..da5f4b6 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -58,6 +58,7 @@ class ProfileController extends Controller $incoming_fields = $request->validate ([ "avatar" => "image|max:4096", "song" => "file|mimes:audio/mpeg,mp3|max:4096", + "notification_sound" => "file|mimes:audio/mpeg,mp3|max:1024", "bio" => "sometimes|nullable|string", "about_you" => "sometimes|nullable|string", "status" => "sometimes|nullable|string", @@ -76,9 +77,11 @@ class ProfileController extends Controller $changing_avatar = false; $changing_song = false; + $changing_notification_sound = false; $old_avatar = null; $old_song = null; + $old_notification_sound = null; if (isset ($incoming_fields["avatar"]) && !empty ($incoming_fields["avatar"])) { $manager = new ImageManager (new Driver ()); @@ -104,6 +107,16 @@ class ProfileController extends Controller $changing_song = true; } + if (isset ($incoming_fields ["notification_sound"]) && !empty ($incoming_fields["notification_sound"])) + { + $file = $request->file ("notification_sound"); + Storage::disk ("public")->put ("notification_sounds/" . $fname . ".mp3", file_get_contents ($file)); + + $old_notification_sound = "notification_sounds/" . $user->notification_sound; + $user->notification_sound = $fname . ".mp3"; + $changing_notification_sound = true; + } + $user->bio = $incoming_fields["bio"]; $user->about_you = $incoming_fields["about_you"]; $user->status = $incoming_fields["status"]; @@ -128,6 +141,9 @@ class ProfileController extends Controller if ($changing_song) Storage::disk ("public")->delete (str_replace ("/storage/", "", $old_song)); + if ($changing_notification_sound) + Storage::disk ("public")->delete (str_replace ("/storage/", "", $old_notification_sound)); + $response = ActionsUser::update_profile (); if (isset ($response["error"])) return back ()->with ("error", "Error updating profile: " . $response["error"]); diff --git a/app/Models/User.php b/app/Models/User.php index 5be5476..7b9947d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -82,6 +82,13 @@ class User extends Authenticatable }); } + protected function notificationSound () : Attribute + { + return Attribute::make (get: function ($value) { + return $value ? "/storage/notification_sounds/" . $value : "/resources/sounds/notification.mp3"; + }); + } + public function actor () { return $this->hasOne (Actor::class); diff --git a/resources/views/partials/layout.blade.php b/resources/views/partials/layout.blade.php index 5514170..3117785 100644 --- a/resources/views/partials/layout.blade.php +++ b/resources/views/partials/layout.blade.php @@ -44,7 +44,7 @@ @if (auth ()->check ())