Module: Decidim::Comments

Defined in:
lib/decidim/comments.rb,
lib/decidim/comments/admin.rb,
lib/decidim/comments/engine.rb,
lib/decidim/comments/export.rb,
lib/decidim/comments/version.rb,
app/models/decidim/comments/seed.rb,
lib/decidim/comments/commentable.rb,
lib/decidim/comments/admin_engine.rb,
app/models/decidim/comments/comment.rb,
lib/decidim/comments/comments_helper.rb,
lib/decidim/comments/api/comment_type.rb,
lib/decidim/comments/query_extensions.rb,
app/forms/decidim/comments/comment_form.rb,
lib/decidim/comments/comment_serializer.rb,
app/models/decidim/comments/comment_vote.rb,
lib/decidim/comments/mutation_extensions.rb,
lib/decidim/comments/api/add_comment_type.rb,
app/commands/decidim/comments/vote_comment.rb,
app/types/decidim/comments/commentable_type.rb,
app/commands/decidim/comments/create_comment.rb,
app/queries/decidim/comments/sorted_comments.rb,
lib/decidim/comments/comment_vote_serializer.rb,
app/models/decidim/comments/application_record.rb,
app/services/decidim/comments/comment_creation.rb,
lib/decidim/comments/api/comment_mutation_type.rb,
app/events/decidim/comments/reply_created_event.rb,
app/cells/decidim/comments/comment_activity_cell.rb,
app/events/decidim/comments/user_mentioned_event.rb,
app/types/decidim/comments/commentable_interface.rb,
app/events/decidim/comments/comment_created_event.rb,
app/resolvers/decidim/comments/vote_comment_resolver.rb,
app/types/decidim/comments/commentable_mutation_type.rb,
app/events/decidim/comments/comment_by_followed_user_event.rb,
app/queries/decidim/comments/metrics/comments_metric_manage.rb,
app/services/decidim/comments/new_comment_notification_creator.rb,
app/queries/decidim/comments/metrics/comment_participants_metric_measure.rb

Overview

This holds the decidim-comments version.

Defined Under Namespace

Modules: Admin, Commentable, CommentsHelper, Export, Metrics, MutationExtensions, QueryExtensions Classes: AdminEngine, ApplicationRecord, Comment, CommentActivityCell, CommentByFollowedUserEvent, CommentCreatedEvent, CommentCreation, CommentForm, CommentSerializer, CommentVote, CommentVoteSerializer, CreateComment, Engine, NewCommentNotificationCreator, ReplyCreatedEvent, Seed, SortedComments, UserMentionedEvent, VoteComment, VoteCommentResolver

Constant Summary collapse

CommentType =

This type represents a comment on a commentable object.

GraphQL::ObjectType.define do
  name "Comment"
  description "A comment"

  interfaces [
    -> { Decidim::Comments::CommentableInterface }
  ]

  field :author, !Decidim::Core::AuthorInterface, "The resource author" do
    resolve lambda { |obj, _args, _ctx|
      obj.user_group || obj.author
    }
  end

  field :id, !types.ID, "The Comment's unique ID"

  field :sgid, !types.String, "The Comment's signed global id" do
    resolve lambda { |obj, _args, _ctx|
      obj.to_sgid.to_s
    }
  end

  field :body, !types.String, "The comment message"

  field :formattedBody, !types.String, "The comment message ready to display (it is expected to include HTML)", property: :formatted_body

  field :createdAt, !types.String, "The creation date of the comment" do
    resolve lambda { |obj, _args, _ctx|
      obj.created_at.iso8601
    }
  end

  field :formattedCreatedAt, !types.String, "The creation date of the comment in relative format", property: :friendly_created_at

  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

  field :hasComments, !types.Boolean, "Check if the commentable has comments" do
    resolve lambda { |obj, _args, _ctx|
      obj.comment_threads.size.positive?
    }
  end

  field :alreadyReported, !types.Boolean, "Check if the current user has reported the comment" do
    resolve lambda { |obj, _args, ctx|
      obj.reported_by?(ctx[:current_user])
    }
  end

  field :userAllowedToComment, !types.Boolean, "Check if the current user can comment" do
    resolve lambda { |obj, _args, ctx|
      obj.root_commentable.commentable? && obj.root_commentable.user_allowed_to_comment?(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
CommentableType =

This type represents a commentable object.

GraphQL::ObjectType.define do
  name "Commentable"
  description "A commentable object"

  interfaces [
    -> { Decidim::Comments::CommentableInterface }
  ]
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
CommentableInterface =

This interface represents a commentable object.

GraphQL::InterfaceType.define do
  name "CommentableInterface"
  description "A commentable interface"

  field :id, !types.ID, "The commentable's ID"

  field :type, !types.String, "The commentable's class name. i.e. `Decidim::ParticipatoryProcess`" do
    property :commentable_type
  end

  field :acceptsNewComments, !types.Boolean, "Whether the object can have new comments or not" do
    property :accepts_new_comments?
  end

  field :commentsHaveAlignment, !types.Boolean, "Whether the object comments have alignment or not" do
    property :comments_have_alignment?
  end

  field :commentsHaveVotes, !types.Boolean, "Whether the object comments have votes or not" do
    property :comments_have_votes?
  end

  field :comments do
    type !types[!CommentType]

    argument :orderBy, types.String, "Order the comments"

    resolve lambda { |obj, args, _ctx|
      SortedComments.for(obj, order_by: args[:orderBy])
    }
  end

  field :totalCommentsCount do
    type !types.Int
    description "The number of comments in all levels this resource holds"

    resolve lambda { |obj, _args, _ctx|
      obj.comments.count
    }
  end

  field :hasComments, !types.Boolean, "Check if the commentable has comments" do
    resolve lambda { |obj, _args, _ctx|
      obj.comment_threads.size.positive?
    }
  end

  field :userAllowedToComment, !types.Boolean, "Check if the current user can comment" do
    resolve lambda { |obj, _args, ctx|
      obj.commentable? && obj.user_allowed_to_comment?(ctx[:current_user])
    }
  end
end
CommentableMutationType =
GraphQL::ObjectType.define do
  name "CommentableMutation"
  description "A commentable which includes its available mutations"

  field :id, !types.ID, "The Commentable's unique ID"

  field :addComment, Decidim::Comments::CommentType do
    description "Add a new comment to a commentable"

    argument :body, !types.String, "The comments's body"
    argument :alignment, types.Int, "The comment's alignment. Can be 0 (neutral), 1 (in favor) or -1 (against)'", default_value: 0
    argument :userGroupId, types.ID, "The comment's user group id. Replaces the author."

    resolve lambda { |obj, args, ctx|
      params = { "comment" => { "body" => args[:body], "alignment" => args[:alignment], "user_group_id" => args[:userGroupId] } }
      form = Decidim::Comments::CommentForm.from_params(params).with_context(current_organization: ctx[:current_organization])
      Decidim::Comments::CreateComment.call(form, ctx[:current_user], obj) do
        on(:ok) do |comment|
          return comment
        end
      end
    }
  end
end

Class Method Summary collapse

Class Method Details

.data_portable_entitiesObject



21
22
23
# File 'lib/decidim/comments.rb', line 21

def self.data_portable_entities
  ["Decidim::Comments::Comment", "Decidim::Comments::CommentVote"]
end

.newsletter_participant_entitiesObject



25
26
27
# File 'lib/decidim/comments.rb', line 25

def self.newsletter_participant_entities
  ["Decidim::Comments::Comment"]
end

.versionObject



6
7
8
# File 'lib/decidim/comments/version.rb', line 6

def self.version
  "0.18.1"
end