@@ -125,13 +125,6 @@ defmodule Mobilizon.Discussions do
|
||||
@spec get_comment_from_url(String.t()) :: Comment.t() | nil
|
||||
def get_comment_from_url(url), do: Repo.get_by(Comment, url: url)
|
||||
|
||||
@doc """
|
||||
Gets a comment by its URL.
|
||||
Raises `Ecto.NoResultsError` if the comment does not exist.
|
||||
"""
|
||||
@spec get_comment_from_url!(String.t()) :: Comment.t()
|
||||
def get_comment_from_url!(url), do: Repo.get_by!(Comment, url: url)
|
||||
|
||||
@doc """
|
||||
Gets a comment by its URL, with all associations loaded.
|
||||
"""
|
||||
@@ -175,19 +168,6 @@ defmodule Mobilizon.Discussions do
|
||||
|> Repo.preload(@comment_preloads)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get all comment threads under an event
|
||||
"""
|
||||
@spec get_threads(String.t() | integer()) :: [Comment.t()]
|
||||
def get_threads(event_id) do
|
||||
Comment
|
||||
|> where([c, _], c.event_id == ^event_id and is_nil(c.origin_comment_id))
|
||||
|> join(:left, [c], r in Comment, on: r.origin_comment_id == c.id)
|
||||
|> group_by([c], c.id)
|
||||
|> select([c, r], %{c | total_replies: count(r.id)})
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets paginated replies for root comment
|
||||
"""
|
||||
@@ -198,17 +178,6 @@ defmodule Mobilizon.Discussions do
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get a comment or create it
|
||||
"""
|
||||
@spec get_or_create_comment(map()) :: {:ok, Comment.t()}
|
||||
def get_or_create_comment(%{"url" => url} = attrs) do
|
||||
case Repo.get_by(Comment, url: url) do
|
||||
%Comment{} = comment -> {:ok, Repo.preload(comment, @comment_preloads)}
|
||||
nil -> create_comment(attrs)
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a comment.
|
||||
"""
|
||||
@@ -253,14 +222,6 @@ defmodule Mobilizon.Discussions do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of public comments.
|
||||
"""
|
||||
@spec list_comments :: [Comment.t()]
|
||||
def list_comments do
|
||||
Repo.all(from(c in Comment, where: c.visibility == ^:public))
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns a paginated list of local comments
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user