2018-12-14 16:41:55 +00:00
|
|
|
defmodule MobilizonWeb.Resolvers.Comment do
|
2019-01-03 13:59:59 +00:00
|
|
|
@moduledoc """
|
|
|
|
Handles the comment-related GraphQL calls
|
|
|
|
"""
|
2018-12-14 16:41:55 +00:00
|
|
|
require Logger
|
|
|
|
alias Mobilizon.Events.Comment
|
|
|
|
alias Mobilizon.Activity
|
2019-03-05 16:23:05 +00:00
|
|
|
alias Mobilizon.Users.User
|
2018-12-14 16:41:55 +00:00
|
|
|
alias MobilizonWeb.API.Comments
|
|
|
|
|
|
|
|
def create_comment(_parent, %{text: comment, actor_username: username}, %{
|
|
|
|
context: %{current_user: %User{} = _user}
|
|
|
|
}) do
|
|
|
|
with {:ok, %Activity{data: %{"object" => %{"type" => "Note"} = object}}} <-
|
|
|
|
Comments.create_comment(username, comment) do
|
|
|
|
{:ok,
|
|
|
|
%Comment{
|
|
|
|
text: object["content"],
|
|
|
|
url: object["id"],
|
|
|
|
uuid: object["uuid"]
|
|
|
|
}}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_comment(_parent, _args, %{}) do
|
|
|
|
{:error, "You are not allowed to create a comment if not connected"}
|
|
|
|
end
|
|
|
|
end
|