mobilizon.chapril.org-mobil.../lib/mobilizon_web/resolvers/comment.ex

27 lines
713 B
Elixir
Raw Normal View History

defmodule MobilizonWeb.Resolvers.Comment do
@moduledoc """
Handles the comment-related GraphQL calls
"""
2019-09-13 01:35:03 +02:00
alias Mobilizon.Events.{Activity, Comment}
alias Mobilizon.Users.User
2019-09-13 01:35:03 +02:00
alias MobilizonWeb.API.Comments
2019-09-13 01:35:03 +02:00
require Logger
def create_comment(_parent, %{text: comment, actor_username: username}, %{
context: %{current_user: %User{} = _user}
}) do
with {:ok, %Activity{data: %{"object" => %{"type" => "Note"} = _object}},
%Comment{} = comment} <-
Comments.create_comment(username, comment) do
{:ok, comment}
end
end
def create_comment(_parent, _args, %{}) do
{:error, "You are not allowed to create a comment if not connected"}
end
end