Merge pull request #629 from pixelfed/frontend-ui-refactor

Update Status, generate missing status types
This commit is contained in:
daniel 2018-12-10 21:16:07 -07:00 committed by GitHub
commit 9a015190ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 14 deletions

View file

@ -53,30 +53,24 @@ class Status extends Model
// todo: deprecate after 0.6.0 // todo: deprecate after 0.6.0
public function viewType() public function viewType()
{ {
return Cache::remember('status:view-type:'.$this->id, 10080, function() { if($this->type) {
$this->setType(); return $this->type;
$media = $this->firstMedia();
$mime = explode('/', $media->mime)[0];
$count = $this->media()->count();
$type = ($mime == 'image') ? 'image' : 'video';
if($count > 1) {
$type = ($type == 'image') ? 'album' : 'video-album';
} }
return $type; return $this->setType();
});
} }
// todo: deprecate after 0.6.0 // todo: deprecate after 0.6.0
public function setType() public function setType()
{ {
if(in_array($this->type, self::STATUS_TYPES)) { if(in_array($this->type, self::STATUS_TYPES)) {
return; return $this->type;
} }
$mimes = $this->media->pluck('mime')->toArray(); $mimes = $this->media->pluck('mime')->toArray();
$type = StatusController::mimeTypeCheck($mimes); $type = StatusController::mimeTypeCheck($mimes);
if($type) { if($type) {
$this->type = $type; $this->type = $type;
$this->save(); $this->save();
return $type;
} }
} }

View file

@ -41,7 +41,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
'language' => null, 'language' => null,
'pinned' => null, 'pinned' => null,
'pf_type' => $status->type, 'pf_type' => $status->type ?? $status->setType(),
]; ];
} }

View file

@ -23,7 +23,7 @@ return [
| This value is the version of your PixelFed instance. | This value is the version of your PixelFed instance.
| |
*/ */
'version' => '0.5.0', 'version' => '0.5.1',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------