Class: Decidim::Debates::Debate

Inherits:
ApplicationRecord show all
Includes:
Authorable, Comments::Commentable, Followable, HasCategory, HasFeature, HasReference, HasScope, Reportable, Resourceable
Defined in:
app/models/decidim/debates/debate.rb

Overview

The data store for a Debate in the Decidim::Debates component. It stores a title, description and any other useful information to render a custom debate.

Instance Method Summary collapse

Instance Method Details

#accepts_new_comments?Boolean

Public: Overrides the ‘accepts_new_comments?` Commentable concern method.

Returns:

  • (Boolean)


65
66
67
68
# File 'app/models/decidim/debates/debate.rb', line 65

def accepts_new_comments?
  return false unless open?
  commentable? && !comments_blocked?
end

#ama?Boolean

Public: Calculates whether the current debate is an AMA-styled one or not. AMA-styled debates are those that have a start and end time set, and comments are only open during that timelapse. AMA stands for Ask Me Anything, a type of debate inspired by Reddit.

Returns a Boolean.

Returns:

  • (Boolean)


41
42
43
# File 'app/models/decidim/debates/debate.rb', line 41

def ama?
  start_time.present? && end_time.present?
end

#commentable?Boolean

Public: Overrides the ‘commentable?` Commentable concern method.

Returns:

  • (Boolean)


60
61
62
# File 'app/models/decidim/debates/debate.rb', line 60

def commentable?
  feature.settings.comments_enabled?
end

#commentable_typeObject

Public: Identifies the commentable type in the API.



81
82
83
# File 'app/models/decidim/debates/debate.rb', line 81

def commentable_type
  self.class.name
end

#comments_have_alignment?Boolean

Public: Overrides the ‘comments_have_alignment?` Commentable concern method.

Returns:

  • (Boolean)


71
72
73
# File 'app/models/decidim/debates/debate.rb', line 71

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

Public: Overrides the ‘comments_have_votes?` Commentable concern method.

Returns:

  • (Boolean)


76
77
78
# File 'app/models/decidim/debates/debate.rb', line 76

def comments_have_votes?
  true
end

#notifiable?(_context) ⇒ Boolean

Public: Overrides the ‘notifiable?` Notifiable concern method.

Returns:

  • (Boolean)


86
87
88
# File 'app/models/decidim/debates/debate.rb', line 86

def notifiable?(_context)
  false
end

#official?Boolean

Public: Checks whether the debate is official or not.

Returns a boolean.

Returns:

  • (Boolean)


26
27
28
# File 'app/models/decidim/debates/debate.rb', line 26

def official?
  author.blank?
end

#open?Boolean

Public: Checks if the debate is open or not.

Returns a boolean.

Returns:

  • (Boolean)


55
56
57
# File 'app/models/decidim/debates/debate.rb', line 55

def open?
  (ama? && open_ama?) || !ama?
end

#open_ama?Boolean

Public: Checks whether the debate is an AMA-styled one and is open.

Returns a boolean.

Returns:

  • (Boolean)


48
49
50
# File 'app/models/decidim/debates/debate.rb', line 48

def open_ama?
  ama? && Time.current.between?(start_time, end_time)
end

#reported_content_urlObject

Public: Overrides the ‘reported_content_url` Reportable concern method.



31
32
33
# File 'app/models/decidim/debates/debate.rb', line 31

def reported_content_url
  ResourceLocatorPresenter.new(self).url
end

#users_to_notify_on_comment_createdObject

Public: Override Commentable concern method ‘users_to_notify_on_comment_created`



91
92
93
94
# File 'app/models/decidim/debates/debate.rb', line 91

def users_to_notify_on_comment_created
  return (followers | feature.participatory_space.admins).uniq if official?
  followers
end