From 7c1b70060cf2b8a1c5ee0d0dae7f1cf3c361a204 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 19 May 2018 21:01:25 -0600 Subject: [PATCH] Remove hashids from Status model, add new methods --- app/Status.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/app/Status.php b/app/Status.php index c62437bdb..2c3f9760b 100644 --- a/app/Status.php +++ b/app/Status.php @@ -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; } }