2018-04-16 01:18:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2018-04-17 01:24:18 +00:00
|
|
|
use Storage;
|
|
|
|
use Vinkla\Hashids\Facades\Hashids;
|
2018-04-16 01:18:59 +00:00
|
|
|
|
|
|
|
class Status extends Model
|
|
|
|
{
|
2018-04-17 01:24:18 +00:00
|
|
|
public function profile()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Profile::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function media()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Media::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function firstMedia()
|
|
|
|
{
|
2018-06-01 20:21:24 +00:00
|
|
|
return $this->hasOne(Media::class)->orderBy('order', 'asc');
|
2018-04-17 01:24:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-20 03:01:25 +00:00
|
|
|
public function thumb()
|
|
|
|
{
|
|
|
|
return url(Storage::url($this->firstMedia()->thumbnail_path));
|
|
|
|
}
|
|
|
|
|
2018-04-17 01:24:18 +00:00
|
|
|
public function url()
|
|
|
|
{
|
2018-05-20 03:01:25 +00:00
|
|
|
$id = $this->id;
|
2018-04-17 01:24:18 +00:00
|
|
|
$username = $this->profile->username;
|
2018-05-31 22:03:43 +00:00
|
|
|
return url(config('app.url') . "/p/{$username}/{$id}");
|
2018-04-17 01:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function mediaUrl()
|
|
|
|
{
|
2018-06-01 20:21:24 +00:00
|
|
|
$path = $this->firstMedia->media_path;
|
2018-04-17 01:24:18 +00:00
|
|
|
$url = Storage::url($path);
|
|
|
|
return url($url);
|
|
|
|
}
|
|
|
|
|
2018-04-17 01:35:18 +00:00
|
|
|
public function likes()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Like::class);
|
|
|
|
}
|
|
|
|
|
2018-06-01 20:21:24 +00:00
|
|
|
public function getLikesCountAttribute()
|
|
|
|
{
|
|
|
|
if(isset($this->likesCountNumber)) {
|
|
|
|
return $this->likesCountNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->likesCountNumber = $this->likes()->count();
|
|
|
|
}
|
|
|
|
|
2018-04-19 05:57:24 +00:00
|
|
|
public function comments()
|
|
|
|
{
|
2018-05-20 03:01:25 +00:00
|
|
|
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;
|
2018-04-19 05:57:24 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 01:18:59 +00:00
|
|
|
}
|