Update NotificationTransformer, handle tagged deletes

This commit is contained in:
Daniel Supernault 2020-12-13 17:28:33 -07:00
parent 28f6fc5936
commit 881fa86573
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 22 additions and 2 deletions

View file

@ -4,6 +4,7 @@ namespace App\Jobs\StatusPipeline;
use DB; use DB;
use App\{ use App\{
MediaTag,
Notification, Notification,
Report, Report,
Status, Status,
@ -104,6 +105,18 @@ class StatusDelete implements ShouldQueue
Report::whereObjectType('App\Status') Report::whereObjectType('App\Status')
->whereObjectId($status->id) ->whereObjectId($status->id)
->delete(); ->delete();
MediaTag::where('status_id', $status->id)
->cursor()
->each(function($tag) {
Notification::where('item_type', 'App\MediaTag')
->where('item_id', $tag->id)
->forceDelete();
$tag->delete();
});
MediaTag::whereStatusId($status->id)
->get();
$status->forceDelete(); $status->forceDelete();
}); });

View file

@ -37,4 +37,10 @@ class Notification extends Model
{ {
return $this->belongsTo(Status::class, 'item_id', 'id'); return $this->belongsTo(Status::class, 'item_id', 'id');
} }
public function tag()
{
return $this->hasOne(MediaTag::class, 'item_id', 'id');
}
} }

View file

@ -6,6 +6,7 @@ use App\{
Notification, Notification,
Status Status
}; };
use App\Services\HashidService;
use League\Fractal; use League\Fractal;
class NotificationTransformer extends Fractal\TransformerAbstract class NotificationTransformer extends Fractal\TransformerAbstract
@ -97,8 +98,8 @@ class NotificationTransformer extends Fractal\TransformerAbstract
$ml = $n->item; $ml = $n->item;
$res = $this->item($ml, function($ml) { $res = $this->item($ml, function($ml) {
return [ return [
'username' => $ml->status->profile->username, 'username' => $ml->tagged_username,
'post_url' => $ml->status->url() 'post_url' => '/p/'.HashidService::encode($ml->status_id)
]; ];
}); });
return $res; return $res;