mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-23 00:05:29 +00:00
Add StatusPipeline
This commit is contained in:
parent
e2afe175f4
commit
ec2bff95b6
3 changed files with 164 additions and 0 deletions
52
app/Jobs/StatusPipeline/NewStatusPipeline.php
Normal file
52
app/Jobs/StatusPipeline/NewStatusPipeline.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\StatusPipeline;
|
||||||
|
|
||||||
|
use Cache, Redis;
|
||||||
|
use App\{Media, Status};
|
||||||
|
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
|
||||||
|
class NewStatusPipeline implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
protected $status;
|
||||||
|
protected $media;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Status $status, $media = false)
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
$this->media = $media;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$status = $this->status;
|
||||||
|
$media = $this->media;
|
||||||
|
|
||||||
|
StatusEntityLexer::dispatch($status);
|
||||||
|
StatusActivityPubDeliver::dispatch($status);
|
||||||
|
if($media) {
|
||||||
|
ImageOptimize::dispatch($media);
|
||||||
|
}
|
||||||
|
Cache::forever('post.' . $status->id, $status);
|
||||||
|
|
||||||
|
$redis = Redis::connection();
|
||||||
|
$redis->lpush(config('cache.prefix').':user.' . $status->profile_id . '.posts', $status->id);
|
||||||
|
}
|
||||||
|
}
|
38
app/Jobs/StatusPipeline/StatusActivityPubDeliver.php
Normal file
38
app/Jobs/StatusPipeline/StatusActivityPubDeliver.php
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\StatusPipeline;
|
||||||
|
|
||||||
|
use App\{Media, Status};
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
|
||||||
|
class StatusActivityPubDeliver implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
protected $status;
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Status $status)
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$status = $this->status;
|
||||||
|
|
||||||
|
// todo: fanout on write
|
||||||
|
}
|
||||||
|
}
|
74
app/Jobs/StatusPipeline/StatusEntityLexer.php
Normal file
74
app/Jobs/StatusPipeline/StatusEntityLexer.php
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\StatusPipeline;
|
||||||
|
|
||||||
|
use Cache;
|
||||||
|
use App\{
|
||||||
|
Hashtag,
|
||||||
|
Media,
|
||||||
|
Status,
|
||||||
|
StatusHashtag
|
||||||
|
};
|
||||||
|
use App\Util\Lexer\Hashtag as HashtagLexer;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
|
||||||
|
class StatusEntityLexer implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
protected $status;
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Status $status)
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$status = $this->status;
|
||||||
|
$this->parseHashtags();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parseHashtags()
|
||||||
|
{
|
||||||
|
$status = $this->status;
|
||||||
|
$text = $status->caption;
|
||||||
|
$tags = HashtagLexer::getHashtags($text);
|
||||||
|
$rendered = $text;
|
||||||
|
if(count($tags) > 0) {
|
||||||
|
$rendered = HashtagLexer::replaceHashtagsWithLinks($text);
|
||||||
|
}
|
||||||
|
$status->rendered = $rendered;
|
||||||
|
$status->save();
|
||||||
|
|
||||||
|
Cache::forever('post.' . $status->id, $status);
|
||||||
|
|
||||||
|
foreach($tags as $tag) {
|
||||||
|
$slug = str_slug($tag);
|
||||||
|
|
||||||
|
$htag = Hashtag::firstOrCreate(
|
||||||
|
['name' => $tag],
|
||||||
|
['slug' => $slug]
|
||||||
|
);
|
||||||
|
|
||||||
|
$stag = new StatusHashtag;
|
||||||
|
$stag->status_id = $status->id;
|
||||||
|
$stag->hashtag_id = $htag->id;
|
||||||
|
$stag->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue