AccountView: Add user background.
authorlain <lain@soykaf.club>
Thu, 13 Jun 2019 17:08:05 +0000 (19:08 +0200)
committerlain <lain@soykaf.club>
Thu, 13 Jun 2019 17:08:05 +0000 (19:08 +0200)
lib/pleroma/web/mastodon_api/views/account_view.ex
test/web/mastodon_api/account_view_test.exs

index b91726b45df557f97c18e42bb86b67a4a8f70407..0ec9ecd93f15c7ab8f50f6752323c9f623876803 100644 (file)
@@ -125,7 +125,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
         hide_follows: user.info.hide_follows,
         hide_favorites: user.info.hide_favorites,
         relationship: relationship,
-        skip_thread_containment: user.info.skip_thread_containment
+        skip_thread_containment: user.info.skip_thread_containment,
+        background_image: image_url(user.info.background) |> MediaProxy.url()
       }
     }
     |> maybe_put_role(user, opts[:for])
@@ -182,4 +183,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
   end
 
   defp maybe_put_notification_settings(data, _, _), do: data
+
+  defp image_url(%{"url" => [%{"href" => href} | _]}), do: href
+  defp image_url(_), do: nil
 end
index e2244dcb7c8ca0182994e6c3a6024fd186ed4ea7..2ba7c050559f9820766b367b463f3e8d5f1dada7 100644 (file)
@@ -19,9 +19,18 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       ]
     }
 
+    background_image = %{
+      "url" => [%{"href" => "https://example.com/images/asuka_hospital.png"}]
+    }
+
     user =
       insert(:user, %{
-        info: %{note_count: 5, follower_count: 3, source_data: source_data},
+        info: %{
+          note_count: 5,
+          follower_count: 3,
+          source_data: source_data,
+          background: background_image
+        },
         nickname: "shp@shitposter.club",
         name: ":karjalanpiirakka: shp",
         bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
@@ -60,6 +69,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
         pleroma: %{}
       },
       pleroma: %{
+        background_image: "https://example.com/images/asuka_hospital.png",
         confirmation_pending: false,
         tags: [],
         is_admin: false,
@@ -126,6 +136,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
         pleroma: %{}
       },
       pleroma: %{
+        background_image: nil,
         confirmation_pending: false,
         tags: [],
         is_admin: false,
@@ -216,6 +227,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
         pleroma: %{}
       },
       pleroma: %{
+        background_image: nil,
         confirmation_pending: false,
         tags: [],
         is_admin: false,