I forgot the notification when someone replies to any of your posts

This commit is contained in:
Ghostie 2025-01-09 21:26:29 -05:00
parent 1baabb7649
commit e11c5402f6
4 changed files with 87 additions and 3 deletions

View File

@ -0,0 +1,34 @@
<?php
namespace App\Events;
use App\Models\Activity;
use App\Models\Actor;
use App\Models\Note;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class NoteRepliedEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public Activity $activity;
public Actor $actor;
public Note $object;
/**
* Create a new event instance.
*/
public function __construct(Activity $activity, Actor $actor, Note $object)
{
$this->activity = $activity;
$this->actor = $actor;
$this->object = $object;
}
}

View File

@ -6,8 +6,9 @@ use App\Models\Like;
use App\Events\NoteLikedEvent; use App\Events\NoteLikedEvent;
use Illuminate\Support\Facades\Log;
use App\Notifications\UserNotification; use App\Notifications\UserNotification;
use Illuminate\Support\Facades\Log;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;

View File

@ -0,0 +1,45 @@
<?php
namespace App\Listeners;
use App\Models\User;
use App\Events\NoteRepliedEvent;
use Illuminate\Support\Facades\Log;
use App\Notifications\UserNotification;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class NoteRepliedListener
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(NoteRepliedEvent $event): void
{
$note_actor = $event->object->get_actor ()->first ();
Log::info ("hi");
if (!$note_actor || !$note_actor->user)
return;
Log::info ("bai");
$note_actor->user->notify (new UserNotification(
"Reply",
$event->actor->id,
$event->object->id,
$event->activity->id
));
}
}

View File

@ -8,7 +8,11 @@ use App\Models\Actor;
use App\Models\Activity; use App\Models\Activity;
use App\Models\NoteAttachment; use App\Models\NoteAttachment;
use App\Models\NoteMention; use App\Models\NoteMention;
use App\Events\NoteRepliedEvent;
use App\Notifications\UserNotification; use App\Notifications\UserNotification;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@ -63,8 +67,6 @@ class TypeNote
]; ];
} }
Log::info (json_encode ($response));
return $response; return $response;
} }
@ -157,6 +159,8 @@ class TypeNote
$parent_exists = TypeNote::obtain_external ($request ["inReplyTo"]); $parent_exists = TypeNote::obtain_external ($request ["inReplyTo"]);
$note->in_reply_to = $parent_exists ? $parent_exists->note_id : null; $note->in_reply_to = $parent_exists ? $parent_exists->note_id : null;
NoteRepliedEvent::dispatch ($activity, $actor, $parent_exists);
} }
if (isset ($request ["tag"]) && $request ["tag"]) if (isset ($request ["tag"]) && $request ["tag"])