From 14b086eec22486d1efc8248f5f157696e7621e5b Mon Sep 17 00:00:00 2001
From: eal <eal@waifu.club>
Date: Mon, 15 Jan 2018 22:18:17 +0200
Subject: [PATCH] Add a default profile picture and banner.

This removes the placehold.it dependency.
---
 lib/pleroma/user.ex                           |   4 +--
 .../web/mastodon_api/views/account_view.ex    |   6 +----
 .../web/twitter_api/views/user_view.ex        |   2 +-
 priv/static/static/avi.png                    | Bin 0 -> 3604 bytes
 priv/static/static/banner.png                 | Bin 0 -> 1293 bytes
 test/web/mastodon_api/account_view_test.exs   |   8 +++---
 test/web/ostatus/user_representer_test.exs    |   1 +
 test/web/twitter_api/views/user_view_test.exs |  23 ++++++++++++------
 8 files changed, 24 insertions(+), 20 deletions(-)
 create mode 100644 priv/static/static/avi.png
 create mode 100644 priv/static/static/banner.png

diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 09bcf0cb4..6ba2b165c 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -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
 
diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex
index 1d5918988..d2a4dd366 100644
--- a/lib/pleroma/web/mastodon_api/views/account_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/account_view.ex
@@ -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, "@")),
diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex
index cc6b450fb..1b995f42f 100644
--- a/lib/pleroma/web/twitter_api/views/user_view.ex
+++ b/lib/pleroma/web/twitter_api/views/user_view.ex
@@ -45,7 +45,7 @@ def render("user.json", %{user: user = %User{}} = assigns) 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
index 0000000000000000000000000000000000000000..336fd15ef331c88a057ce05ce49ae237b4e7bfbf
GIT binary patch
literal 3604
zcmY*ccQo8v*ZvXl265G>(WB1jgTXLJqGgCKdauzt(GuY%Ve}GZ^wFXuYP66W-59+D
zgR3)o4N<<i-}=7wzV9D<?{)S$XRou)+2`5&d9S0bMoG>>4gdh9hWZmdg0=of?hzBT
z`{j}+!H{{WoA?3%1>HYF1Z3qf5u9u;1~2>`d%C+jc=!>90Pxty!N$+Qo-@$J&zVzA
zLrceA#Nl6rs3?sm$_7ERyE!ff^u`R4p2mU3f#X^-NX~mW@Q@G$S=-P3F0xD@zvl_k
zF<C=GmRVBrLfm&f=R(R?I~<c~l_F_^>9?mvGEIE7PA#MU{xvGH_8zei_wTXanl;BO
z%IHnxA42_z?cAHg%XZ^QLo3{?#rE?DBhu-H0B`QyB5IvT0VR4)a_YP9h@TJ@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dnXh^L?R>rMOkIk2zKmNo!u83;3RoSWz
z@AqE&yuH*X`8UD&Umm0R-=rr}py0nq4^iP;;`+oZM$*`UD!}7}_8$hP@l^XswTktd
F{{dsjz|jBz

literal 0
HcmV?d00001

diff --git a/priv/static/static/banner.png b/priv/static/static/banner.png
new file mode 100644
index 0000000000000000000000000000000000000000..467c075d64667cdb67bac4c20ee06153bb28a774
GIT binary patch
literal 1293
zcmeAS@N?(olHy`uVBq!ia0y~yVA{jL!06Ax1Qby)>#_q<oCO|{#S9GG!XV7ZFl&wk
zP*65AB%;JQKQ}iuuLQ_tU~n!<O)N=GQ7F$W$xv|j^bJVSOJ!$ZV43FW;uunK>+Lm1
zK_HL8@yq!nH)lbX4bl(ereBt2V3<CMfx&>6p&^rj!H1b4L5hLlG6Ta5HW+olgn?lh
zBa#XXg-{h33ZX_JOhi?I%}$UCpw*}fp{_!496|-E;}DiXeSuI2b@!<A!BIUL`k*8|
gFo|cvXomCG`ErA0_3f=M|AUGyPgg&ebxsLQ0Kkg+N&o-=

literal 0
HcmV?d00001

diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index eccfe0b36..061fc2693 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -19,10 +19,10 @@ test "Represent a user account" 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",
diff --git a/test/web/ostatus/user_representer_test.exs b/test/web/ostatus/user_representer_test.exs
index d5d70f5c6..b22420379 100644
--- a/test/web/ostatus/user_representer_test.exs
+++ b/test/web/ostatus/user_representer_test.exs
@@ -21,6 +21,7 @@ test "returns a user with id, uri, name and link" 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)
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 753e41d20..3f84e4116 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -33,7 +33,8 @@ test "A user" 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 @@ test "A user" do
       "statusnet_blocking" => false,
       "rights" => %{},
       "statusnet_profile_url" => user.ap_id,
-      "cover_photo" => nil,
+      "cover_photo" => banner,
       "background_image" => nil
     }
 
@@ -64,7 +65,9 @@ test "A user" 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 @@ test "A user for a given other follower", %{user: user} do
       "statusnet_blocking" => false,
       "rights" => %{},
       "statusnet_profile_url" => user.ap_id,
-      "cover_photo" => nil,
+      "cover_photo" => banner,
       "background_image" => nil
     }
 
@@ -95,7 +98,9 @@ test "A user that follows you", %{user: user} 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 @@ test "A user that follows you", %{user: user} do
       "statusnet_blocking" => false,
       "rights" => %{},
       "statusnet_profile_url" => follower.ap_id,
-      "cover_photo" => nil,
+      "cover_photo" => banner,
       "background_image" => nil
     }
 
@@ -126,7 +131,9 @@ test "A blocked user for the blocker", %{user: user} 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 @@ test "A blocked user for the blocker", %{user: user} do
       "statusnet_blocking" => true,
       "rights" => %{},
       "statusnet_profile_url" => user.ap_id,
-      "cover_photo" => nil,
+      "cover_photo" => banner,
       "background_image" => nil
     }