From ec2bff95b6e5b93b1ca581566dbb6152306364e2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 31 May 2018 21:14:46 -0600 Subject: [PATCH] Add StatusPipeline --- app/Jobs/StatusPipeline/NewStatusPipeline.php | 52 +++++++++++++ .../StatusActivityPubDeliver.php | 38 ++++++++++ app/Jobs/StatusPipeline/StatusEntityLexer.php | 74 +++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 app/Jobs/StatusPipeline/NewStatusPipeline.php create mode 100644 app/Jobs/StatusPipeline/StatusActivityPubDeliver.php create mode 100644 app/Jobs/StatusPipeline/StatusEntityLexer.php diff --git a/app/Jobs/StatusPipeline/NewStatusPipeline.php b/app/Jobs/StatusPipeline/NewStatusPipeline.php new file mode 100644 index 00000000..01392aa4 --- /dev/null +++ b/app/Jobs/StatusPipeline/NewStatusPipeline.php @@ -0,0 +1,52 @@ +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); + } +} diff --git a/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php b/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php new file mode 100644 index 00000000..acf660ca --- /dev/null +++ b/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php @@ -0,0 +1,38 @@ +status = $status; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $status = $this->status; + + // todo: fanout on write + } +} diff --git a/app/Jobs/StatusPipeline/StatusEntityLexer.php b/app/Jobs/StatusPipeline/StatusEntityLexer.php new file mode 100644 index 00000000..ebbf4ad4 --- /dev/null +++ b/app/Jobs/StatusPipeline/StatusEntityLexer.php @@ -0,0 +1,74 @@ +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(); + } + + } +}