|
@@ -2,11 +2,10 @@
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
+use App\Util\Lexer\Bearcap;
|
|
|
use Auth;
|
|
|
-use Storage;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
-use App\HasSnowflakePrimary;
|
|
|
-use App\Util\Lexer\Bearcap;
|
|
|
+use Storage;
|
|
|
|
|
|
class Story extends Model
|
|
|
{
|
|
@@ -22,70 +21,88 @@ class Story extends Model
|
|
|
public $incrementing = false;
|
|
|
|
|
|
protected $casts = [
|
|
|
- 'expires_at' => 'datetime'
|
|
|
+ 'story' => 'array',
|
|
|
+ 'expires_at' => 'datetime',
|
|
|
];
|
|
|
|
|
|
protected $fillable = ['profile_id', 'view_count'];
|
|
|
|
|
|
- protected $visible = ['id'];
|
|
|
-
|
|
|
- protected $hidden = ['json'];
|
|
|
-
|
|
|
- public function profile()
|
|
|
- {
|
|
|
- return $this->belongsTo(Profile::class);
|
|
|
- }
|
|
|
-
|
|
|
- public function views()
|
|
|
- {
|
|
|
- return $this->hasMany(StoryView::class);
|
|
|
- }
|
|
|
-
|
|
|
- public function seen($pid = false)
|
|
|
- {
|
|
|
- return StoryView::whereStoryId($this->id)
|
|
|
- ->whereProfileId(Auth::user()->profile->id)
|
|
|
- ->exists();
|
|
|
- }
|
|
|
-
|
|
|
- public function permalink()
|
|
|
- {
|
|
|
- $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 Bearcap::encode($this->url(), $this->bearcap_token);
|
|
|
- }
|
|
|
-
|
|
|
- public function scopeToAudience($scope)
|
|
|
- {
|
|
|
- $res = [];
|
|
|
-
|
|
|
- switch ($scope) {
|
|
|
- case 'to':
|
|
|
- $res = [
|
|
|
- $this->profile->permalink('/followers')
|
|
|
- ];
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- $res = [];
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- return $res;
|
|
|
- }
|
|
|
+ protected $visible = ['id'];
|
|
|
+
|
|
|
+ protected $hidden = ['json'];
|
|
|
+
|
|
|
+ public function profile()
|
|
|
+ {
|
|
|
+ return $this->belongsTo(Profile::class);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function views()
|
|
|
+ {
|
|
|
+ return $this->hasMany(StoryView::class);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function seen($pid = false)
|
|
|
+ {
|
|
|
+ return StoryView::whereStoryId($this->id)
|
|
|
+ ->whereProfileId(Auth::user()->profile->id)
|
|
|
+ ->exists();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function permalink()
|
|
|
+ {
|
|
|
+ $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 Bearcap::encode($this->url(), $this->bearcap_token);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function scopeToAudience($scope)
|
|
|
+ {
|
|
|
+ $res = [];
|
|
|
+
|
|
|
+ switch ($scope) {
|
|
|
+ case 'to':
|
|
|
+ $res = [
|
|
|
+ $this->profile->permalink('/followers'),
|
|
|
+ ];
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ $res = [];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function toAdminEntity()
|
|
|
+ {
|
|
|
+ return [
|
|
|
+ 'id' => $this->id,
|
|
|
+ 'profile_id' => $this->profile_id,
|
|
|
+ 'media_src' => $this->mediaUrl(),
|
|
|
+ 'url' => $this->url(),
|
|
|
+ 'type' => $this->type,
|
|
|
+ 'duration' => $this->duration,
|
|
|
+ 'mime' => $this->mime,
|
|
|
+ 'size' => $this->size,
|
|
|
+ 'local' => $this->local,
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|