forked from mirrors/akkoma
Merge branch 'default-pictures' into 'develop'
Add a default profile picture and banner. See merge request pleroma/pleroma!48
This commit is contained in:
commit
80f6ac412a
|
@ -29,14 +29,14 @@ defmodule Pleroma.User do
|
||||||
def avatar_url(user) do
|
def avatar_url(user) do
|
||||||
case user.avatar do
|
case user.avatar do
|
||||||
%{"url" => [%{"href" => href} | _]} -> href
|
%{"url" => [%{"href" => href} | _]} -> href
|
||||||
_ -> "https://placehold.it/48x48"
|
_ -> "#{Web.base_url()}/static/avi.png"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def banner_url(user) do
|
def banner_url(user) do
|
||||||
case user.info["banner"] do
|
case user.info["banner"] do
|
||||||
%{"url" => [%{"href" => href} | _]} -> href
|
%{"url" => [%{"href" => href} | _]} -> href
|
||||||
_ -> nil
|
_ -> "#{Web.base_url()}/static/banner.png"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,19 +5,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.MediaProxy
|
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
|
def render("accounts.json", %{users: users} = opts) do
|
||||||
render_many(users, AccountView, "account.json", opts)
|
render_many(users, AccountView, "account.json", opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("account.json", %{user: user}) do
|
def render("account.json", %{user: user}) do
|
||||||
image = User.avatar_url(user) |> MediaProxy.url()
|
image = User.avatar_url(user) |> MediaProxy.url()
|
||||||
|
header = User.banner_url(user) |> MediaProxy.url()
|
||||||
user_info = User.user_info(user)
|
user_info = User.user_info(user)
|
||||||
|
|
||||||
header = (image_url(user.info["banner"]) || "https://placehold.it/700x335") |> MediaProxy.url()
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
id: to_string(user.id),
|
id: to_string(user.id),
|
||||||
username: hd(String.split(user.nickname, "@")),
|
username: hd(String.split(user.nickname, "@")),
|
||||||
|
|
|
@ -45,7 +45,7 @@ def render("user.json", %{user: user = %User{}} = assigns) do
|
||||||
"screen_name" => user.nickname,
|
"screen_name" => user.nickname,
|
||||||
"statuses_count" => user_info[:note_count],
|
"statuses_count" => user_info[:note_count],
|
||||||
"statusnet_profile_url" => user.ap_id,
|
"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(),
|
"background_image" => image_url(user.info["background"]) |> MediaProxy.url(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
priv/static/static/avi.png
Normal file
BIN
priv/static/static/avi.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
priv/static/static/banner.png
Normal file
BIN
priv/static/static/banner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -19,10 +19,10 @@ test "Represent a user account" do
|
||||||
statuses_count: 5,
|
statuses_count: 5,
|
||||||
note: user.bio,
|
note: user.bio,
|
||||||
url: user.ap_id,
|
url: user.ap_id,
|
||||||
avatar: "https://placehold.it/48x48",
|
avatar: "http://localhost:4001/static/avi.png",
|
||||||
avatar_static: "https://placehold.it/48x48",
|
avatar_static: "http://localhost:4001/static/avi.png",
|
||||||
header: "https://placehold.it/700x335",
|
header: "http://localhost:4001/static/banner.png",
|
||||||
header_static: "https://placehold.it/700x335",
|
header_static: "http://localhost:4001/static/banner.png",
|
||||||
source: %{
|
source: %{
|
||||||
note: "",
|
note: "",
|
||||||
privacy: "public",
|
privacy: "public",
|
||||||
|
|
|
@ -21,6 +21,7 @@ test "returns a user with id, uri, name and link" do
|
||||||
<summary>#{user.bio}</summary>
|
<summary>#{user.bio}</summary>
|
||||||
<name>#{user.nickname}</name>
|
<name>#{user.nickname}</name>
|
||||||
<link rel="avatar" href="#{User.avatar_url(user)}" />
|
<link rel="avatar" href="#{User.avatar_url(user)}" />
|
||||||
|
<link rel="header" href="#{User.banner_url(user)}" />
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert clean(res) == clean(expected)
|
assert clean(res) == clean(expected)
|
||||||
|
|
|
@ -33,7 +33,8 @@ test "A user" do
|
||||||
{:ok, user} = User.update_follower_count(user)
|
{:ok, user} = User.update_follower_count(user)
|
||||||
Cachex.set(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
|
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 = %{
|
represented = %{
|
||||||
"id" => user.id,
|
"id" => user.id,
|
||||||
|
@ -54,7 +55,7 @@ test "A user" do
|
||||||
"statusnet_blocking" => false,
|
"statusnet_blocking" => false,
|
||||||
"rights" => %{},
|
"rights" => %{},
|
||||||
"statusnet_profile_url" => user.ap_id,
|
"statusnet_profile_url" => user.ap_id,
|
||||||
"cover_photo" => nil,
|
"cover_photo" => banner,
|
||||||
"background_image" => nil
|
"background_image" => nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +65,9 @@ test "A user" do
|
||||||
test "A user for a given other follower", %{user: user} do
|
test "A user for a given other follower", %{user: user} do
|
||||||
{:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
|
{:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
|
||||||
{:ok, user} = User.update_follower_count(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 = %{
|
represented = %{
|
||||||
"id" => user.id,
|
"id" => user.id,
|
||||||
"name" => user.name,
|
"name" => user.name,
|
||||||
|
@ -84,7 +87,7 @@ test "A user for a given other follower", %{user: user} do
|
||||||
"statusnet_blocking" => false,
|
"statusnet_blocking" => false,
|
||||||
"rights" => %{},
|
"rights" => %{},
|
||||||
"statusnet_profile_url" => user.ap_id,
|
"statusnet_profile_url" => user.ap_id,
|
||||||
"cover_photo" => nil,
|
"cover_photo" => banner,
|
||||||
"background_image" => nil
|
"background_image" => nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +98,9 @@ test "A user that follows you", %{user: user} do
|
||||||
follower = insert(:user)
|
follower = insert(:user)
|
||||||
{:ok, follower} = User.follow(follower, user)
|
{:ok, follower} = User.follow(follower, user)
|
||||||
{:ok, user} = User.update_follower_count(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 = %{
|
represented = %{
|
||||||
"id" => follower.id,
|
"id" => follower.id,
|
||||||
"name" => follower.name,
|
"name" => follower.name,
|
||||||
|
@ -115,7 +120,7 @@ test "A user that follows you", %{user: user} do
|
||||||
"statusnet_blocking" => false,
|
"statusnet_blocking" => false,
|
||||||
"rights" => %{},
|
"rights" => %{},
|
||||||
"statusnet_profile_url" => follower.ap_id,
|
"statusnet_profile_url" => follower.ap_id,
|
||||||
"cover_photo" => nil,
|
"cover_photo" => banner,
|
||||||
"background_image" => nil
|
"background_image" => nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +131,9 @@ test "A blocked user for the blocker", %{user: user} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
blocker = insert(:user)
|
blocker = insert(:user)
|
||||||
User.block(blocker, 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 = %{
|
represented = %{
|
||||||
"id" => user.id,
|
"id" => user.id,
|
||||||
"name" => user.name,
|
"name" => user.name,
|
||||||
|
@ -146,7 +153,7 @@ test "A blocked user for the blocker", %{user: user} do
|
||||||
"statusnet_blocking" => true,
|
"statusnet_blocking" => true,
|
||||||
"rights" => %{},
|
"rights" => %{},
|
||||||
"statusnet_profile_url" => user.ap_id,
|
"statusnet_profile_url" => user.ap_id,
|
||||||
"cover_photo" => nil,
|
"cover_photo" => banner,
|
||||||
"background_image" => nil
|
"background_image" => nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue