mirror of https://github.com/pixelfed/pixelfed
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Util\ActivityPub\Inbox;
|
|
|
|
use App\Jobs\LikePipeline\LikePipeline;
|
|
use App\Models\Like;
|
|
use App\Util\ActivityPub\Helpers;
|
|
|
|
trait HandlesLikes
|
|
{
|
|
public function handleLikeActivity(): void
|
|
{
|
|
$actor = $this->payload['actor'];
|
|
|
|
if (! Helpers::validateUrl($actor)) {
|
|
return;
|
|
}
|
|
|
|
$profile = $this->validateAndFetchActor($actor);
|
|
$obj = $this->payload['object'];
|
|
|
|
if (! Helpers::validateUrl($obj)) {
|
|
return;
|
|
}
|
|
|
|
$status = Helpers::statusFirstOrFetch($obj);
|
|
|
|
if (! $status || ! $profile) {
|
|
return;
|
|
}
|
|
|
|
if ($this->isDomainBlocked($status->profile_id, $profile->domain)) {
|
|
return;
|
|
}
|
|
|
|
if ($this->isUserBlocked($status->profile_id, $profile->id)) {
|
|
return;
|
|
}
|
|
|
|
$like = Like::firstOrCreate([
|
|
'profile_id' => $profile->id,
|
|
'status_id' => $status->id,
|
|
]);
|
|
|
|
if ($like->wasRecentlyCreated == true) {
|
|
$status->likes_count = $status->likes_count + 1;
|
|
$status->save();
|
|
LikePipeline::dispatch($like);
|
|
}
|
|
}
|
|
}
|