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 App\{
MediaTag,
Notification,
Report,
Status,
@ -104,6 +105,18 @@ class StatusDelete implements ShouldQueue
Report::whereObjectType('App\Status')
->whereObjectId($status->id)
->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();
});

View File

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