Add a push notification when a user is mentioned in a comment

This commit is contained in:
Anil Kulkarni 2025-01-12 13:29:13 -08:00
parent 4ce6e610bd
commit 64bad4ee4d
No known key found for this signature in database
GPG key ID: 4806669421E998D3

View file

@ -5,11 +5,15 @@ namespace App\Jobs\MentionPipeline;
use App\Mention; use App\Mention;
use App\Notification; use App\Notification;
use App\Status; use App\Status;
use App\User;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use App\Jobs\PushNotificationPipeline\MentionPushNotifyPipeline;
use App\Services\NotificationAppGatewayService;
use App\Services\PushNotificationService;
use App\Services\StatusService; use App\Services\StatusService;
class MentionPipeline implements ShouldQueue class MentionPipeline implements ShouldQueue
@ -57,7 +61,7 @@ class MentionPipeline implements ShouldQueue
->count(); ->count();
if ($actor->id === $target || $exists !== 0) { if ($actor->id === $target || $exists !== 0) {
return true; return;
} }
Notification::firstOrCreate( Notification::firstOrCreate(
@ -71,5 +75,14 @@ class MentionPipeline implements ShouldQueue
); );
StatusService::del($status->id); StatusService::del($status->id);
if (NotificationAppGatewayService::enabled()) {
if (PushNotificationService::check('mention', $target)) {
$user = User::whereProfileId($target)->first();
if ($user && $user->expo_token && $user->notify_enabled) {
MentionPushNotifyPipeline::dispatch($user->expo_token, $actor->username)->onQueue('pushnotify');
}
}
}
} }
} }