forked from AkkomaGang/akkoma
Display the users avatar if he has one set.
This commit is contained in:
parent
d7e3b72c6a
commit
03a9c11d25
2 changed files with 11 additions and 8 deletions
|
@ -4,8 +4,10 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
def to_map(user, opts) do
|
def to_map(user, opts) do
|
||||||
|
image = case user.avatar do
|
||||||
image = "https://placehold.it/48x48"
|
%{"url" => [%{"href" => href} | _]} -> href
|
||||||
|
_ -> "https://placehold.it/48x48"
|
||||||
|
end
|
||||||
|
|
||||||
following = if opts[:for] do
|
following = if opts[:for] do
|
||||||
User.following?(opts[:for], user)
|
User.following?(opts[:for], user)
|
||||||
|
|
|
@ -8,18 +8,19 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenterTest do
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
# {:ok, user} = UserBuilder.insert
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
[user: user]
|
[user: user]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "A user with an avatar object", %{user: user} do
|
||||||
|
image = "image"
|
||||||
|
user = %{ user | avatar: %{ "url" => [%{"href" => image}] }}
|
||||||
|
represented = UserRepresenter.to_map(user)
|
||||||
|
assert represented["profile_image_url"] == image
|
||||||
|
end
|
||||||
|
|
||||||
test "A user", %{user: user} do
|
test "A user", %{user: user} do
|
||||||
image = "https://placehold.it/48x48"
|
image = "https://placehold.it/48x48"
|
||||||
image = if user.avatar do
|
|
||||||
|
|
||||||
else
|
|
||||||
image
|
|
||||||
end
|
|
||||||
|
|
||||||
represented = %{
|
represented = %{
|
||||||
"id" => user.id,
|
"id" => user.id,
|
||||||
|
|
Loading…
Reference in a new issue