From c0ad0c46d639561caac52b0669ed6cdb8e43c489 Mon Sep 17 00:00:00 2001 From: Ghostie Date: Sat, 11 Jan 2025 14:51:17 -0500 Subject: [PATCH] added the signup notification --- README.md | 14 ++++++ app/Events/UserSignedUp.php | 28 +++++++++++ app/Http/Controllers/HomeController.php | 6 ++- app/Http/Controllers/ProfileController.php | 6 ++- app/Http/Controllers/UserController.php | 11 ++--- app/Listeners/UserSignedUpListener.php | 48 +++++++++++++++++++ resources/views/browse.blade.php | 2 + resources/views/users/notifications.blade.php | 16 +++++-- resources/views/users/profile.blade.php | 2 +- 9 files changed, 118 insertions(+), 15 deletions(-) create mode 100644 app/Events/UserSignedUp.php create mode 100644 app/Listeners/UserSignedUpListener.php diff --git a/README.md b/README.md index 35346eb..355c2e7 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,7 @@ WantedBy=multi-user.target ``` ```ini +# /lib/systemd/system/ourspace-ws.service [Unit] Description=OurSpace WebSockets Service @@ -233,8 +234,21 @@ ExecStart=/usr/bin/php /var/www/html/ourspace/artisan reverb:start WantedBy=multi-user.target ``` +Now reload the systemd daemon: + +```bash +sudo systemctl daemon-reload +``` + Finally, enable and start both services, and your OurSpace instance will be ready to be used! +Aditionally, if you want to start multiple instances of the queue workers (which is ideal) you can name the service like `/lib/systemd/system/ourspace-queue@.service` and you can enable and manage them like this: + +```bash +sudo systemctl enable ourspace-queue\{1..6} # enables 6 services +sudo systemctl start ourspace-queue\{1..6} # starts 6 services +``` + ## TODO: For a list of planned features and improvements, please refer to the [TODO](TODO.md) file. diff --git a/app/Events/UserSignedUp.php b/app/Events/UserSignedUp.php new file mode 100644 index 0000000..6fcdcf0 --- /dev/null +++ b/app/Events/UserSignedUp.php @@ -0,0 +1,28 @@ +user = $user; + } +} diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index d87ca9c..5450ddc 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -42,15 +42,17 @@ class HomeController extends Controller if (request ()->get ("posts") == "latest") { - $notes = Note::latest ()->where ("in_reply_to", null)->take (10)->get (); + $notes = Note::latest (); } else { $notes = Note::withCount ([ "get_likes" => function ($query) { $query->where ("created_at", ">=", now ()->subDay ()); - }])->where ("in_reply_to", null)->orderBy ("get_likes_count", "desc")->take (8)->get (); + }])->where ("in_reply_to", null)->orderBy ("get_likes_count", "desc"); } + $notes = $notes->paginate (10); + return view ("browse", compact ("users", "popular_hashtags", "notes")); } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index ac04122..698402c 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -57,7 +57,7 @@ class ProfileController extends Controller $incoming_fields = $request->validate ([ "avatar" => "image|max:4096", - "song" => "file|mimes:audio/mpeg,mp3|max:1024", + "song" => "file|mimes:audio/mpeg,mp3|max:4096", "bio" => "sometimes|nullable|string", "about_you" => "sometimes|nullable|string", "status" => "sometimes|nullable|string", @@ -188,6 +188,10 @@ class ProfileController extends Controller $object = Actor::find ($data["object"]); break; + case "Signup": + $object = User::find ($data ["object"]); + break; + case "Like": case "Reply": case "Boost": diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index bcc3447..225f6de 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -7,6 +7,8 @@ use App\Models\Actor; use App\Actions\ActionsFriends; +use App\Events\UserSignedUp; + use Illuminate\Http\Request; class UserController extends Controller @@ -30,14 +32,9 @@ class UserController extends Controller ]); $user = User::create ($incoming_fields); - $actor = new Actor (); - $actor->create_from_user ($user); - auth ()->login ($user); - // create a friendship between the new user and the admin - $admin = User::where ("is_admin", 1)->first (); - if ($admin) - ActionsFriends::force_friendship ($user, $admin); + UserSignedUp::dispatch ($user); + auth ()->login ($user); return redirect ()->route ("home")->with ("success", "You have successfuly signed up!"); } diff --git a/app/Listeners/UserSignedUpListener.php b/app/Listeners/UserSignedUpListener.php new file mode 100644 index 0000000..a0322a4 --- /dev/null +++ b/app/Listeners/UserSignedUpListener.php @@ -0,0 +1,48 @@ +create_from_user ($event->user); + + // create a friendship between the new user and the admin + $admin = User::where ("is_admin", 1)->first (); + if ($admin) + { + ActionsFriends::force_friendship ($event->user, $admin); + + $admin->notify (new UserNotification( + "Signup", + $actor->id, + $event->user->id + )); + } + } +} diff --git a/resources/views/browse.blade.php b/resources/views/browse.blade.php index 99f4e06..b5dbc6a 100644 --- a/resources/views/browse.blade.php +++ b/resources/views/browse.blade.php @@ -53,5 +53,7 @@ @endforeach + + {{ $notes->links("pagination::default") }} @endsection diff --git a/resources/views/users/notifications.blade.php b/resources/views/users/notifications.blade.php index b23fb64..67ece07 100644 --- a/resources/views/users/notifications.blade.php +++ b/resources/views/users/notifications.blade.php @@ -19,13 +19,21 @@ @foreach ($processed_notifications as $notification) - -

{{ $notification ['actor']->name }}

-
+ @if ($notification ['type'] == 'Signup') + +

{{ $notification ['object']->actor->preferredUsername }}

+
+ @else + +

{{ $notification ['actor']->name }}

+
+ @endif - @if ($notification ['type'] == 'Follow') + @if ($notification ['type'] == 'Signup') +

Joined Ourspace! Say something!!

+ @elseif ($notification ['type'] == 'Follow')

Followed you

@elseif ($notification ['type'] == 'Unfollow')

Unfollowed you

diff --git a/resources/views/users/profile.blade.php b/resources/views/users/profile.blade.php index dd44f25..84e7ff6 100644 --- a/resources/views/users/profile.blade.php +++ b/resources/views/users/profile.blade.php @@ -40,7 +40,7 @@ @endif