diff --git a/lib/philomena_web/templates/user_attribution/_anon_user_avatar.html.slime b/lib/philomena_web/templates/user_attribution/_anon_user_avatar.html.slime index 1d149919..b28207b4 100644 --- a/lib/philomena_web/templates/user_attribution/_anon_user_avatar.html.slime +++ b/lib/philomena_web/templates/user_attribution/_anon_user_avatar.html.slime @@ -1,4 +1,4 @@ = if !!@object.user and !@object.anonymous do - = anonymous_avatar(@object) + = user_avatar(@object) - else - = user_avatar(@object) \ No newline at end of file + = anonymous_avatar(@object) \ No newline at end of file diff --git a/lib/philomena_web/views/user_attribution_view.ex b/lib/philomena_web/views/user_attribution_view.ex index 619556b7..2b2ca5cc 100644 --- a/lib/philomena_web/views/user_attribution_view.ex +++ b/lib/philomena_web/views/user_attribution_view.ex @@ -16,15 +16,14 @@ defmodule PhilomenaWeb.UserAttributionView do img_tag(Routes.static_path(PhilomenaWeb.Endpoint, "/images/no_avatar.svg"), class: class) end - def user_avatar(object, class \\ "avatar--100px") do - user = object.user + def user_avatar(object, class \\ "avatar--100px") - if user && user.avatar do - img_tag(avatar_url_root() <> object.user.avatar, class: class) - else - anonymous_avatar(object, class) - end - end + def user_avatar(%{user: nil} = object, class), + do: anonymous_avatar(object, class) + def user_avatar(%{user: %{avatar: nil}} = object, class), + do: anonymous_avatar(object, class) + def user_avatar(%{user: %{avatar: avatar}}, class), + do: img_tag(avatar_url_root() <> avatar, class: class) defp avatar_url_root do Application.get_env(:philomena, :avatar_url_root)