mobilizon.chapril.org-mobil.../lib/mobilizon_web/resolvers/comment.ex
Thomas Citharel 2f2c538cc9
Add Credo checks and refactor code
Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Make Logger.debug calls lazy

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Add missing @moduledocs

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Refactor according to credo

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Final fixes and add credo to CI

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Closes #52
2019-01-03 15:52:48 +01:00

29 lines
803 B
Elixir

defmodule MobilizonWeb.Resolvers.Comment do
@moduledoc """
Handles the comment-related GraphQL calls
"""
require Logger
alias Mobilizon.Events.Comment
alias Mobilizon.Activity
alias Mobilizon.Actors.User
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