added a queue for posting activities
This commit is contained in:
parent
c0ad0c46d6
commit
7e3b868a90
17
README.md
17
README.md
@ -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
|
||||||
|
@ -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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
@ -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">
|
||||||
|
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user