diff --git a/lib/philomena_web/templates/admin/report/show.html.slime b/lib/philomena_web/templates/admin/report/show.html.slime index c0b462b68..d993be92d 100644 --- a/lib/philomena_web/templates/admin/report/show.html.slime +++ b/lib/philomena_web/templates/admin/report/show.html.slime @@ -5,10 +5,10 @@ p article.block.communication .block__content.communication__content.flex.flex--no-wrap .communication__body__avatar.hide-mobile - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @report, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @report, conn: @conn, profile_link: true .flex__grow.communication__body .communication__body__avatar.hide-desktop - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @report, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @report, conn: @conn, profile_link: true .communication__body__sender span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @report, awards: true, conn: @conn br diff --git a/lib/philomena_web/templates/comment/_comment.html.slime b/lib/philomena_web/templates/comment/_comment.html.slime index 8ac3285dc..5e0726f8b 100644 --- a/lib/philomena_web/templates/comment/_comment.html.slime +++ b/lib/philomena_web/templates/comment/_comment.html.slime @@ -23,10 +23,10 @@ article.block.communication id="comment_#{@comment.id}" .block__content.communication__content.flex.flex--no-wrap class=communication_body_class(@comment) .communication__body__avatar.hide-mobile - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn, profile_link: true .flex__grow.communication__body .communication__body__avatar.hide-desktop - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn, profile_link: true .communication__body__sender span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @comment, awards: true, conn: @conn br diff --git a/lib/philomena_web/templates/commission/_directory_results.html.slime b/lib/philomena_web/templates/commission/_directory_results.html.slime index 3e8b1aebc..e68112886 100644 --- a/lib/philomena_web/templates/commission/_directory_results.html.slime +++ b/lib/philomena_web/templates/commission/_directory_results.html.slime @@ -23,7 +23,7 @@ elixir: .block.commission .block__content.flex.flex--no-wrap .flex__fixed.spacing-right - = render PhilomenaWeb.UserAttributionView, "_user_avatar.html", object: c, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_user_avatar.html", object: c, conn: @conn, profile_link: true .flex__grow.commission__listing_body span.commission__listing_artist diff --git a/lib/philomena_web/templates/image/comment/history/index.html.slime b/lib/philomena_web/templates/image/comment/history/index.html.slime index 32eb0ada4..879adce50 100644 --- a/lib/philomena_web/templates/image/comment/history/index.html.slime +++ b/lib/philomena_web/templates/image/comment/history/index.html.slime @@ -10,11 +10,11 @@ h1 article.block.communication .block__content.communication__content.flex.flex--no-wrap .communication__body__avatar.hide-mobile - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn, profile_link: true .flex__grow.communication__body .communication__body__avatar.hide-desktop - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment, conn: @conn, profile_link: true .communication__body__sender span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @comment, awards: true, conn: @conn br diff --git a/lib/philomena_web/templates/message/_message.html.slime b/lib/philomena_web/templates/message/_message.html.slime index 2820d5cec..ab4eff5b6 100644 --- a/lib/philomena_web/templates/message/_message.html.slime +++ b/lib/philomena_web/templates/message/_message.html.slime @@ -15,11 +15,11 @@ article.block.communication .block__content.communication__content.flex.flex--no-wrap .communication__body__avatar.hide-mobile - = render PhilomenaWeb.UserAttributionView, "_user_avatar.html", object: %{user: @message.from}, conn: @conn, class: "avatar--100px" + = render PhilomenaWeb.UserAttributionView, "_user_avatar.html", object: %{user: @message.from}, conn: @conn, class: "avatar--100px", profile_link: true .flex__grow.communication__body .communication__body__avatar.hide-desktop - = render PhilomenaWeb.UserAttributionView, "_user_avatar.html", object: %{user: @message.from}, conn: @conn, class: "avatar--100px" + = render PhilomenaWeb.UserAttributionView, "_user_avatar.html", object: %{user: @message.from}, conn: @conn, class: "avatar--100px", profile_link: true .communication__body__sender span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_user.html", object: %{user: @message.from}, badges: true, conn: @conn br diff --git a/lib/philomena_web/templates/post/_post.html.slime b/lib/philomena_web/templates/post/_post.html.slime index 8f9861244..5956801bb 100644 --- a/lib/philomena_web/templates/post/_post.html.slime +++ b/lib/philomena_web/templates/post/_post.html.slime @@ -23,10 +23,10 @@ article.block.communication id="post_#{@post.id}" .block__content.communication__content.flex.flex--no-wrap class=communication_body_class(@post) .communication__body__avatar.hide-mobile - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn, profile_link: true .flex__grow.communication__body .communication__body__avatar.hide-desktop - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn, profile_link: true .communication__body__sender span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @post, awards: true, conn: @conn br diff --git a/lib/philomena_web/templates/post/preview/create.html.slime b/lib/philomena_web/templates/post/preview/create.html.slime index 2c07907b3..cd7c0f439 100644 --- a/lib/philomena_web/templates/post/preview/create.html.slime +++ b/lib/philomena_web/templates/post/preview/create.html.slime @@ -1,10 +1,10 @@ .block.flex.communication__content .communication__body__avatar.hide-mobile - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn, profile_link: true .flex__grow.communication__body .communication__body__avatar.hide-desktop - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn, profile_link: true .communication__body__sender span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @post, conn: @conn, awards: true diff --git a/lib/philomena_web/templates/topic/post/history/index.html.slime b/lib/philomena_web/templates/topic/post/history/index.html.slime index 2d0876a0b..b22e7e1b9 100644 --- a/lib/philomena_web/templates/topic/post/history/index.html.slime +++ b/lib/philomena_web/templates/topic/post/history/index.html.slime @@ -9,11 +9,11 @@ h1 article.block.communication .block__content.flex.flex--no-wrap.communication__content .communication__body__avatar.hide-mobile - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn, profile_link: true .flex__grow.communication__body .communication__body__avatar.hide-desktop - = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post, conn: @conn, profile_link: true .communication__body__sender span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @post, awards: true, conn: @conn br 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 8e31711f8..6781dc314 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,5 @@ +- opts = [class: assigns[:class], profile_link: assigns[:profile_link]] = if !!@object.user and !anonymous?(@object) do - = user_avatar(@object, assigns[:class] || "avatar--100px") + = user_avatar(@object, opts) - else - = anonymous_avatar(anonymous_name(@object), assigns[:class] || "avatar--100px") + = anonymous_avatar(anonymous_name(@object), @object[:user], opts) diff --git a/lib/philomena_web/templates/user_attribution/_user_avatar.html.slime b/lib/philomena_web/templates/user_attribution/_user_avatar.html.slime index 847499e76..07f771c0a 100644 --- a/lib/philomena_web/templates/user_attribution/_user_avatar.html.slime +++ b/lib/philomena_web/templates/user_attribution/_user_avatar.html.slime @@ -1,2 +1,2 @@ = if !!@object.user do - = user_avatar(@object, assigns[:class] || "avatar--100px") + = user_avatar(@object, class: assigns[:class], profile_link: assigns[:profile_link]) diff --git a/lib/philomena_web/views/user_attribution_view.ex b/lib/philomena_web/views/user_attribution_view.ex index 668ecbc4d..2ca2eee2a 100644 --- a/lib/philomena_web/views/user_attribution_view.ex +++ b/lib/philomena_web/views/user_attribution_view.ex @@ -1,5 +1,6 @@ defmodule PhilomenaWeb.UserAttributionView do use PhilomenaWeb, :view + require Logger alias Philomena.Attribution alias PhilomenaWeb.AvatarGeneratorView @@ -40,39 +41,52 @@ defmodule PhilomenaWeb.UserAttributionView do end end - def anonymous_avatar(name, class \\ "avatar--100px") do - class = Enum.join(["image-constrained", class], " ") + def anonymous_avatar(name, user, opts) do + content = AvatarGeneratorView.generated_avatar(name) + make_user_avatar(user, content, opts) + end + + def user_avatar(object, opts \\ []) do + user = Map.get(object, :user) - content_tag :div, class: class do - AvatarGeneratorView.generated_avatar(name) + case user do + nil -> anonymous_avatar(anonymous_name(object), nil, opts) + %{avatar: nil} -> anonymous_avatar(user.name, user, opts) + _ -> named_user_avatar(user, opts) end end - def user_avatar(object, class \\ "avatar--100px") + defp named_user_avatar(user, opts) do + content = img_tag(avatar_url_root() <> "/" <> user.avatar) + make_user_avatar(user, content, opts) + end - def user_avatar(%{user: nil} = object, class), - do: anonymous_avatar(anonymous_name(object), class) + defp make_user_avatar(user, content, opts) do + class = Keyword.get(opts, :class) || "avatar--100px" + profile_link = Keyword.get(opts, :profile_link) || false - def user_avatar(%{user: %{avatar: nil}} = object, class), - do: anonymous_avatar(object.user.name, class) + {tag, attrs} = + if profile_link and !!user do + {:a, [href: ~p"/profiles/#{user}"]} + else + {:div, []} + end - def user_avatar(%{user: %{avatar: avatar}}, class) do class = Enum.join(["image-constrained", class], " ") + attrs = Keyword.put(attrs, :class, class) - content_tag :div, class: class do - img_tag(avatar_url_root() <> "/" <> avatar) - end + content_tag(tag, content, attrs) end - def user_avatar_url(%{user: %{avatar: nil}} = object) do + defp user_avatar_url(%{user: %{avatar: nil}} = object) do anonymous_avatar_url(object.user.name) end - def user_avatar_url(%{user: %{avatar: avatar}}) do + defp user_avatar_url(%{user: %{avatar: avatar}}) do avatar_url_root() <> "/" <> avatar end - def anonymous_avatar_url(name) do + defp anonymous_avatar_url(name) do svg = name |> AvatarGeneratorView.generated_avatar()