2020-07-09 17:24:28 +02:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.Discussions.CommentType do
|
2019-01-14 17:48:08 +01:00
|
|
|
@moduledoc """
|
|
|
|
Schema representation for Comment
|
|
|
|
"""
|
2019-01-14 17:13:17 +01:00
|
|
|
use Absinthe.Schema.Notation
|
2020-01-26 20:34:25 +01:00
|
|
|
|
2024-01-05 18:15:08 +01:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1, dataloader: 2]
|
2019-01-14 17:13:17 +01:00
|
|
|
|
2021-04-28 11:59:15 +02:00
|
|
|
alias Mobilizon.{Actors, Discussions, Events}
|
2020-01-26 20:34:25 +01:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.Comment
|
|
|
|
|
2019-01-14 17:13:17 +01:00
|
|
|
@desc "A comment"
|
|
|
|
object :comment do
|
2023-03-17 18:10:59 +01:00
|
|
|
meta(:authorize, :all)
|
2021-03-10 17:38:13 +01:00
|
|
|
interfaces([:action_log_object, :activity_object])
|
2019-01-21 15:08:22 +01:00
|
|
|
field(:id, :id, description: "Internal ID for this comment")
|
2020-11-19 17:06:28 +01:00
|
|
|
field(:uuid, :uuid, description: "An UUID for this comment")
|
|
|
|
field(:url, :string, description: "Comment URL")
|
|
|
|
field(:local, :boolean, description: "Whether this comment is local or not")
|
|
|
|
field(:visibility, :comment_visibility, description: "The visibility for the comment")
|
|
|
|
field(:text, :string, description: "The comment body")
|
|
|
|
field(:primaryLanguage, :string, description: "The comment's primary language")
|
2019-11-15 18:36:47 +01:00
|
|
|
|
|
|
|
field(:replies, list_of(:comment)) do
|
2020-11-19 17:06:28 +01:00
|
|
|
description("A list of replies to the comment")
|
2024-01-05 18:15:08 +01:00
|
|
|
resolve(dataloader(Discussions, args: %{replies: true}))
|
2019-11-15 18:36:47 +01:00
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
field(:total_replies, :integer,
|
|
|
|
description: "The number of total known replies to this comment"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:in_reply_to_comment, :comment,
|
|
|
|
resolve: dataloader(Discussions),
|
|
|
|
description: "The comment this comment directly replies to"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:event, :event,
|
|
|
|
resolve: dataloader(Events),
|
|
|
|
description: "The eventual event this comment is under"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:origin_comment, :comment,
|
|
|
|
resolve: dataloader(Discussions),
|
|
|
|
description: "The original comment that started the thread this comment is in"
|
|
|
|
)
|
|
|
|
|
|
|
|
field(:threadLanguages, non_null(list_of(:string)), description: "The thread languages")
|
|
|
|
field(:actor, :person, resolve: dataloader(Actors), description: "The comment's author")
|
2024-01-05 17:51:41 +01:00
|
|
|
|
|
|
|
field(:attributed_to, :actor,
|
|
|
|
resolve: dataloader(Actors),
|
|
|
|
description: "The comment's attributed to actor"
|
|
|
|
)
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
field(:inserted_at, :datetime, description: "When was the comment inserted in database")
|
|
|
|
field(:updated_at, :datetime, description: "When was the comment updated")
|
|
|
|
field(:deleted_at, :datetime, description: "When was the comment deleted")
|
|
|
|
field(:published_at, :datetime, description: "When was the comment published")
|
2021-06-01 18:08:03 +02:00
|
|
|
|
|
|
|
field(:is_announcement, non_null(:boolean),
|
|
|
|
description: "Whether this comment needs to be announced to participants"
|
|
|
|
)
|
2021-08-19 20:43:35 +02:00
|
|
|
|
2023-10-17 16:41:31 +02:00
|
|
|
field(:conversation, :conversation, description: "The conversation this comment is part of")
|
|
|
|
|
2021-11-23 09:36:19 +01:00
|
|
|
field(:language, :string, description: "The comment language")
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|
2019-01-14 17:48:08 +01:00
|
|
|
|
|
|
|
@desc "The list of visibility options for a comment"
|
|
|
|
enum :comment_visibility do
|
2019-09-16 15:11:43 +02:00
|
|
|
value(:public, description: "Publicly listed and federated. Can be shared.")
|
2019-01-14 17:48:08 +01:00
|
|
|
value(:unlisted, description: "Visible only to people with the link - or invited")
|
|
|
|
|
|
|
|
value(:private,
|
|
|
|
description: "Visible only to people members of the group or followers of the person"
|
|
|
|
)
|
|
|
|
|
|
|
|
value(:moderated, description: "Visible only after a moderator accepted")
|
|
|
|
value(:invite, description: "visible only to people invited")
|
|
|
|
end
|
2019-01-25 15:41:10 +01:00
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc "A paginated list of comments"
|
2020-02-18 08:57:00 +01:00
|
|
|
object :paginated_comment_list do
|
2023-03-17 18:10:59 +01:00
|
|
|
meta(:authorize, :all)
|
2020-02-18 08:57:00 +01:00
|
|
|
field(:elements, list_of(:comment), description: "A list of comments")
|
|
|
|
field(:total, :integer, description: "The total number of comments in the list")
|
|
|
|
end
|
|
|
|
|
2019-11-15 18:36:47 +01:00
|
|
|
object :comment_queries do
|
|
|
|
@desc "Get replies for thread"
|
|
|
|
field :thread, type: list_of(:comment) do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:id, non_null(:id), description: "The comment ID")
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization, permit: :all)
|
2019-11-15 18:36:47 +01:00
|
|
|
resolve(&Comment.get_thread/3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-25 15:41:10 +01:00
|
|
|
object :comment_mutations do
|
|
|
|
@desc "Create a comment"
|
|
|
|
field :create_comment, type: :comment do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:text, non_null(:string), description: "The comment's body")
|
|
|
|
arg(:event_id, non_null(:id), description: "The event under which this comment is")
|
|
|
|
arg(:in_reply_to_comment_id, :id, description: "The comment ID this one replies to")
|
2021-08-19 20:43:35 +02:00
|
|
|
arg(:language, :string, description: "The comment language", default_value: "und")
|
2019-01-25 15:41:10 +01:00
|
|
|
|
2023-08-17 13:18:01 +02:00
|
|
|
arg(:is_announcement, :boolean,
|
|
|
|
description: "Should this comment be announced to everyone?"
|
|
|
|
)
|
2021-06-01 18:08:03 +02:00
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Discussions.Comment,
|
|
|
|
rule: :"write:comment:create",
|
|
|
|
args: %{event_id: :event_id}
|
|
|
|
)
|
|
|
|
|
2019-01-25 15:41:10 +01:00
|
|
|
resolve(&Comment.create_comment/3)
|
|
|
|
end
|
2019-11-15 18:36:47 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@desc "Update a comment"
|
|
|
|
field :update_comment, type: :comment do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:text, non_null(:string), description: "The comment updated body")
|
|
|
|
arg(:comment_id, non_null(:id), description: "The comment ID")
|
2021-08-19 20:43:35 +02:00
|
|
|
arg(:language, :string, description: "The comment language", default_value: "und")
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2023-08-17 13:18:01 +02:00
|
|
|
arg(:is_announcement, :boolean,
|
|
|
|
description: "Should this comment be announced to everyone?"
|
|
|
|
)
|
2021-06-01 18:08:03 +02:00
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: :user,
|
|
|
|
scope: Mobilizon.Discussions.Comment,
|
|
|
|
rule: :"write:comment:update",
|
|
|
|
args: %{id: :comment_id}
|
|
|
|
)
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
resolve(&Comment.update_comment/3)
|
|
|
|
end
|
|
|
|
|
2020-08-14 11:32:23 +02:00
|
|
|
@desc "Delete a single comment"
|
2019-11-15 18:36:47 +01:00
|
|
|
field :delete_comment, type: :comment do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:comment_id, non_null(:id), description: "The comment ID")
|
2019-11-15 18:36:47 +01:00
|
|
|
|
2023-03-17 18:10:59 +01:00
|
|
|
middleware(Rajska.QueryAuthorization,
|
|
|
|
permit: [:user, :moderator],
|
|
|
|
scope: Mobilizon.Discussions.Comment,
|
|
|
|
rule: :"write:comment:delete",
|
|
|
|
args: %{id: :comment_id}
|
|
|
|
)
|
|
|
|
|
2019-11-15 18:36:47 +01:00
|
|
|
resolve(&Comment.delete_comment/3)
|
|
|
|
end
|
2019-01-25 15:41:10 +01:00
|
|
|
end
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|