@@ -47,6 +47,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
4747 'tweet_id ' ,
4848 'submitted_at ' ,
4949 'approved_at ' ,
50+ 'declined_at ' ,
5051 'shared_at ' ,
5152 'sponsored_at ' ,
5253 ];
@@ -59,6 +60,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
5960 protected $ casts = [
6061 'submitted_at ' => 'datetime ' ,
6162 'approved_at ' => 'datetime ' ,
63+ 'declined_at ' => 'datetime ' ,
6264 'shared_at ' => 'datetime ' ,
6365 'sponsored_at ' => 'datetime ' ,
6466 'show_toc ' => 'boolean ' ,
@@ -169,6 +171,16 @@ public function isNotApproved(): bool
169171 return $ this ->approved_at === null ;
170172 }
171173
174+ public function isDeclined (): bool
175+ {
176+ return ! $ this ->isNotDeclined ();
177+ }
178+
179+ public function isNotDeclined (): bool
180+ {
181+ return $ this ->declined_at === null ;
182+ }
183+
172184 public function isPublished (): bool
173185 {
174186 return ! $ this ->isNotPublished ();
@@ -201,7 +213,7 @@ public function isShared(): bool
201213
202214 public function isAwaitingApproval (): bool
203215 {
204- return $ this ->isSubmitted () && $ this ->isNotApproved ();
216+ return $ this ->isSubmitted () && $ this ->isNotApproved () && $ this -> isNotDeclined () ;
205217 }
206218
207219 public function isNotAwaitingApproval (): bool
@@ -227,7 +239,8 @@ public function scopeNotApproved(Builder $query): Builder
227239 public function scopeAwaitingApproval (Builder $ query ): Builder
228240 {
229241 return $ query ->submitted ()
230- ->notApproved ();
242+ ->notApproved ()
243+ ->notDeclined ();
231244 }
232245
233246 public function scopePublished (Builder $ query ): Builder
@@ -240,7 +253,8 @@ public function scopeNotPublished(Builder $query): Builder
240253 {
241254 return $ query ->where (function ($ query ) {
242255 $ query ->whereNull ('submitted_at ' )
243- ->orWhereNull ('approved_at ' );
256+ ->orWhereNull ('approved_at ' )
257+ ->orWhereNotNull ('declined_at ' );
244258 });
245259 }
246260
@@ -264,6 +278,16 @@ public function scopeNotShared(Builder $query): Builder
264278 return $ query ->whereNull ('shared_at ' );
265279 }
266280
281+ public function scopeDeclined (Builder $ query ): Builder
282+ {
283+ return $ query ->whereNotNull ('declined_at ' );
284+ }
285+
286+ public function scopeNotDeclined (Builder $ query ): Builder
287+ {
288+ return $ query ->whereNull ('declined_at ' );
289+ }
290+
267291 public function scopeForTag (Builder $ query , string $ tag ): Builder
268292 {
269293 return $ query ->whereHas ('tags ' , function ($ query ) use ($ tag ) {
@@ -305,4 +329,18 @@ public static function nextForSharing(): ?self
305329 ->orderBy ('submitted_at ' , 'asc ' )
306330 ->first ();
307331 }
332+
333+ public static function nexForSharingToTelegram (): ?self
334+ {
335+ return self ::shared ()
336+ ->published ()
337+ ->whereNull ('tweet_id ' )
338+ ->orderBy ('submitted_at ' , 'asc ' )
339+ ->first ();
340+ }
341+
342+ public function markAsPublish ()
343+ {
344+ $ this ->update (['tweet_id ' => $ this ->author ->id ]);
345+ }
308346}
0 commit comments