Class: Decidim::Comments::CommentType

Inherits:
Api::Types::BaseObject show all
Defined in:
decidim-comments/lib/decidim/api/comment_type.rb

Overview

This type represents a comment on a commentable object.

Instance Method Summary collapse

Instance Method Details

#already_reportedObject


80
81
82
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 80

def already_reported
  object.reported_by?(context[:current_user])
end

#authorObject


40
41
42
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 40

def author
  object.user_group || object.author
end

#bodyObject


48
49
50
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 48

def body
  object.translated_body
end

#created_atObject


52
53
54
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 52

def created_at
  object.created_at.iso8601
end

#down_votedObject


72
73
74
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 72

def down_voted
  object.down_voted_by?(context[:current_user])
end

#down_votesObject


68
69
70
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 68

def down_votes
  object.down_votes.size
end

#formatted_created_atObject


56
57
58
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 56

def formatted_created_at
  object.friendly_created_at
end

#has_comments?Boolean

Returns:

  • (Boolean)

76
77
78
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 76

def has_comments?
  object.comment_threads.size.positive?
end

#sgidObject


44
45
46
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 44

def sgid
  object.to_sgid.to_s
end

#up_votedObject


64
65
66
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 64

def up_voted
  object.up_voted_by?(context[:current_user])
end

#up_votesObject


60
61
62
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 60

def up_votes
  object.up_votes.size
end

#user_allowed_to_commentObject


84
85
86
# File 'decidim-comments/lib/decidim/api/comment_type.rb', line 84

def user_allowed_to_comment
  object.root_commentable.commentable? && object.root_commentable.user_allowed_to_comment?(context[:current_user])
end