2018-11-03 21:45:44 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
2019-01-12 13:14:22 -07:00
|
|
|
use Auth;
|
2021-08-31 00:41:43 -06:00
|
|
|
use Storage;
|
2018-11-03 21:45:44 -06:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-09-01 22:46:57 -06:00
|
|
|
use App\HasSnowflakePrimary;
|
2021-09-01 01:21:47 -06:00
|
|
|
use App\Util\Lexer\Bearcap;
|
2018-11-03 21:45:44 -06:00
|
|
|
|
|
|
|
class Story extends Model
|
|
|
|
{
|
2019-11-10 17:25:28 -07:00
|
|
|
use HasSnowflakePrimary;
|
|
|
|
|
2020-01-28 21:32:32 -07:00
|
|
|
public const MAX_PER_DAY = 20;
|
2020-01-02 21:20:55 -07:00
|
|
|
|
2019-11-10 17:25:28 -07:00
|
|
|
/**
|
|
|
|
* Indicates if the IDs are auto-incrementing.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $incrementing = false;
|
|
|
|
|
2021-08-31 00:41:43 -06:00
|
|
|
protected $casts = [
|
2021-09-03 22:46:06 -06:00
|
|
|
'expires_at' => 'datetime'
|
2021-08-31 00:41:43 -06:00
|
|
|
];
|
2019-11-10 17:25:28 -07:00
|
|
|
|
2021-08-31 00:41:43 -06:00
|
|
|
protected $fillable = ['profile_id', 'view_count'];
|
2019-12-31 02:33:54 -07:00
|
|
|
|
2019-01-12 12:38:09 -07:00
|
|
|
protected $visible = ['id'];
|
2019-01-12 13:14:22 -07:00
|
|
|
|
2020-01-21 15:09:21 -07:00
|
|
|
protected $hidden = ['json'];
|
|
|
|
|
2019-01-12 12:38:09 -07:00
|
|
|
public function profile()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Profile::class);
|
|
|
|
}
|
|
|
|
|
2019-01-12 00:42:26 -07:00
|
|
|
public function views()
|
|
|
|
{
|
|
|
|
return $this->hasMany(StoryView::class);
|
|
|
|
}
|
2019-01-12 13:14:22 -07:00
|
|
|
|
|
|
|
public function seen($pid = false)
|
|
|
|
{
|
2019-12-31 02:33:54 -07:00
|
|
|
return StoryView::whereStoryId($this->id)
|
|
|
|
->whereProfileId(Auth::user()->profile->id)
|
|
|
|
->exists();
|
2019-01-12 13:14:22 -07:00
|
|
|
}
|
2020-01-05 21:53:09 -07:00
|
|
|
|
|
|
|
public function permalink()
|
|
|
|
{
|
2021-08-31 00:41:43 -06:00
|
|
|
$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()
|
|
|
|
{
|
2021-09-01 01:21:47 -06:00
|
|
|
return Bearcap::encode($this->url(), $this->bearcap_token);
|
2021-08-31 00:41:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeToAudience($scope)
|
|
|
|
{
|
|
|
|
$res = [];
|
|
|
|
|
|
|
|
switch ($scope) {
|
|
|
|
case 'to':
|
|
|
|
$res = [
|
|
|
|
$this->profile->permalink('/followers')
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$res = [];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $res;
|
2020-01-05 21:53:09 -07:00
|
|
|
}
|
2018-11-03 21:45:44 -06:00
|
|
|
}
|