Module: Decidim::Comments
- Defined in:
- lib/decidim/comments.rb,
lib/decidim/comments/engine.rb,
app/models/decidim/comments/seed.rb,
app/models/decidim/comments/comment.rb,
lib/decidim/comments/query_extensions.rb,
app/forms/decidim/comments/comment_form.rb,
app/types/decidim/comments/comment_type.rb,
app/models/decidim/comments/comment_vote.rb,
lib/decidim/comments/mutation_extensions.rb,
app/commands/decidim/comments/vote_comment.rb,
app/types/decidim/comments/add_comment_type.rb,
app/commands/decidim/comments/create_comment.rb,
app/helpers/decidim/comments/comments_helper.rb,
app/models/decidim/comments/application_record.rb,
app/types/decidim/comments/comment_mutation_type.rb,
app/queries/decidim/comments/comments_with_replies.rb,
app/resolvers/decidim/comments/vote_comment_resolver.rb
Overview
This module contains all the logic related to the comments feature. It exposes a single entry point as a rails helper method to render a React component which handle all the comments render and logic.
Defined Under Namespace
Modules: CommentsHelper, MutationExtensions, QueryExtensions Classes: ApplicationRecord, Comment, CommentForm, CommentVote, CommentsWithReplies, CreateComment, Engine, Seed, VoteComment, VoteCommentResolver
Constant Summary collapse
- CommentType =
This type represents a comment on a commentable object.
GraphQL::ObjectType.define do name "Comment" description "A comment" field :id, !types.ID, "The Comment's unique ID" field :body, !types.String, "The comment message" field :createdAt, !types.String, "The creation date of the comment" do resolve lambda { |obj, _args, _ctx| obj.created_at.iso8601 } end field :author, !Decidim::Api::AuthorInterface, "The comment's author" do resolve lambda { |obj, _args, _ctx| obj.user_group || obj. } end field :replies, !types[CommentType], "The comment's replies" do resolve lambda { |obj, _args, _ctx| obj.replies.sort_by(&:created_at) } end field :hasReplies, !types.Boolean, "Check if the comment has replies" do resolve lambda { |obj, _args, _ctx| obj.replies.size.positive? } end field :canHaveReplies, !types.Boolean, "Define if a comment can or not have replies" do property :can_have_replies? end field :alignment, types.Int, "The comment's alignment. Can be 0 (neutral), 1 (in favor) or -1 (against)'" field :upVotes, !types.Int, "The number of comment's upVotes" do resolve lambda { |obj, _args, _ctx| obj.up_votes.size } end field :upVoted, !types.Boolean, "Check if the current user has upvoted the comment" do resolve lambda { |obj, _args, ctx| obj.up_voted_by?(ctx[:current_user]) } end field :downVotes, !types.Int, "The number of comment's downVotes" do resolve lambda { |obj, _args, _ctx| obj.down_votes.size } end field :downVoted, !types.Boolean, "Check if the current user has downvoted the comment" do resolve lambda { |obj, _args, ctx| obj.down_voted_by?(ctx[:current_user]) } end end
- AddCommentType =
This type represents a mutation to create new comments.
GraphQL::ObjectType.define do name "Add comment" description "Add a new comment" field :comment, CommentType, "The new created comment" end
- CommentMutationType =
GraphQL::ObjectType.define do name "CommentMutation" description "A comment which includes its available mutations" field :id, !types.ID, "The Comment's unique ID" field :upVote, Decidim::Comments::CommentType do resolve VoteCommentResolver.new(weight: 1) end field :downVote, Decidim::Comments::CommentType do resolve VoteCommentResolver.new(weight: -1) end end