From e1a3e26644cbf5bb13b11316c291bf5a98d64cef Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 31 Aug 2021 00:41:43 -0600 Subject: [PATCH] Update Story model --- app/Story.php | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/app/Story.php b/app/Story.php index 700d1659e..f46f01403 100644 --- a/app/Story.php +++ b/app/Story.php @@ -3,6 +3,7 @@ namespace App; use Auth; +use Storage; use Illuminate\Database\Eloquent\Model; use Pixelfed\Snowflake\HasSnowflakePrimary; @@ -19,14 +20,11 @@ class Story extends Model */ public $incrementing = false; - /** - * The attributes that should be mutated to dates. - * - * @var array - */ - protected $dates = ['published_at', 'expires_at']; + protected $casts = [ + 'expires_at' => 'immutable_datetime' + ]; - protected $fillable = ['profile_id']; + protected $fillable = ['profile_id', 'view_count']; protected $visible = ['id']; @@ -51,6 +49,42 @@ class Story extends Model public function permalink() { - return url("/story/$this->id"); + $username = $this->profile->username; + return url("/stories/{$username}/{$this->id}/activity"); + } + + public function url() + { + $username = $this->profile->username; + return url("/stories/{$username}/{$this->id}"); + } + + public function mediaUrl() + { + return url(Storage::url($this->path)); + } + + public function bearcapUrl() + { + return "bear:?t={$this->bearcap_token}&u={$this->url()}"; + } + + public function scopeToAudience($scope) + { + $res = []; + + switch ($scope) { + case 'to': + $res = [ + $this->profile->permalink('/followers') + ]; + break; + + default: + $res = []; + break; + } + + return $res; } }