Skip to content

Commit

Permalink
feat: 讓管理員審核文章時,文章不會發表得那麼頻繁
Browse files Browse the repository at this point in the history
  • Loading branch information
Kantai235 authored Apr 27, 2024
1 parent 969ebd5 commit bae944b
Showing 1 changed file with 77 additions and 66 deletions.
143 changes: 77 additions & 66 deletions app/Domains/Social/Http/Controllers/Api/Cards/ReviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Domains\Social\Services\CardsService;
use App\Domains\Social\Services\ReviewService;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use Illuminate\Http\Request;

/**
Expand Down Expand Up @@ -98,77 +99,87 @@ public function voting(Request $request, Cards $card, $status)
$model->sendPublishNotification();

/**
* 先把需要發表的社群平台抓出來
* 如果上一篇通過審核的文章距今已超過 60 分鐘,那就順便發表到社群平台上。
*/
$platforms = Platform::where('action', Platform::ACTION_PUBLISH)
->active()
->get();

/**
* 根據社群平台逐一發佈
*/
foreach ($platforms as $platform) {
switch ($platform->type) {
/**
* 丟給負責發表文章到 Facebook 的 Job
*/
case Platform::TYPE_FACEBOOK:
dispatch(new FacebookPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Twitter 的 Job
*/
case Platform::TYPE_TWITTER:
dispatch(new TwitterPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Plurk 的 Job
*/
case Platform::TYPE_PLURK:
dispatch(new PlurkPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Discord 的 Job
*/
case Platform::TYPE_DISCORD:
dispatch(new DiscordPublishJob($model, $platform))->onQueue('highest');
break;

if ($this->delayMode) {
$card = Cards::where('active', 1)->orderBy('updated_at', 'DESC')->first();
$now = Carbon::now()->subMinutes(60);

if (isset($card) && $now->timestamp > $card->updated_at->timestamp) {
/**
* 丟給負責發表文章到 Tumblr 的 Job
* 先把需要發表的社群平台抓出來
*/
case Platform::TYPE_TUMBLR:
dispatch(new TumblrPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Telegram 的 Job
*/
case Platform::TYPE_TELEGRAM:
dispatch(new TelegramPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Bsky 的 Job
*/
case Platform::TYPE_BSKY:
dispatch(new BskyPublishJob($card, $platform))->onQueue('highest');
break;

$platforms = Platform::where('action', Platform::ACTION_PUBLISH)
->active()
->get();

/**
* 其它並不在支援名單當中的社群
* 根據社群平台逐一發佈
*/
default:
/**
* 直接把資料寫入 Activity log 以便日後查核
*/
activity('social cards - undefined publish')
->performedOn($card)
->log(json_encode($model));
break;
foreach ($platforms as $platform) {
switch ($platform->type) {
/**
* 丟給負責發表文章到 Facebook 的 Job
*/
case Platform::TYPE_FACEBOOK:
dispatch(new FacebookPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Twitter 的 Job
*/
case Platform::TYPE_TWITTER:
dispatch(new TwitterPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Plurk 的 Job
*/
case Platform::TYPE_PLURK:
dispatch(new PlurkPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Discord 的 Job
*/
case Platform::TYPE_DISCORD:
dispatch(new DiscordPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Tumblr 的 Job
*/
case Platform::TYPE_TUMBLR:
dispatch(new TumblrPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Telegram 的 Job
*/
case Platform::TYPE_TELEGRAM:
dispatch(new TelegramPublishJob($model, $platform))->onQueue('highest');
break;

/**
* 丟給負責發表文章到 Bsky 的 Job
*/
case Platform::TYPE_BSKY:
dispatch(new BskyPublishJob($card, $platform))->onQueue('highest');
break;

/**
* 其它並不在支援名單當中的社群
*/
default:
/**
* 直接把資料寫入 Activity log 以便日後查核
*/
activity('social cards - undefined publish')
->performedOn($card)
->log(json_encode($model));
break;
}
}
}
}
}
Expand Down

0 comments on commit bae944b

Please sign in to comment.