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
```
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
# /lib/systemd/system/ourspace-queue.service
[Unit]
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]
User=www-data
Group=www-data

View File

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

View File

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

View File

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

View File

@ -237,7 +237,7 @@ class TypeActivity {
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 [
"success" => "activity posted"

View File

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

View File

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