Browse Source

Update Status model

Daniel Supernault 6 years ago
parent
commit
072a5749af
1 changed files with 18 additions and 1 deletions
  1. 18 1
      app/Status.php

+ 18 - 1
app/Status.php

@@ -3,6 +3,7 @@
 namespace App;
 namespace App;
 
 
 use Auth, Cache;
 use Auth, Cache;
+use App\Http\Controllers\StatusController;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use Storage;
 use Storage;
@@ -49,9 +50,11 @@ class Status extends Model
         return $this->hasMany(Media::class)->orderBy('order', 'asc')->first();
         return $this->hasMany(Media::class)->orderBy('order', 'asc')->first();
     }
     }
 
 
+    // todo: deprecate after 0.6.0
     public function viewType()
     public function viewType()
     {
     {
-        return Cache::remember('status:view-type:'.$this->id, 40320, function() {
+        return Cache::remember('status:view-type:'.$this->id, 10080, function() {
+            $this->setType();
             $media = $this->firstMedia();
             $media = $this->firstMedia();
             $mime = explode('/', $media->mime)[0];
             $mime = explode('/', $media->mime)[0];
             $count = $this->media()->count();
             $count = $this->media()->count();
@@ -63,6 +66,20 @@ class Status extends Model
         });
         });
     }
     }
 
 
+    // todo: deprecate after 0.6.0
+    public function setType()
+    {
+        if(in_array($this->type, self::STATUS_TYPES)) {
+            return;
+        }
+        $mimes = $this->media->pluck('mime')->toArray();
+        $type = StatusController::mimeTypeCheck($mimes);
+        if($type) {
+            $this->type = $type;
+            $this->save();
+        }
+    }
+
     public function thumb($showNsfw = false)
     public function thumb($showNsfw = false)
     {
     {
         return Cache::remember('status:thumb:'.$this->id, 40320, function() use ($showNsfw) {
         return Cache::remember('status:thumb:'.$this->id, 40320, function() use ($showNsfw) {