diff options
author | lain <lain@soykaf.club> | 2018-02-22 08:14:15 +0100 |
---|---|---|
committer | lain <lain@soykaf.club> | 2018-02-22 08:14:15 +0100 |
commit | 37e406ae36e4b7f922cb46d7873ec584768a721b (patch) | |
tree | 5318792bbe14c90235e609e0549ca565eb3fcfd6 /lib | |
parent | 1555b7fab56e404bc6fae775c5d91e705c9df3f5 (diff) | |
download | pleroma-37e406ae36e4b7f922cb46d7873ec584768a721b.tar.gz |
Get avatar and banner from AP users.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/user.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 16 |
2 files changed, 15 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} |