mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +00:00
Remove hashids from Status model, add new methods
This commit is contained in:
parent
cb0780898e
commit
7c1b70060c
1 changed files with 52 additions and 3 deletions
|
@ -23,11 +23,16 @@ class Status extends Model
|
|||
return $this->hasMany(Media::class)->orderBy('order', 'asc')->first();
|
||||
}
|
||||
|
||||
public function thumb()
|
||||
{
|
||||
return url(Storage::url($this->firstMedia()->thumbnail_path));
|
||||
}
|
||||
|
||||
public function url()
|
||||
{
|
||||
$hid = Hashids::encode($this->id);
|
||||
$id = $this->id;
|
||||
$username = $this->profile->username;
|
||||
return url("/p/@{$username}/{$hid}");
|
||||
return url(config('app.url') . "/p/@{$username}/{$id}");
|
||||
}
|
||||
|
||||
public function mediaUrl()
|
||||
|
@ -44,7 +49,51 @@ class Status extends Model
|
|||
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(Comment::class);
|
||||
return $this->hasMany(Status::class, 'in_reply_to_id');
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
if(!empty($this->in_reply_to_id)) {
|
||||
return Status::findOrFail($this->in_reply_to_id);
|
||||
}
|
||||
}
|
||||
|
||||
public function conversation()
|
||||
{
|
||||
return $this->hasOne(Conversation::class);
|
||||
}
|
||||
|
||||
public function hashtags()
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
Hashtag::class,
|
||||
StatusHashtag::class,
|
||||
'status_id',
|
||||
'id',
|
||||
'id',
|
||||
'hashtag_id'
|
||||
);
|
||||
}
|
||||
|
||||
public function toActivityStream()
|
||||
{
|
||||
$media = $this->media;
|
||||
$mediaCollection = [];
|
||||
foreach($media as $image) {
|
||||
$mediaCollection[] = [
|
||||
"type" => "Link",
|
||||
"href" => $image->url(),
|
||||
"mediaType" => $image->mime
|
||||
];
|
||||
}
|
||||
$obj = [
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"type" => "Image",
|
||||
"name" => null,
|
||||
"url" => $mediaCollection
|
||||
];
|
||||
return $obj;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue