2019-11-12 04:10:41 +01:00
|
|
|
defmodule PhilomenaWeb.CommentController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
2019-12-01 02:06:08 +01:00
|
|
|
alias Philomena.{Comments.Query, Comments.Comment, Textile.Renderer}
|
2019-11-12 04:10:41 +01:00
|
|
|
import Ecto.Query
|
|
|
|
|
2019-11-17 22:30:20 +01:00
|
|
|
def index(conn, params) do
|
2019-12-01 02:30:05 +01:00
|
|
|
cq = params["cq"] || "created_at.gte:1 week ago"
|
2019-12-01 02:06:08 +01:00
|
|
|
|
|
|
|
{:ok, query} = Query.compile(conn.assigns.current_user, cq)
|
|
|
|
|
2019-11-12 04:10:41 +01:00
|
|
|
comments =
|
|
|
|
Comment.search_records(
|
|
|
|
%{
|
|
|
|
query: %{
|
|
|
|
bool: %{
|
2019-12-01 02:06:08 +01:00
|
|
|
must: query,
|
|
|
|
must_not: [
|
|
|
|
%{terms: %{image_tag_ids: conn.assigns.current_filter.hidden_tag_ids}},
|
|
|
|
%{term: %{hidden_from_users: true}}
|
|
|
|
]
|
2019-11-12 04:10:41 +01:00
|
|
|
}
|
|
|
|
},
|
2019-12-01 02:06:08 +01:00
|
|
|
sort: %{posted_at: :desc}
|
2019-11-12 04:10:41 +01:00
|
|
|
},
|
|
|
|
conn.assigns.pagination,
|
2019-11-17 21:37:01 +01:00
|
|
|
Comment |> preload([image: [:tags], user: [awards: :badge]])
|
2019-11-12 04:10:41 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
rendered =
|
|
|
|
comments.entries
|
2019-12-01 18:11:00 +01:00
|
|
|
|> Renderer.render_collection(conn)
|
2019-11-12 04:10:41 +01:00
|
|
|
|
|
|
|
comments =
|
2019-12-01 02:06:08 +01:00
|
|
|
%{comments | entries: Enum.zip(rendered, comments.entries)}
|
2019-11-17 23:14:20 +01:00
|
|
|
|
2019-12-01 02:06:08 +01:00
|
|
|
render(conn, "index.html", comments: comments)
|
2019-11-17 23:14:20 +01:00
|
|
|
end
|
2019-11-12 04:10:41 +01:00
|
|
|
end
|