2019-12-24 09:26:01 +01:00
|
|
|
defmodule PhilomenaWeb.PostJson do
|
|
|
|
alias PhilomenaWeb.UserAttributionView
|
|
|
|
|
2020-01-02 23:47:12 +01:00
|
|
|
def as_json(%{topic: %{hidden_from_users: true}} = post) do
|
|
|
|
%{
|
|
|
|
id: post.id,
|
|
|
|
user_id: nil,
|
|
|
|
author: nil,
|
|
|
|
body: nil
|
|
|
|
}
|
|
|
|
end
|
2020-01-11 05:20:19 +01:00
|
|
|
|
2020-01-02 23:47:12 +01:00
|
|
|
def as_json(%{hidden_from_users: true} = post) do
|
|
|
|
%{
|
|
|
|
id: post.id,
|
|
|
|
user_id: if(not post.anonymous, do: post.user_id),
|
2020-01-11 05:20:19 +01:00
|
|
|
author:
|
|
|
|
if(post.anonymous or is_nil(post.user),
|
|
|
|
do: UserAttributionView.anonymous_name(post),
|
|
|
|
else: post.user.name
|
|
|
|
),
|
2020-01-02 23:47:12 +01:00
|
|
|
body: nil
|
|
|
|
}
|
|
|
|
end
|
2020-01-11 05:20:19 +01:00
|
|
|
|
2019-12-24 09:26:01 +01:00
|
|
|
def as_json(post) do
|
|
|
|
%{
|
|
|
|
id: post.id,
|
|
|
|
user_id: if(not post.anonymous, do: post.user_id),
|
2020-01-11 05:20:19 +01:00
|
|
|
author:
|
|
|
|
if(post.anonymous or is_nil(post.user),
|
|
|
|
do: UserAttributionView.anonymous_name(post),
|
|
|
|
else: post.user.name
|
|
|
|
),
|
2020-01-02 23:47:12 +01:00
|
|
|
body: post.body
|
2019-12-24 09:26:01 +01:00
|
|
|
}
|
|
|
|
end
|
2020-01-02 23:47:12 +01:00
|
|
|
end
|