From 37e406ae36e4b7f922cb46d7873ec584768a721b Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 22 Feb 2018 08:14:15 +0100 Subject: [PATCH] Get avatar and banner from AP users. --- lib/pleroma/user.ex | 2 +- lib/pleroma/web/activity_pub/activity_pub.ex | 16 ++++++++++++++-- test/web/activity_pub/transmogrifier_test.exs | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index f97dbb387..8c1c524ff 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -105,7 +105,7 @@ defmodule Pleroma.User do def upgrade_changeset(struct, params \\ %{}) do struct - |> cast(params, [:bio, :name, :info, :follower_address]) + |> cast(params, [:bio, :name, :info, :follower_address, :avatar]) |> unique_constraint(:nickname) |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/) |> validate_length(:bio, min: 1, max: 1000) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 0de730410..d59346042 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -264,15 +264,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do with {:ok, %{status_code: 200, body: body}} <- @httpoison.get(ap_id, ["Accept": "application/activity+json"]), {:ok, data} <- Poison.decode(body) do + avatar = %{ + "type" => "Image", + "url" => [%{"href" => data["icon"]["url"]}] + } + + banner = %{ + "type" => "Image", + "url" => [%{"href" => data["image"]["url"]}] + } + user_data = %{ ap_id: data["id"], info: %{ "ap_enabled" => true, - "source_data" => data + "source_data" => data, + "banner" => banner }, + avatar: avatar, nickname: "#{data["preferredUsername"]}@#{URI.parse(ap_id).host}", name: data["name"], - follower_address: data["followers"] + follower_address: data["followers"], } {:ok, user_data} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 185734852..e3a170e4e 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -204,6 +204,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do activity = Repo.get(Activity, activity.id) assert user.follower_address in activity.recipients + assert %{"url" => [%{"href" => "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"}]} = user.avatar + assert %{"url" => [%{"href" => "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"}]} = user.info["banner"] refute "..." in activity.recipients unrelated_activity = Repo.get(Activity, unrelated_activity.id)