From e8975d06bed653f362777ee7046f8bb0129e461e Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 10 Sep 2017 10:37:34 +0200 Subject: [PATCH] Add header image to masto api. --- lib/pleroma/web/mastodon_api/views/account_view.ex | 9 +++++++-- test/web/mastodon_api/account_view_test.exs | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 5f6ca84d0..35a130b1e 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -2,10 +2,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do use Pleroma.Web, :view alias Pleroma.User + defp image_url(%{"url" => [ %{ "href" => href } | t ]}), do: href + defp image_url(_), do: nil + def render("account.json", %{user: user}) do image = User.avatar_url(user) user_info = User.user_info(user) + header = image_url(user.info["banner"]) || "https://placehold.it/700x335" + %{ id: user.id, username: user.nickname, @@ -20,8 +25,8 @@ def render("account.json", %{user: user}) do url: user.ap_id, avatar: image, avatar_static: image, - header: "", - header_static: "" + header: header, + header_static: header } end diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index f0c8673ad..59fac6d95 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -20,8 +20,8 @@ test "Represent a user account" do url: user.ap_id, avatar: "https://placehold.it/48x48", avatar_static: "https://placehold.it/48x48", - header: "", - header_static: "" + header: "https://placehold.it/700x335", + header_static: "https://placehold.it/700x335" } assert expected == AccountView.render("account.json", %{user: user})