1
0
Fork 0
forked from mirror/pixelfed

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; namespace App\Jobs\LikePipeline;
use Cache, DB, Log; use App\Jobs\PushNotificationPipeline\LikePushNotifyPipeline;
use Illuminate\Support\Facades\Redis; use App\Like;
use App\{Like, Notification}; 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\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\Util\ActivityPub\Helpers; use Illuminate\Support\Lottery;
use League\Fractal; use League\Fractal;
use League\Fractal\Serializer\ArraySerializer; use League\Fractal\Serializer\ArraySerializer;
use App\Transformer\ActivityPub\Verb\Like as LikeTransformer;
use App\Services\StatusService;
class LikePipeline implements ShouldQueue class LikePipeline implements ShouldQueue
{ {
@ -30,6 +35,7 @@ class LikePipeline implements ShouldQueue
public $deleteWhenMissingModels = true; public $deleteWhenMissingModels = true;
public $timeout = 5; public $timeout = 5;
public $tries = 1; public $tries = 1;
/** /**
@ -59,8 +65,16 @@ class LikePipeline implements ShouldQueue
return; return;
} }
Lottery::odds(1, 20)
->winner(function () use ($status) {
$status->likes_count = DB::table('likes')->whereStatusId($status->id)->count(); $status->likes_count = DB::table('likes')->whereStatusId($status->id)->count();
$status->save(); $status->save();
})
->loser(function () use ($status) {
$status->likes_count = $status->likes_count + 1;
$status->save();
})
->choose();
StatusService::refresh($status->id); StatusService::refresh($status->id);
@ -75,13 +89,13 @@ class LikePipeline implements ShouldQueue
->whereItemType('App\Status') ->whereItemType('App\Status')
->count(); ->count();
if ($actor->id === $status->profile_id || $exists !== 0) { if ($actor->id === $status->profile_id || $exists) {
return true; 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 { try {
$notification = new Notification(); $notification = new Notification;
$notification->profile_id = $status->profile_id; $notification->profile_id = $status->profile_id;
$notification->actor_id = $actor->id; $notification->actor_id = $actor->id;
$notification->action = 'like'; $notification->action = 'like';
@ -91,6 +105,15 @@ class LikePipeline implements ShouldQueue
} catch (Exception $e) { } 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; $status = $this->like->status;
$actor = $this->like->actor; $actor = $this->like->actor;
$fractal = new Fractal\Manager(); $fractal = new Fractal\Manager;
$fractal->setSerializer(new ArraySerializer()); $fractal->setSerializer(new ArraySerializer);
$resource = new Fractal\Resource\Item($like, new LikeTransformer()); $resource = new Fractal\Resource\Item($like, new LikeTransformer);
$activity = $fractal->createData($resource)->toArray(); $activity = $fractal->createData($resource)->toArray();
$url = $status->profile->sharedInbox ?? $status->profile->inbox_url; $url = $status->profile->sharedInbox ?? $status->profile->inbox_url;