2018-06-01 03:14:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\StatusPipeline;
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
use App\Hashtag;
|
2024-03-12 08:20:37 +00:00
|
|
|
use App\Jobs\HomeFeedPipeline\FeedInsertPipeline;
|
2018-08-28 03:07:36 +00:00
|
|
|
use App\Jobs\MentionPipeline\MentionPipeline;
|
|
|
|
use App\Mention;
|
|
|
|
use App\Profile;
|
2024-03-12 08:20:37 +00:00
|
|
|
use App\Services\AdminShadowFilterService;
|
|
|
|
use App\Services\PublicTimelineService;
|
|
|
|
use App\Services\StatusService;
|
|
|
|
use App\Services\UserFilterService;
|
2018-08-28 03:07:36 +00:00
|
|
|
use App\Status;
|
|
|
|
use App\StatusHashtag;
|
|
|
|
use App\Util\Lexer\Autolink;
|
|
|
|
use App\Util\Lexer\Extractor;
|
2020-12-11 04:58:56 +00:00
|
|
|
use App\Util\Sentiment\Bouncer;
|
2023-03-19 03:45:35 +00:00
|
|
|
use Cache;
|
2018-08-28 03:07:36 +00:00
|
|
|
use DB;
|
2018-06-01 03:14:46 +00:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2018-08-28 03:07:36 +00:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2018-06-01 03:14:46 +00:00
|
|
|
|
|
|
|
class StatusEntityLexer implements ShouldQueue
|
|
|
|
{
|
2023-11-16 07:47:49 +00:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected $status;
|
2024-03-12 08:20:37 +00:00
|
|
|
|
2023-11-16 07:47:49 +00:00
|
|
|
protected $entities;
|
2024-03-12 08:20:37 +00:00
|
|
|
|
2023-11-16 07:47:49 +00:00
|
|
|
protected $autolink;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete the job if its models no longer exist.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $deleteWhenMissingModels = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(Status $status)
|
|
|
|
{
|
|
|
|
$this->status = $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$profile = $this->status->profile;
|
|
|
|
$status = $this->status;
|
|
|
|
|
2024-03-12 08:20:37 +00:00
|
|
|
if (in_array($status->type, ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])) {
|
2023-11-16 07:47:49 +00:00
|
|
|
$profile->status_count = $profile->status_count + 1;
|
|
|
|
$profile->save();
|
|
|
|
}
|
|
|
|
|
2024-03-12 08:20:37 +00:00
|
|
|
if ($profile->no_autolink == false) {
|
2023-11-16 07:47:49 +00:00
|
|
|
$this->parseEntities();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function parseEntities()
|
|
|
|
{
|
|
|
|
$this->extractEntities();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function extractEntities()
|
|
|
|
{
|
|
|
|
$this->entities = Extractor::create()->extract($this->status->caption);
|
|
|
|
$this->autolinkStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function autolinkStatus()
|
|
|
|
{
|
|
|
|
$this->autolink = Autolink::create()->autolink($this->status->caption);
|
|
|
|
$this->storeEntities();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function storeEntities()
|
|
|
|
{
|
|
|
|
$this->storeHashtags();
|
|
|
|
DB::transaction(function () {
|
|
|
|
$status = $this->status;
|
|
|
|
$status->rendered = nl2br($this->autolink);
|
|
|
|
$status->save();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function storeHashtags()
|
|
|
|
{
|
|
|
|
$tags = array_unique($this->entities['hashtags']);
|
|
|
|
$status = $this->status;
|
|
|
|
|
|
|
|
foreach ($tags as $tag) {
|
2024-03-12 08:20:37 +00:00
|
|
|
if (mb_strlen($tag) > 124) {
|
2023-11-16 07:47:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DB::transaction(function () use ($status, $tag) {
|
|
|
|
$slug = str_slug($tag, '-', false);
|
2023-11-13 03:54:32 +00:00
|
|
|
|
|
|
|
$hashtag = Hashtag::firstOrCreate([
|
2024-03-12 08:20:37 +00:00
|
|
|
'slug' => $slug,
|
2023-11-13 03:54:32 +00:00
|
|
|
], [
|
2024-03-12 08:20:37 +00:00
|
|
|
'name' => $tag,
|
2023-11-13 03:54:32 +00:00
|
|
|
]);
|
2022-01-05 06:41:32 +00:00
|
|
|
|
2023-11-16 07:47:49 +00:00
|
|
|
StatusHashtag::firstOrCreate(
|
|
|
|
[
|
|
|
|
'status_id' => $status->id,
|
|
|
|
'hashtag_id' => $hashtag->id,
|
|
|
|
'profile_id' => $status->profile_id,
|
|
|
|
'status_visibility' => $status->visibility,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$this->storeMentions();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function storeMentions()
|
|
|
|
{
|
|
|
|
$mentions = array_unique($this->entities['mentions']);
|
|
|
|
$status = $this->status;
|
|
|
|
|
|
|
|
foreach ($mentions as $mention) {
|
|
|
|
$mentioned = Profile::whereUsername($mention)->first();
|
|
|
|
|
2024-03-12 08:20:37 +00:00
|
|
|
if (empty($mentioned) || ! isset($mentioned->id)) {
|
2023-11-16 07:47:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-08-08 02:59:36 +00:00
|
|
|
$blocks = UserFilterService::blocks($mentioned->id);
|
2024-03-12 08:20:37 +00:00
|
|
|
if ($blocks && in_array($status->profile_id, $blocks)) {
|
2022-08-08 02:59:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-05-12 00:17:03 +00:00
|
|
|
|
2023-11-16 07:47:49 +00:00
|
|
|
DB::transaction(function () use ($status, $mentioned) {
|
|
|
|
$m = new Mention();
|
|
|
|
$m->status_id = $status->id;
|
|
|
|
$m->profile_id = $mentioned->id;
|
|
|
|
$m->save();
|
|
|
|
|
|
|
|
MentionPipeline::dispatch($status, $m);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$this->fanout();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fanout()
|
|
|
|
{
|
|
|
|
$status = $this->status;
|
|
|
|
StatusService::refresh($status->id);
|
|
|
|
|
2024-03-12 08:20:37 +00:00
|
|
|
if (config('exp.cached_home_timeline')) {
|
|
|
|
if ($status->in_reply_to_id === null &&
|
2023-11-16 07:47:49 +00:00
|
|
|
in_array($status->scope, ['public', 'unlisted', 'private'])
|
|
|
|
) {
|
|
|
|
FeedInsertPipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->deliver();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deliver()
|
|
|
|
{
|
|
|
|
$status = $this->status;
|
|
|
|
$types = [
|
|
|
|
'photo',
|
|
|
|
'photo:album',
|
|
|
|
'video',
|
|
|
|
'video:album',
|
2024-03-12 08:20:37 +00:00
|
|
|
'photo:video:album',
|
2023-11-16 07:47:49 +00:00
|
|
|
];
|
|
|
|
|
2024-03-12 08:20:37 +00:00
|
|
|
if (config_cache('pixelfed.bouncer.enabled')) {
|
2023-11-16 07:47:49 +00:00
|
|
|
Bouncer::get($status);
|
|
|
|
}
|
|
|
|
|
2024-03-12 08:20:37 +00:00
|
|
|
Cache::forget('pf:atom:user-feed:by-id:'.$status->profile_id);
|
2023-11-16 07:47:49 +00:00
|
|
|
$hideNsfw = config('instance.hide_nsfw_on_public_feeds');
|
2024-03-12 08:20:37 +00:00
|
|
|
if ($status->uri == null &&
|
2023-11-16 07:47:49 +00:00
|
|
|
$status->scope == 'public' &&
|
|
|
|
in_array($status->type, $types) &&
|
|
|
|
$status->in_reply_to_id === null &&
|
|
|
|
$status->reblog_of_id === null &&
|
|
|
|
($hideNsfw ? $status->is_nsfw == false : true)
|
|
|
|
) {
|
2024-03-12 08:20:37 +00:00
|
|
|
if (AdminShadowFilterService::canAddToPublicFeedByProfileId($status->profile_id)) {
|
2023-11-16 07:47:49 +00:00
|
|
|
PublicTimelineService::add($status->id);
|
2023-09-15 04:32:37 +00:00
|
|
|
}
|
2023-11-16 07:47:49 +00:00
|
|
|
}
|
2021-05-12 00:17:03 +00:00
|
|
|
|
2024-03-12 08:20:37 +00:00
|
|
|
if ((bool) config_cache('federation.activitypub.enabled') == true && config('app.env') == 'production') {
|
2023-11-16 07:47:49 +00:00
|
|
|
StatusActivityPubDeliver::dispatch($status);
|
|
|
|
}
|
|
|
|
}
|
2018-06-01 03:14:46 +00:00
|
|
|
}
|