diff --git a/app/Console/Commands/SendProfileUpdate.php b/app/Console/Commands/SendProfileUpdate.php index f88485b..e130d0a 100644 --- a/app/Console/Commands/SendProfileUpdate.php +++ b/app/Console/Commands/SendProfileUpdate.php @@ -44,7 +44,7 @@ public function handle() $activity->type = 'Update'; $activity->user_id = $user->id; $activity->setData([ - 'object' => $user->actorURL() + 'object' => $user->toActivityStreamsObject() ]); $activity->save(); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 304a87c..446db79 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -25,46 +25,9 @@ public function get($username, $format=false) { // Switch on Accept header if((!$format && request()->wantsJson()) || $format == 'json') { - $profile = [ - "@context" => [ - "https://www.w3.org/ns/activitystreams", - "https://w3id.org/security/v1", - ], - "id" => $user->actorURL(), - "type" => "Person", - "preferredUsername" => $user->username, - "url" => $user->actorURL(), - "icon" => [ - "type" => "Image", - "mediaType" => "image/jpeg", - "url" => env('APP_URL')."/storage/images/".$user->username.".jpg", - ], - "inbox" => env('APP_URL').$user->inboxPath(), - "outbox" => env('APP_URL').$user->outboxPath(), - "featured" => env('APP_URL').$user->featuredPath(), - "publicKey" => [ - "id" => $user->actorURL(), - "owner" => $user->actorURL(), - "publicKeyPem" => $user->public_key - ] - ]; - - if($user->photo) { - $profile['icon']['url'] = $user->photo; - } - - if($user->banner) { - $profile['image'] = [ - 'type' => 'image', - 'mediaType' => 'image/jpeg', - 'url' => $user->banner, - ]; - } + $profile = $user->toActivityStreamsObject(); if($user->external_domain) { - // Override some of the properties - $profile['url'] = 'https://' . $user->external_domain; - // Add the Webfinger bits to this response $profile['---webfinger---'] = '---webfinger---'; $profile['subject'] = 'acct:' . $user->username . '@' . $user->external_domain; diff --git a/app/User.php b/app/User.php index 0257fe0..81cf726 100644 --- a/app/User.php +++ b/app/User.php @@ -98,4 +98,49 @@ public function outboxPath() { public function featuredPath() { return '/' . $this->username . '/featured'; } + + public function toActivityStreamsObject() { + $profile = [ + "@context" => [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + ], + "id" => $this->actorURL(), + "type" => "Person", + "preferredUsername" => $this->username, + "url" => $this->actorURL(), + "icon" => [ + "type" => "Image", + "mediaType" => "image/jpeg", + "url" => env('APP_URL')."/storage/images/".$this->username.".jpg", + ], + "inbox" => env('APP_URL').$this->inboxPath(), + "outbox" => env('APP_URL').$this->outboxPath(), + "featured" => env('APP_URL').$this->featuredPath(), + "publicKey" => [ + "id" => $this->actorURL(), + "owner" => $this->actorURL(), + "publicKeyPem" => $this->public_key + ] + ]; + + if($this->photo) { + $profile['icon']['url'] = $this->photo; + } + + if($this->banner) { + $profile['image'] = [ + 'type' => 'image', + 'mediaType' => 'image/jpeg', + 'url' => $this->banner, + ]; + } + + if($this->external_domain) { + // Override some of the properties + $profile['url'] = 'https://' . $this->external_domain; + } + + return $profile; + } }