Skip to content

Commit bae944b

Browse files
authored
feat: 讓管理員審核文章時,文章不會發表得那麼頻繁
1 parent 969ebd5 commit bae944b

File tree

1 file changed

+77
-66
lines changed

1 file changed

+77
-66
lines changed

app/Domains/Social/Http/Controllers/Api/Cards/ReviewController.php

Lines changed: 77 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Domains\Social\Services\CardsService;
1515
use App\Domains\Social\Services\ReviewService;
1616
use App\Http\Controllers\Controller;
17+
use Carbon\Carbon;
1718
use Illuminate\Http\Request;
1819

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

100101
/**
101-
* 先把需要發表的社群平台抓出來
102+
* 如果上一篇通過審核的文章距今已超過 60 分鐘,那就順便發表到社群平台上。
102103
*/
103-
$platforms = Platform::where('action', Platform::ACTION_PUBLISH)
104-
->active()
105-
->get();
106-
107-
/**
108-
* 根據社群平台逐一發佈
109-
*/
110-
foreach ($platforms as $platform) {
111-
switch ($platform->type) {
112-
/**
113-
* 丟給負責發表文章到 Facebook 的 Job
114-
*/
115-
case Platform::TYPE_FACEBOOK:
116-
dispatch(new FacebookPublishJob($model, $platform))->onQueue('highest');
117-
break;
118-
119-
/**
120-
* 丟給負責發表文章到 Twitter 的 Job
121-
*/
122-
case Platform::TYPE_TWITTER:
123-
dispatch(new TwitterPublishJob($model, $platform))->onQueue('highest');
124-
break;
125-
126-
/**
127-
* 丟給負責發表文章到 Plurk 的 Job
128-
*/
129-
case Platform::TYPE_PLURK:
130-
dispatch(new PlurkPublishJob($model, $platform))->onQueue('highest');
131-
break;
132-
133-
/**
134-
* 丟給負責發表文章到 Discord 的 Job
135-
*/
136-
case Platform::TYPE_DISCORD:
137-
dispatch(new DiscordPublishJob($model, $platform))->onQueue('highest');
138-
break;
139-
104+
if ($this->delayMode) {
105+
$card = Cards::where('active', 1)->orderBy('updated_at', 'DESC')->first();
106+
$now = Carbon::now()->subMinutes(60);
107+
108+
if (isset($card) && $now->timestamp > $card->updated_at->timestamp) {
140109
/**
141-
* 丟給負責發表文章到 Tumblr 的 Job
110+
* 先把需要發表的社群平台抓出來
142111
*/
143-
case Platform::TYPE_TUMBLR:
144-
dispatch(new TumblrPublishJob($model, $platform))->onQueue('highest');
145-
break;
146-
147-
/**
148-
* 丟給負責發表文章到 Telegram 的 Job
149-
*/
150-
case Platform::TYPE_TELEGRAM:
151-
dispatch(new TelegramPublishJob($model, $platform))->onQueue('highest');
152-
break;
153-
154-
/**
155-
* 丟給負責發表文章到 Bsky 的 Job
156-
*/
157-
case Platform::TYPE_BSKY:
158-
dispatch(new BskyPublishJob($card, $platform))->onQueue('highest');
159-
break;
160-
112+
$platforms = Platform::where('action', Platform::ACTION_PUBLISH)
113+
->active()
114+
->get();
115+
161116
/**
162-
* 其它並不在支援名單當中的社群
117+
* 根據社群平台逐一發佈
163118
*/
164-
default:
165-
/**
166-
* 直接把資料寫入 Activity log 以便日後查核
167-
*/
168-
activity('social cards - undefined publish')
169-
->performedOn($card)
170-
->log(json_encode($model));
171-
break;
119+
foreach ($platforms as $platform) {
120+
switch ($platform->type) {
121+
/**
122+
* 丟給負責發表文章到 Facebook 的 Job
123+
*/
124+
case Platform::TYPE_FACEBOOK:
125+
dispatch(new FacebookPublishJob($model, $platform))->onQueue('highest');
126+
break;
127+
128+
/**
129+
* 丟給負責發表文章到 Twitter 的 Job
130+
*/
131+
case Platform::TYPE_TWITTER:
132+
dispatch(new TwitterPublishJob($model, $platform))->onQueue('highest');
133+
break;
134+
135+
/**
136+
* 丟給負責發表文章到 Plurk 的 Job
137+
*/
138+
case Platform::TYPE_PLURK:
139+
dispatch(new PlurkPublishJob($model, $platform))->onQueue('highest');
140+
break;
141+
142+
/**
143+
* 丟給負責發表文章到 Discord 的 Job
144+
*/
145+
case Platform::TYPE_DISCORD:
146+
dispatch(new DiscordPublishJob($model, $platform))->onQueue('highest');
147+
break;
148+
149+
/**
150+
* 丟給負責發表文章到 Tumblr 的 Job
151+
*/
152+
case Platform::TYPE_TUMBLR:
153+
dispatch(new TumblrPublishJob($model, $platform))->onQueue('highest');
154+
break;
155+
156+
/**
157+
* 丟給負責發表文章到 Telegram 的 Job
158+
*/
159+
case Platform::TYPE_TELEGRAM:
160+
dispatch(new TelegramPublishJob($model, $platform))->onQueue('highest');
161+
break;
162+
163+
/**
164+
* 丟給負責發表文章到 Bsky 的 Job
165+
*/
166+
case Platform::TYPE_BSKY:
167+
dispatch(new BskyPublishJob($card, $platform))->onQueue('highest');
168+
break;
169+
170+
/**
171+
* 其它並不在支援名單當中的社群
172+
*/
173+
default:
174+
/**
175+
* 直接把資料寫入 Activity log 以便日後查核
176+
*/
177+
activity('social cards - undefined publish')
178+
->performedOn($card)
179+
->log(json_encode($model));
180+
break;
181+
}
182+
}
172183
}
173184
}
174185
}

0 commit comments

Comments
 (0)