2019-12-24 09:26:01 +01:00
|
|
|
defmodule PhilomenaWeb.CommentJson do
|
|
|
|
alias PhilomenaWeb.UserAttributionView
|
|
|
|
|
2020-01-01 00:25:11 +01:00
|
|
|
def as_json(%{destroyed_content: true}) do
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_json(%{image: %{hidden_from_users: true}} = comment) do
|
|
|
|
%{
|
|
|
|
id: comment.id,
|
|
|
|
image_id: comment.image_id,
|
|
|
|
user_id: nil,
|
|
|
|
author: nil,
|
|
|
|
body: nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_json(%{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
|
|
|
|
|
2019-12-24 09:26:01 +01:00
|
|
|
def as_json(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),
|
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
|