From 03a9c11d25a33eddd89175578617da1f2f766088 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 16 Apr 2017 15:40:50 +0200 Subject: [PATCH] Display the users avatar if he has one set. --- .../twitter_api/representers/user_representer.ex | 6 ++++-- .../representers/user_representer_test.exs | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/pleroma/web/twitter_api/representers/user_representer.ex b/lib/pleroma/web/twitter_api/representers/user_representer.ex index d8f98488e..2ee4ee254 100644 --- a/lib/pleroma/web/twitter_api/representers/user_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/user_representer.ex @@ -4,8 +4,10 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenter do alias Pleroma.User def to_map(user, opts) do - - image = "https://placehold.it/48x48" + image = case user.avatar do + %{"url" => [%{"href" => href} | _]} -> href + _ -> "https://placehold.it/48x48" + end following = if opts[:for] do User.following?(opts[:for], user) diff --git a/test/web/twitter_api/representers/user_representer_test.exs b/test/web/twitter_api/representers/user_representer_test.exs index 324d60982..913d1322c 100644 --- a/test/web/twitter_api/representers/user_representer_test.exs +++ b/test/web/twitter_api/representers/user_representer_test.exs @@ -8,18 +8,19 @@ defmodule Pleroma.Web.TwitterAPI.Representers.UserRepresenterTest do import Pleroma.Factory setup do - # {:ok, user} = UserBuilder.insert user = insert(:user) [user: user] 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 image = "https://placehold.it/48x48" - image = if user.avatar do - - else - image - end represented = %{ "id" => user.id,