mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-23 00:05:29 +00:00
Update Status model
This commit is contained in:
parent
55aeab2733
commit
1812fa8851
1 changed files with 44 additions and 3 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use Storage;
|
use Auth, Storage;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
@ -71,15 +71,39 @@ class Status extends Model
|
||||||
return $this->hasMany(Like::class);
|
return $this->hasMany(Like::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function liked() : bool
|
||||||
|
{
|
||||||
|
$profile = Auth::user()->profile;
|
||||||
|
return Like::whereProfileId($profile->id)->whereStatusId($this->id)->count();
|
||||||
|
}
|
||||||
|
|
||||||
public function comments()
|
public function comments()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Status::class, 'in_reply_to_id');
|
return $this->hasMany(Status::class, 'in_reply_to_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function bookmarked()
|
||||||
|
{
|
||||||
|
$profile = Auth::user()->profile;
|
||||||
|
return Bookmark::whereProfileId($profile->id)->whereStatusId($this->id)->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shares()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Status::class, 'reblog_of_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shared() : bool
|
||||||
|
{
|
||||||
|
$profile = Auth::user()->profile;
|
||||||
|
return Status::whereProfileId($profile->id)->whereReblogOfId($this->id)->count();
|
||||||
|
}
|
||||||
|
|
||||||
public function parent()
|
public function parent()
|
||||||
{
|
{
|
||||||
if(!empty($this->in_reply_to_id)) {
|
$parent = $this->in_reply_to_id ?? $this->reblog_of_id;
|
||||||
return Status::findOrFail($this->in_reply_to_id);
|
if(!empty($parent)) {
|
||||||
|
return Status::findOrFail($parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +124,23 @@ class Status extends Model
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function mentions()
|
||||||
|
{
|
||||||
|
return $this->hasManyThrough(
|
||||||
|
Profile::class,
|
||||||
|
Mention::class,
|
||||||
|
'status_id',
|
||||||
|
'id',
|
||||||
|
'id',
|
||||||
|
'profile_id'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reportUrl()
|
||||||
|
{
|
||||||
|
return route('report.form') . "?type=post&id={$this->id}";
|
||||||
|
}
|
||||||
|
|
||||||
public function toActivityStream()
|
public function toActivityStream()
|
||||||
{
|
{
|
||||||
$media = $this->media;
|
$media = $this->media;
|
||||||
|
|
Loading…
Reference in a new issue