Update FollowPipeline

This commit is contained in:
Daniel Supernault 2024-09-30 04:45:36 -06:00
parent bd96840587
commit 7b4256549a
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -3,7 +3,13 @@
namespace App\Jobs\FollowPipeline;
use App\Follower;
use App\Jobs\PushNotificationPipeline\FollowPushNotifyPipeline;
use App\Notification;
use App\Services\AccountService;
use App\Services\FollowerService;
use App\Services\NotificationAppGatewayService;
use App\Services\PushNotificationService;
use App\User;
use Cache;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@ -11,9 +17,6 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Log;
use Illuminate\Support\Facades\Redis;
use App\Services\AccountService;
use App\Services\FollowerService;
class FollowPipeline implements ShouldQueue
{
@ -49,16 +52,16 @@ class FollowPipeline implements ShouldQueue
$actor = $follower->actor;
$target = $follower->target;
if(!$actor || !$target) {
if (! $actor || ! $target) {
return;
}
if($target->domain || !$target->private_key) {
if ($target->domain || ! $target->private_key) {
return;
}
Cache::forget('profile:following:' . $actor->id);
Cache::forget('profile:following:' . $target->id);
Cache::forget('profile:following:'.$actor->id);
Cache::forget('profile:following:'.$target->id);
FollowerService::add($actor->id, $target->id);
@ -72,9 +75,9 @@ class FollowPipeline implements ShouldQueue
$target->save();
AccountService::del($target->id);
if($target->user_id && $target->domain === null) {
if ($target->user_id && $target->domain === null) {
try {
$notification = new Notification();
$notification = new Notification;
$notification->profile_id = $target->id;
$notification->actor_id = $actor->id;
$notification->action = 'follow';
@ -84,6 +87,15 @@ class FollowPipeline implements ShouldQueue
} catch (Exception $e) {
Log::error($e);
}
if (NotificationAppGatewayService::enabled()) {
if (PushNotificationService::check('follow', $target->id)) {
$user = User::whereProfileId($target->id)->first();
if ($user && $user->expo_token && $user->notify_enabled) {
FollowPushNotifyPipeline::dispatchSync($user->expo_token, $actor->username);
}
}
}
}
}
}