mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-18 19:13:17 +00:00
Update LikePipeline
This commit is contained in:
parent
873031538d
commit
6889fffbfb
1 changed files with 44 additions and 21 deletions
|
@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,34 +60,42 @@ class LikePipeline implements ShouldQueue
|
||||||
$status = $this->like->status;
|
$status = $this->like->status;
|
||||||
$actor = $this->like->actor;
|
$actor = $this->like->actor;
|
||||||
|
|
||||||
if (!$status) {
|
if (! $status) {
|
||||||
// Ignore notifications to deleted statuses
|
// Ignore notifications to deleted statuses
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$status->likes_count = DB::table('likes')->whereStatusId($status->id)->count();
|
Lottery::odds(1, 20)
|
||||||
$status->save();
|
->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);
|
StatusService::refresh($status->id);
|
||||||
|
|
||||||
if($status->url && $actor->domain == null) {
|
if ($status->url && $actor->domain == null) {
|
||||||
return $this->remoteLikeDeliver();
|
return $this->remoteLikeDeliver();
|
||||||
}
|
}
|
||||||
|
|
||||||
$exists = Notification::whereProfileId($status->profile_id)
|
$exists = Notification::whereProfileId($status->profile_id)
|
||||||
->whereActorId($actor->id)
|
->whereActorId($actor->id)
|
||||||
->whereAction('like')
|
->whereAction('like')
|
||||||
->whereItemId($status->id)
|
->whereItemId($status->id)
|
||||||
->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;
|
||||||
|
|
Loading…
Reference in a new issue