Display the users avatar if he has one set.
authorRoger Braun <roger@rogerbraun.net>
Sun, 16 Apr 2017 13:40:50 +0000 (15:40 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sun, 16 Apr 2017 13:40:50 +0000 (15:40 +0200)
lib/pleroma/web/twitter_api/representers/user_representer.ex
test/web/twitter_api/representers/user_representer_test.exs

index d8f98488e7cd817f33b09ce0b139ecc0d6d0d180..2ee4ee25443a00bc2a9d9dd16b8c5d20f5f777e7 100644 (file)
@@ -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)
index 324d6098250216f23cbb49387ca950e631b55af4..913d1322c0b20518e3e64f136937009510623517 100644 (file)
@@ -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,