I forgot the notification when someone replies to any of your posts
This commit is contained in:
parent
1baabb7649
commit
e11c5402f6
34
app/Events/NoteRepliedEvent.php
Normal file
34
app/Events/NoteRepliedEvent.php
Normal 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;
|
||||
}
|
||||
}
|
@ -6,8 +6,9 @@ use App\Models\Like;
|
||||
|
||||
use App\Events\NoteLikedEvent;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Notifications\UserNotification;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
|
45
app/Listeners/NoteRepliedListener.php
Normal file
45
app/Listeners/NoteRepliedListener.php
Normal 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
|
||||
));
|
||||
}
|
||||
}
|
@ -8,7 +8,11 @@ use App\Models\Actor;
|
||||
use App\Models\Activity;
|
||||
use App\Models\NoteAttachment;
|
||||
use App\Models\NoteMention;
|
||||
|
||||
use App\Events\NoteRepliedEvent;
|
||||
|
||||
use App\Notifications\UserNotification;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@ -63,8 +67,6 @@ class TypeNote
|
||||
];
|
||||
}
|
||||
|
||||
Log::info (json_encode ($response));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@ -157,6 +159,8 @@ class TypeNote
|
||||
$parent_exists = TypeNote::obtain_external ($request ["inReplyTo"]);
|
||||
|
||||
$note->in_reply_to = $parent_exists ? $parent_exists->note_id : null;
|
||||
|
||||
NoteRepliedEvent::dispatch ($activity, $actor, $parent_exists);
|
||||
}
|
||||
|
||||
if (isset ($request ["tag"]) && $request ["tag"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user