Add a default profile picture and banner.
authoreal <eal@waifu.club>
Mon, 15 Jan 2018 20:18:17 +0000 (22:18 +0200)
committereal <eal@waifu.club>
Mon, 15 Jan 2018 20:18:17 +0000 (22:18 +0200)
This removes the placehold.it dependency.

lib/pleroma/user.ex
lib/pleroma/web/mastodon_api/views/account_view.ex
lib/pleroma/web/twitter_api/views/user_view.ex
priv/static/static/avi.png [new file with mode: 0644]
priv/static/static/banner.png [new file with mode: 0644]
test/web/mastodon_api/account_view_test.exs
test/web/ostatus/user_representer_test.exs
test/web/twitter_api/views/user_view_test.exs

index 09bcf0cb494d5b75dd1d2eb4b94a3d6c8cde03bb..6ba2b165c3dacac885f75105cae111d3e665b4a0 100644 (file)
@@ -29,14 +29,14 @@ defmodule Pleroma.User do
   def avatar_url(user) do
     case user.avatar do
       %{"url" => [%{"href" => href} | _]} -> href
-      _ -> "https://placehold.it/48x48"
+      _ -> "#{Web.base_url()}/static/avi.png"
     end
   end
 
   def banner_url(user) do
     case user.info["banner"] do
       %{"url" => [%{"href" => href} | _]} -> href
-      _ -> nil
+      _ -> "#{Web.base_url()}/static/banner.png"
     end
   end
 
index 1d5918988822400da00be251f1948ca660a77f7e..d2a4dd3669fa5fae8f24734fecb1b216136cf879 100644 (file)
@@ -5,19 +5,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
   alias Pleroma.Web.CommonAPI.Utils
   alias Pleroma.Web.MediaProxy
 
-  defp image_url(%{"url" => [ %{ "href" => href } | _ ]}), do: href
-  defp image_url(_), do: nil
-
   def render("accounts.json", %{users: users} = opts) do
     render_many(users, AccountView, "account.json", opts)
   end
 
   def render("account.json", %{user: user}) do
     image = User.avatar_url(user) |> MediaProxy.url()
+    header = User.banner_url(user) |> MediaProxy.url()
     user_info = User.user_info(user)
 
-    header = (image_url(user.info["banner"]) || "https://placehold.it/700x335") |> MediaProxy.url()
-
     %{
       id: to_string(user.id),
       username: hd(String.split(user.nickname, "@")),
index cc6b450fb1f6067ced932388acb1774ccde0934a..1b995f42fea3322a901febd16750214338ef4264 100644 (file)
@@ -45,7 +45,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
       "screen_name" => user.nickname,
       "statuses_count" => user_info[:note_count],
       "statusnet_profile_url" => user.ap_id,
-      "cover_photo" => image_url(user.info["banner"]) |> MediaProxy.url(),
+      "cover_photo" => User.banner_url(user) |> MediaProxy.url(),
       "background_image" => image_url(user.info["background"]) |> MediaProxy.url(),
     }
 
diff --git a/priv/static/static/avi.png b/priv/static/static/avi.png
new file mode 100644 (file)
index 0000000..336fd15
Binary files /dev/null and b/priv/static/static/avi.png differ
diff --git a/priv/static/static/banner.png b/priv/static/static/banner.png
new file mode 100644 (file)
index 0000000..467c075
Binary files /dev/null and b/priv/static/static/banner.png differ
index eccfe0b366f4cf1d877d705dbbf21a274488fb97..061fc2693544fa596bcd56381c9d95e10db57287 100644 (file)
@@ -19,10 +19,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       statuses_count: 5,
       note: user.bio,
       url: user.ap_id,
-      avatar: "https://placehold.it/48x48",
-      avatar_static: "https://placehold.it/48x48",
-      header: "https://placehold.it/700x335",
-      header_static: "https://placehold.it/700x335",
+      avatar: "http://localhost:4001/static/avi.png",
+      avatar_static: "http://localhost:4001/static/avi.png",
+      header: "http://localhost:4001/static/banner.png",
+      header_static: "http://localhost:4001/static/banner.png",
       source: %{
         note: "",
         privacy: "public",
index d5d70f5c61a53c8d4704a1e8ae487ad58e62583e..b224203794d053273545ddde82a7144b6e0c5e93 100644 (file)
@@ -21,6 +21,7 @@ defmodule Pleroma.Web.OStatus.UserRepresenterTest do
     <summary>#{user.bio}</summary>
     <name>#{user.nickname}</name>
     <link rel="avatar" href="#{User.avatar_url(user)}" />
+    <link rel="header" href="#{User.banner_url(user)}" />
     """
 
     assert clean(res) == clean(expected)
index 753e41d20bc2f7c857e04a9af098d780353f905c..3f84e4116959e76c54b9b3f373783917561b2a58 100644 (file)
@@ -33,7 +33,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
     {:ok, user} = User.update_follower_count(user)
     Cachex.set(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
 
-    image = "https://placehold.it/48x48"
+    image = "http://localhost:4001/static/avi.png"
+    banner = "http://localhost:4001/static/banner.png"
 
     represented = %{
       "id" => user.id,
@@ -54,7 +55,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "statusnet_blocking" => false,
       "rights" => %{},
       "statusnet_profile_url" => user.ap_id,
-      "cover_photo" => nil,
+      "cover_photo" => banner,
       "background_image" => nil
     }
 
@@ -64,7 +65,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
   test "A user for a given other follower", %{user: user} do
     {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
     {:ok, user} = User.update_follower_count(user)
-    image = "https://placehold.it/48x48"
+    image = "http://localhost:4001/static/avi.png"
+    banner = "http://localhost:4001/static/banner.png"
+
     represented = %{
       "id" => user.id,
       "name" => user.name,
@@ -84,7 +87,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "statusnet_blocking" => false,
       "rights" => %{},
       "statusnet_profile_url" => user.ap_id,
-      "cover_photo" => nil,
+      "cover_photo" => banner,
       "background_image" => nil
     }
 
@@ -95,7 +98,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
     follower = insert(:user)
     {:ok, follower} = User.follow(follower, user)
     {:ok, user} = User.update_follower_count(user)
-    image = "https://placehold.it/48x48"
+    image = "http://localhost:4001/static/avi.png"
+    banner = "http://localhost:4001/static/banner.png"
+
     represented = %{
       "id" => follower.id,
       "name" => follower.name,
@@ -115,7 +120,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "statusnet_blocking" => false,
       "rights" => %{},
       "statusnet_profile_url" => follower.ap_id,
-      "cover_photo" => nil,
+      "cover_photo" => banner,
       "background_image" => nil
     }
 
@@ -126,7 +131,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
     user = insert(:user)
     blocker = insert(:user)
     User.block(blocker, user)
-    image = "https://placehold.it/48x48"
+    image = "http://localhost:4001/static/avi.png"
+    banner = "http://localhost:4001/static/banner.png"
+
     represented = %{
       "id" => user.id,
       "name" => user.name,
@@ -146,7 +153,7 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "statusnet_blocking" => true,
       "rights" => %{},
       "statusnet_profile_url" => user.ap_id,
-      "cover_photo" => nil,
+      "cover_photo" => banner,
       "background_image" => nil
     }