added a queue for posting activities

This commit is contained in:
Ghostie 2025-01-11 15:29:26 -05:00
parent c0ad0c46d6
commit 7e3b868a90
8 changed files with 30 additions and 10 deletions

View File

@ -202,13 +202,28 @@ php artisan storage:link
php artisan install:broadcasting php artisan install:broadcasting
``` ```
Now, we need to create two services to handle the jobs that OurSpace needs to run and another one to run Laravel Reverb. So run something `emacs /lib/systemd/system/ourspace-queue.service` and `emacs /lib/systemd/system/ourspace-ws.service` and add the following content: Now, we need to create three services to handle the jobs that OurSpace needs to run, another to handle the notifications' queue and another one to run Laravel Reverb. So run something `emacs /lib/systemd/system/ourspace-queue.service`, `emacs /lib/systemd/system/ourspace-notifications.service`, `emacs /lib/systemd/system/ourspace-ws.service` and add the following content:
```ini ```ini
# /lib/systemd/system/ourspace-queue.service # /lib/systemd/system/ourspace-queue.service
[Unit] [Unit]
Description=OurSpace queue worker Description=OurSpace queue worker
[Service]
User=www-data
Group=www-data
Restart=on-failure
ExecStart=/usr/bin/php /var/www/html/ourspace/artisan queue:work --daemon --env=production --queue=ap
[Install]
WantedBy=multi-user.target
```
```ini
# /lib/systemd/system/ourspace-notifications.service
[Unit]
Description=OurSpace notifications worker
[Service] [Service]
User=www-data User=www-data
Group=www-data Group=www-data

View File

@ -18,6 +18,9 @@ class PostController extends Controller
{ {
$actor = $note->get_actor ()->first (); $actor = $note->get_actor ()->first ();
if (!$actor)
return redirect ()->back ();
return view ("posts.show", compact ("note", "actor")); return view ("posts.show", compact ("note", "actor"));
} }

View File

@ -170,8 +170,9 @@ class ProfileController extends Controller
return redirect ()->route ("login"); return redirect ()->route ("login");
$user = auth ()->user (); $user = auth ()->user ();
$unread_notifications = $user->notifications; $user_notifications = $user->notifications;
$notifications = PaginationHelper::paginate (collect ($unread_notifications), 20); $notifications = PaginationHelper::paginate (collect ($user_notifications), 20);
$unread_notifications = $user->unreadNotifications->count ();
$processed_notifications = []; $processed_notifications = [];
foreach ($notifications as $notification) foreach ($notifications as $notification)
@ -212,6 +213,6 @@ class ProfileController extends Controller
$notification->markAsRead (); $notification->markAsRead ();
} }
return view ("users.notifications", compact ("user", "notifications", "processed_notifications")); return view ("users.notifications", compact ("user", "notifications", "processed_notifications", "unread_notifications"));
} }
} }

View File

@ -27,7 +27,7 @@ class UserUnfollowedListener
*/ */
public function handle(UserUnfollowedEvent $event): void public function handle(UserUnfollowedEvent $event): void
{ {
$follow_exists = Follow::where("actor_id", $event->actor->id) $follow_exists = Follow::where ("actor_id", $event->actor->id)
->where("object_id", $event->object->id) ->where("object_id", $event->object->id)
->first(); ->first();
@ -38,7 +38,7 @@ class UserUnfollowedListener
if (!$user) if (!$user)
return; return;
$user->notify(new UserNotification( $user->notify (new UserNotification (
"Unfollow", "Unfollow",
$event->actor->id, $event->actor->id,
$event->object->id, $event->object->id,

View File

@ -4,10 +4,11 @@ namespace App\Notifications;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification; use Illuminate\Notifications\Notification;
class UserNotification extends Notification class UserNotification extends Notification implements ShouldQueue
{ {
use Queueable; use Queueable;

View File

@ -237,7 +237,7 @@ class TypeActivity {
public static function post_activity (Activity $activity, Actor $source, $target, $should_sign = false) public static function post_activity (Activity $activity, Actor $source, $target, $should_sign = false)
{ {
PostActivityJob::dispatch ($activity, $source, $target, $should_sign); PostActivityJob::dispatch ($activity, $source, $target, $should_sign)->onQueue ("ap");
return [ return [
"success" => "activity posted" "success" => "activity posted"

View File

@ -3,6 +3,7 @@
@section ("title", "View Post") @section ("title", "View Post")
@section ("content") @section ("content")
<div class="row article blog-entry"> <div class="row article blog-entry">
<div class="col w-20 left"> <div class="col w-20 left">
<div class="edit-info"> <div class="edit-info">

View File

@ -5,8 +5,7 @@
@section ("content") @section ("content")
<div class="simple-container"> <div class="simple-container">
<h1>Notifications</h1> <h1>Notifications</h1>
<p>You have <b>{{ count ($user->unreadNotifications) }}</b> unread notifications</p> <p>You have <b>{{ $unread_notifications }}</b> unread notifications</p>
<br>
<table border="1" width="100%"> <table border="1" width="100%">
<tr> <tr>