From 4f254ed9cf2bcd97410632fefc804a015af839b9 Mon Sep 17 00:00:00 2001 From: Ghostie Date: Thu, 26 Dec 2024 22:41:53 -0500 Subject: [PATCH] now profile pictures are federalized as well --- app/Http/Controllers/ProfileController.php | 5 +++++ app/Models/Actor.php | 21 ++++++++++++++++++- .../2024_12_27_002726_create_actors_table.php | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index dc57a37..02450c7 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -57,7 +57,9 @@ class ProfileController extends Controller Storage::disk ("public")->put ("avatars/" . $fname, $image_data); $old_avatar = $user->avatar; + $user->avatar = $fname; + $user->actor->icon = env ("APP_URL") . $user->avatar; $changing_avatar = true; } @@ -71,6 +73,9 @@ class ProfileController extends Controller $user->interests_heroes = $incoming_fields["heroes"]; $user->save (); + $user->actor->summary = $user->bio; + $user->actor->save (); + if ($changing_avatar) { Storage::disk ("public")->delete (str_replace ("/storage/", "", $old_avatar)); diff --git a/app/Models/Actor.php b/app/Models/Actor.php index c57dcee..85775ec 100644 --- a/app/Models/Actor.php +++ b/app/Models/Actor.php @@ -33,6 +33,11 @@ class Actor extends Model "private_key" ]; + public function user () + { + return $this->belongsTo (User::class); + } + public function create_from_user (User $user) { $app_url = Config::get ("app.url"); @@ -74,7 +79,7 @@ class Actor extends Model public static function build_response (Actor $actor) { - return [ + $response = [ "@context" => [ "https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1" @@ -96,11 +101,25 @@ class Actor extends Model "name" => $actor->name, "summary" => $actor->summary, + "icon" => [ + "type" => "Image", + "mediaType" => "image/jpeg", + "url" => $actor->icon + ], + + "image" => [ + "type" => "Image", + "mediaType" => "image/jpeg", + "url" => $actor->icon + ], + "publicKey" => [ "id" => $actor->actor_id . "#main-key", "owner" => $actor->actor_id, "publicKeyPem" => $actor->public_key ] ]; + + return $response; } } diff --git a/database/migrations/2024_12_27_002726_create_actors_table.php b/database/migrations/2024_12_27_002726_create_actors_table.php index 425ec43..94ffdab 100644 --- a/database/migrations/2024_12_27_002726_create_actors_table.php +++ b/database/migrations/2024_12_27_002726_create_actors_table.php @@ -36,6 +36,8 @@ return new class extends Migration $table->string ("public_key")->nullable (); $table->string ("private_key")->nullable (); + $table->string ("icon")->nullable (); + $table->timestamps(); }); }