|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\HasSnowflakePrimary;
|
|
|
|
|
use App\Util\Lexer\Bearcap;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
fix: add return type declarations to Eloquent relation methods
Larastan 3.x requires explicit return types on relation methods to
verify relation existence when using with(), has(), etc. This adds
the appropriate return type declarations to all relation methods
flagged by the larastan.relationExistence rule.
Models fixed:
- Profile (avatar, statuses)
- User (profile)
- Status (profile, media, hashtags)
- DirectMessage (status, author, recipient)
- Report (reporter, status, reportedUser)
- Like (actor, status)
- Media (status)
- Notification (item)
- HashtagFollow (hashtag)
- OauthClient (user)
- Story (profile)
- StatusHashtag (status, hashtag, profile, media)
- AccountInterstitial (user)
- Hashtag (posts)
- CustomFilter (keywords)
- CustomFilterKeyword (customFilter)
- AdminShadowFilter (profile)
- ImportPost (status)
4 weeks ago
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @property int $id
|
|
|
|
|
* @property int $profile_id
|
|
|
|
|
* @property string|null $path
|
|
|
|
|
* @property string|null $bearcap_token
|
|
|
|
|
* @property array|null $story
|
|
|
|
|
* @property int $view_count
|
|
|
|
|
* @property Carbon|null $expires_at
|
|
|
|
|
* @property Carbon|null $created_at
|
|
|
|
|
* @property Carbon|null $updated_at
|
|
|
|
|
* @property-read Profile $profile
|
|
|
|
|
*/
|
|
|
|
|
class Story extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasSnowflakePrimary;
|
|
|
|
|
|
|
|
|
|
public const MAX_PER_DAY = 20;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indicates if the IDs are auto-incrementing.
|
|
|
|
|
*
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
|
|
|
|
public $incrementing = false;
|
|
|
|
|
|
|
|
|
|
protected $guarded = [];
|
|
|
|
|
|
|
|
|
|
protected $visible = ['id'];
|
|
|
|
|
|
|
|
|
|
protected $hidden = ['json'];
|
|
|
|
|
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'story' => 'json',
|
|
|
|
|
'expires_at' => 'datetime',
|
|
|
|
|
'view_count' => 'integer',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
fix: add return type declarations to Eloquent relation methods
Larastan 3.x requires explicit return types on relation methods to
verify relation existence when using with(), has(), etc. This adds
the appropriate return type declarations to all relation methods
flagged by the larastan.relationExistence rule.
Models fixed:
- Profile (avatar, statuses)
- User (profile)
- Status (profile, media, hashtags)
- DirectMessage (status, author, recipient)
- Report (reporter, status, reportedUser)
- Like (actor, status)
- Media (status)
- Notification (item)
- HashtagFollow (hashtag)
- OauthClient (user)
- Story (profile)
- StatusHashtag (status, hashtag, profile, media)
- AccountInterstitial (user)
- Hashtag (posts)
- CustomFilter (keywords)
- CustomFilterKeyword (customFilter)
- AdminShadowFilter (profile)
- ImportPost (status)
4 weeks ago
|
|
|
public function profile(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return list
|
|
|
|
|
*/
|
|
|
|
|
public function scopeToAudience($scope): array
|
|
|
|
|
{
|
|
|
|
|
$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,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|