Class: Decidim::Debates::Debate

Inherits:
ApplicationRecord show all
Includes:
Authorable, Comments::Commentable, Followable, HasCategory, HasComponent, HasReference, Loggable, Reportable, Resourceable, ScopableComponent, Traceable
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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



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

def self.log_presenter_class_for(_log)
  Decidim::Debates::AdminLog::DebatePresenter
end

Instance Method Details

#accepts_new_comments?Boolean

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

Returns:

  • (Boolean)


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

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)


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

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

#commentable?Boolean

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

Returns:

  • (Boolean)


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

def commentable?
  component.settings.comments_enabled?
end

#commentable_typeObject

Public: Identifies the commentable type in the API.



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

def commentable_type
  self.class.name
end

#comments_have_alignment?Boolean

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

Returns:

  • (Boolean)


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

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

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

Returns:

  • (Boolean)


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

def comments_have_votes?
  true
end

#notifiable?(_context) ⇒ Boolean

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

Returns:

  • (Boolean)


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

def notifiable?(_context)
  false
end

#official?Boolean

Public: Checks whether the debate is official or not.

Returns a boolean.

Returns:

  • (Boolean)


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

def official?
  author.blank?
end

#open?Boolean

Public: Checks if the debate is open or not.

Returns a boolean.

Returns:

  • (Boolean)


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

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)


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

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

#reported_content_urlObject

Public: Overrides the ‘reported_content_url` Reportable concern method.



37
38
39
# File 'app/models/decidim/debates/debate.rb', line 37

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`



97
98
99
100
# File 'app/models/decidim/debates/debate.rb', line 97

def users_to_notify_on_comment_created
  return Decidim::User.where(id: followers).or(Decidim::User.where(id: component.participatory_space.admins)).distinct if official?
  followers
end