mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
35 lines
862 B
Elixir
35 lines
862 B
Elixir
defmodule PhilomenaWeb.CommentController do
|
|
use PhilomenaWeb, :controller
|
|
|
|
alias Philomena.{Images.Image, Comments.Comment, Textile.Renderer}
|
|
alias Philomena.Repo
|
|
import Ecto.Query
|
|
|
|
def index(conn, _params) do
|
|
comments =
|
|
Comment.search_records(
|
|
%{
|
|
query: %{
|
|
bool: %{
|
|
must: [
|
|
%{range: %{posted_at: %{gt: "now-1w"}}},
|
|
%{term: %{hidden_from_users: false}}
|
|
]
|
|
}
|
|
},
|
|
sort: %{posted_at: :desc}
|
|
},
|
|
conn.assigns.pagination,
|
|
Comment |> preload([:image, user: [awards: :badge]])
|
|
)
|
|
|
|
rendered =
|
|
comments.entries
|
|
|> Renderer.render_collection()
|
|
|
|
comments =
|
|
%{comments | entries: Enum.zip(comments.entries, rendered)}
|
|
|
|
render(conn, "index.html", comments: comments)
|
|
end
|
|
end
|