소스 검색

Update NotificationTransformer, handle tagged deletes

Daniel Supernault 4 년 전
부모
커밋
881fa86573
3개의 변경된 파일22개의 추가작업 그리고 2개의 파일을 삭제
  1. 13 0
      app/Jobs/StatusPipeline/StatusDelete.php
  2. 6 0
      app/Notification.php
  3. 3 2
      app/Transformer/Api/NotificationTransformer.php

+ 13 - 0
app/Jobs/StatusPipeline/StatusDelete.php

@@ -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();
         });
 

+ 6 - 0
app/Notification.php

@@ -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');
+    }
+
 }

+ 3 - 2
app/Transformer/Api/NotificationTransformer.php

@@ -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;