Add header image to masto api.
authorRoger Braun <roger@rogerbraun.net>
Sun, 10 Sep 2017 08:37:34 +0000 (10:37 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sun, 10 Sep 2017 08:37:34 +0000 (10:37 +0200)
lib/pleroma/web/mastodon_api/views/account_view.ex
test/web/mastodon_api/account_view_test.exs

index 5f6ca84d0941f633a610203d8fa257ab2b73b776..35a130b1edba6ef57e5389841101289e00d1ecfe 100644 (file)
@@ -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 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
       url: user.ap_id,
       avatar: image,
       avatar_static: image,
-      header: "",
-      header_static: ""
+      header: header,
+      header_static: header
     }
   end
 
index f0c8673ade048cd2e342b632cd4e8a21841892eb..59fac6d95bd2453280eb4c370f31f546a711205c 100644 (file)
@@ -20,8 +20,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest 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})