mirror of
https://ghfast.top/https://github.com/discourse/discourse-topic-voting.git
synced 2026-07-17 11:37:03 +08:00
- Define extension modules - Use different files instead of plugin.rb - Make sure plugin is disabled according to the setting
21 lines
663 B
Ruby
21 lines
663 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseTopicVoting
|
|
module TopicQueryExtension
|
|
def list_voted_by(user)
|
|
create_list(:user_topics) do |topics|
|
|
topics.joins(
|
|
"INNER JOIN discourse_voting_votes ON discourse_voting_votes.topic_id = topics.id",
|
|
).where("discourse_voting_votes.user_id = ?", user.id)
|
|
end
|
|
end
|
|
|
|
def list_votes
|
|
create_list(:votes, unordered: true) do |topics|
|
|
topics.joins(
|
|
"LEFT JOIN discourse_voting_topic_vote_count dvtvc ON dvtvc.topic_id = topics.id",
|
|
).order("COALESCE(dvtvc.votes_count,'0')::integer DESC, topics.bumped_at DESC")
|
|
end
|
|
end
|
|
end
|
|
end
|