0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/plugins/discourse-topic-voting/lib/discourse_topic_voting/user_extension.rb
Jarek Radosz 8baf4d5d4c
DEV: Enable Style/RedundantSelf rubocop rule (#40098)
(to be enabled in the shared config)
2026-05-19 19:27:45 +02:00

50 lines
1.2 KiB
Ruby
Vendored

# frozen_string_literal: true
module DiscourseTopicVoting
module UserExtension
extend ActiveSupport::Concern
prepended { has_many :votes, class_name: "DiscourseTopicVoting::Vote", dependent: :destroy }
def vote_count
topics_with_vote.length
end
def alert_low_votes?
return false unless SiteSetting.topic_voting_enable_vote_limits
(vote_limit - vote_count) <= SiteSetting.topic_voting_alert_votes_left
end
def topics_with_vote
votes.where(archive: false)
end
def topics_with_archived_vote
votes.where(archive: true)
end
def can_vote?
!reached_voting_limit?
end
def reached_voting_limit?
return false unless SiteSetting.topic_voting_enable_vote_limits
vote_count >= vote_limit
end
def vote_limit
return nil unless SiteSetting.topic_voting_enable_vote_limits
SiteSetting.public_send("topic_voting_tl#{trust_level}_vote_limit")
end
def votes_left
return nil unless SiteSetting.topic_voting_enable_vote_limits
[vote_limit - vote_count, 0].max
end
def vote_limit_0?
return false unless SiteSetting.topic_voting_enable_vote_limits
vote_limit == 0
end
end
end