2020-03-30 03:11:38 +02:00
|
|
|
defmodule PhilomenaWeb.Api.Json.CommentView do
|
|
|
|
use PhilomenaWeb, :view
|
2019-12-24 09:26:01 +01:00
|
|
|
alias PhilomenaWeb.UserAttributionView
|
|
|
|
|
2020-03-30 03:11:38 +02:00
|
|
|
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
|
2020-01-01 00:25:11 +01:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2020-03-30 03:11:38 +02:00
|
|
|
def render("comment.json", %{comment: %{image: %{hidden_from_users: true}} = comment}) do
|
2020-01-01 00:25:11 +01:00
|
|
|
%{
|
|
|
|
id: comment.id,
|
|
|
|
image_id: comment.image_id,
|
|
|
|
user_id: nil,
|
|
|
|
author: nil,
|
|
|
|
body: nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-03-30 03:11:38 +02:00
|
|
|
def render("comment.json", %{comment: %{hidden_from_users: true} = comment}) do
|
2020-01-01 00:25:11 +01:00
|
|
|
%{
|
|
|
|
id: comment.id,
|
|
|
|
image_id: comment.image_id,
|
|
|
|
user_id: if(not comment.anonymous, do: comment.user_id),
|
2020-01-11 05:20:19 +01:00
|
|
|
author:
|
|
|
|
if(comment.anonymous or is_nil(comment.user),
|
|
|
|
do: UserAttributionView.anonymous_name(comment),
|
|
|
|
else: comment.user.name
|
|
|
|
),
|
2020-01-01 00:25:11 +01:00
|
|
|
body: nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-03-30 03:11:38 +02:00
|
|
|
def render("comment.json", %{comment: comment}) do
|
2019-12-24 09:26:01 +01:00
|
|
|
%{
|
|
|
|
id: comment.id,
|
|
|
|
image_id: comment.image_id,
|
|
|
|
user_id: if(not comment.anonymous, do: comment.user_id),
|
2020-01-11 05:20:19 +01:00
|
|
|
author:
|
|
|
|
if(comment.anonymous or is_nil(comment.user),
|
|
|
|
do: UserAttributionView.anonymous_name(comment),
|
|
|
|
else: comment.user.name
|
|
|
|
),
|
2020-01-01 00:25:11 +01:00
|
|
|
body: comment.body
|
2019-12-24 09:26:01 +01:00
|
|
|
}
|
|
|
|
end
|
2020-01-01 00:25:11 +01:00
|
|
|
end
|