discourse-topic-voting/lib/discourse_topic_voting/user_extension.rb
Natalie Tay 3d3037729c
DEV: Scope topic voting tables to avoid confusion with post voting (#196)
Renaming discourse_voting to topic_voting since there are two forms of voting in Discourse - posts and topics.

This PR also moves a OnceOff into a post migration. The post migration will be executed, but should ideally be a no-op. This allows us to not have to maintain the OnceOff as it had to be modified before with a previous migration. I considered removing this file altogether, but I don't think there is anything negative from just converting it into a migration, and it might be useful in the unlikely scenario that a forum from the past has never ran the OnceOff before.
2024-07-17 20:26:40 +08:00

33 lines
724 B
Ruby

# 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?
(vote_limit - vote_count) <= SiteSetting.topic_voting_alert_votes_left
end
def topics_with_vote
self.votes.where(archive: false)
end
def topics_with_archived_vote
self.votes.where(archive: true)
end
def reached_voting_limit?
vote_count >= vote_limit
end
def vote_limit
SiteSetting.public_send("topic_voting_tl#{self.trust_level}_vote_limit")
end
end
end