Update LikePipeline

This commit is contained in:
Daniel Supernault 2024-10-01 23:59:52 -06:00
parent 873031538d
commit 6889fffbfb
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -2,19 +2,24 @@
namespace App\Jobs\LikePipeline;
use Cache, DB, Log;
use Illuminate\Support\Facades\Redis;
use App\{Like, Notification};
use App\Jobs\PushNotificationPipeline\LikePushNotifyPipeline;
use App\Like;
use App\Notification;
use App\Services\NotificationAppGatewayService;
use App\Services\PushNotificationService;
use App\Services\StatusService;
use App\Transformer\ActivityPub\Verb\Like as LikeTransformer;
use App\User;
use App\Util\ActivityPub\Helpers;
use DB;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Util\ActivityPub\Helpers;
use Illuminate\Support\Lottery;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
use App\Transformer\ActivityPub\Verb\Like as LikeTransformer;
use App\Services\StatusService;
class LikePipeline implements ShouldQueue
{
@ -30,6 +35,7 @@ class LikePipeline implements ShouldQueue
public $deleteWhenMissingModels = true;
public $timeout = 5;
public $tries = 1;
/**
@ -54,17 +60,25 @@ class LikePipeline implements ShouldQueue
$status = $this->like->status;
$actor = $this->like->actor;
if (!$status) {
if (! $status) {
// Ignore notifications to deleted statuses
return;
}
Lottery::odds(1, 20)
->winner(function () use ($status) {
$status->likes_count = DB::table('likes')->whereStatusId($status->id)->count();
$status->save();
})
->loser(function () use ($status) {
$status->likes_count = $status->likes_count + 1;
$status->save();
})
->choose();
StatusService::refresh($status->id);
if($status->url && $actor->domain == null) {
if ($status->url && $actor->domain == null) {
return $this->remoteLikeDeliver();
}
@ -75,13 +89,13 @@ class LikePipeline implements ShouldQueue
->whereItemType('App\Status')
->count();
if ($actor->id === $status->profile_id || $exists !== 0) {
if ($actor->id === $status->profile_id || $exists) {
return true;
}
if($status->uri === null && $status->object_url === null && $status->url === null) {
if ($status->uri === null && $status->object_url === null && $status->url === null) {
try {
$notification = new Notification();
$notification = new Notification;
$notification->profile_id = $status->profile_id;
$notification->actor_id = $actor->id;
$notification->action = 'like';
@ -91,6 +105,15 @@ class LikePipeline implements ShouldQueue
} catch (Exception $e) {
}
if (NotificationAppGatewayService::enabled()) {
if (PushNotificationService::check('like', $status->profile_id)) {
$user = User::whereProfileId($status->profile_id)->first();
if ($user && $user->expo_token && $user->notify_enabled) {
LikePushNotifyPipeline::dispatchSync($user->expo_token, $actor->username);
}
}
}
}
}
@ -100,9 +123,9 @@ class LikePipeline implements ShouldQueue
$status = $this->like->status;
$actor = $this->like->actor;
$fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Item($like, new LikeTransformer());
$fractal = new Fractal\Manager;
$fractal->setSerializer(new ArraySerializer);
$resource = new Fractal\Resource\Item($like, new LikeTransformer);
$activity = $fractal->createData($resource)->toArray();
$url = $status->profile->sharedInbox ?? $status->profile->inbox_url;