From 14b086eec22486d1efc8248f5f157696e7621e5b Mon Sep 17 00:00:00 2001 From: eal 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<>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 zF9?mvGEIE7PA#MU{xvGH_8zei_wTXanl;BO z%IHnxA42_z?cAHg%XZ^QLo3{?#rE?DBhu-H0B`QyB5IvT0VR4)a_YP9h@TJ@0=g>y zsQ>Vh{r|-O`FIJ7NA!q4&_<7M!Fk7%=XdH?i#h!7q2j-oK(nLkyh3R@`VPWeXO7nP zcjoLMLw;vxxz(-q4L{RA{*l)U!VWo#G2J!UGL+gVNz=577XpC=`Y=kn=Tz+M%y~hU zEcJ@=6adtXAz{!WL{2@7={_lN01bDon(8eoKJjek27jS z6xb9KGLo|1%sR1(m{l5C#nVQ|kd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YraNwK>1mj^WhnvP*(W%(E#K0kCAaQ z5-`l^GKd>zv3$ICJ<;_RG$gF836T{(Uz_Bz?dM=&O*lzp-$JT3tH^R0Bl_0p^vCV=^(K$@|Dnrza1DW--Hl(y%{=BW_Us9X;;;VSBq((PK+ z5po@^g>I5>aTT>Xoa}1hfL$%=Oum$F(n5e(6g)A5X+mgI1*o(l6t+y#NBC-G6}bii z?eoFcr`fyhVeqpC{pUVKyL-sS)>!E0@^*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+Lm1 zK_HL8@yq!nH)lbX4bl(ereBt2V36p&^rj!H1b4L5hLlG6Ta5HW+olgn?lh zBa#XXg-{h33ZX_JOhi?I%}$UCpw*}fp{_!496|-E;}DiXeSuI2b@!#{user.bio} #{user.nickname} + """ 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 }