mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 12:37:58 +01:00
723bfa213f
* AwardJson, LinkJson, UserJson to views * FilterJson -> view * ForumJson -> view * TopicJson -> view * PostJson -> view * TagJson -> view * CommentJson -> view * GalleryJson -> view
57 lines
1.6 KiB
Elixir
57 lines
1.6 KiB
Elixir
defmodule PhilomenaWeb.Api.Json.CommentView do
|
|
use PhilomenaWeb, :view
|
|
alias PhilomenaWeb.UserAttributionView
|
|
|
|
def render("index.json", %{comments: comments, total: total} = assigns) do
|
|
%{
|
|
comments: render_many(comments, PhilomenaWeb.Api.Json.CommentView, "comment.json", assigns),
|
|
total: total
|
|
}
|
|
end
|
|
|
|
def render("show.json", %{comment: comment} = assigns) do
|
|
%{comment: render_one(comment, PhilomenaWeb.Api.Json.CommentView, "comment.json", assigns)}
|
|
end
|
|
|
|
def render("comment.json", %{comment: %{destroyed_content: true}}) do
|
|
nil
|
|
end
|
|
|
|
def render("comment.json", %{comment: %{image: %{hidden_from_users: true}} = comment}) do
|
|
%{
|
|
id: comment.id,
|
|
image_id: comment.image_id,
|
|
user_id: nil,
|
|
author: nil,
|
|
body: nil
|
|
}
|
|
end
|
|
|
|
def render("comment.json", %{comment: %{hidden_from_users: true} = comment}) do
|
|
%{
|
|
id: comment.id,
|
|
image_id: comment.image_id,
|
|
user_id: if(not comment.anonymous, do: comment.user_id),
|
|
author:
|
|
if(comment.anonymous or is_nil(comment.user),
|
|
do: UserAttributionView.anonymous_name(comment),
|
|
else: comment.user.name
|
|
),
|
|
body: nil
|
|
}
|
|
end
|
|
|
|
def render("comment.json", %{comment: comment}) do
|
|
%{
|
|
id: comment.id,
|
|
image_id: comment.image_id,
|
|
user_id: if(not comment.anonymous, do: comment.user_id),
|
|
author:
|
|
if(comment.anonymous or is_nil(comment.user),
|
|
do: UserAttributionView.anonymous_name(comment),
|
|
else: comment.user.name
|
|
),
|
|
body: comment.body
|
|
}
|
|
end
|
|
end
|