FIX: Stop register_topic_list_preload_user_ids from breaking old versions (#160)
We need a proper fix, but this stops the bleeding for now. Wrapped code related to `register_topic_list_preload_user_ids` in a `respond_to?(:register_topic_list_preload_user_ids)` block because this API is not available in beta or stable versions of Discourse.
This commit is contained in:
parent
6b6d5978a2
commit
cf368c19cb
82
plugin.rb
82
plugin.rb
|
@ -695,53 +695,55 @@ SQL
|
||||||
.count
|
.count
|
||||||
end
|
end
|
||||||
|
|
||||||
class ::Topic
|
if respond_to?(:register_topic_list_preload_user_ids)
|
||||||
attr_accessor :accepted_answer_user_id
|
class ::Topic
|
||||||
end
|
attr_accessor :accepted_answer_user_id
|
||||||
|
end
|
||||||
|
|
||||||
register_topic_list_preload_user_ids do |topics, user_ids, topic_list|
|
register_topic_list_preload_user_ids do |topics, user_ids, topic_list|
|
||||||
answer_post_ids = TopicCustomField
|
answer_post_ids = TopicCustomField
|
||||||
.select('value::INTEGER')
|
.select('value::INTEGER')
|
||||||
.where(name: 'accepted_answer_post_id')
|
.where(name: 'accepted_answer_post_id')
|
||||||
.where(topic_id: topics.map(&:id))
|
.where(topic_id: topics.map(&:id))
|
||||||
answer_user_ids = Post
|
answer_user_ids = Post
|
||||||
.where(id: answer_post_ids)
|
.where(id: answer_post_ids)
|
||||||
.pluck(:topic_id, :user_id)
|
.pluck(:topic_id, :user_id)
|
||||||
.to_h
|
.to_h
|
||||||
topics.each { |topic| topic.accepted_answer_user_id = answer_user_ids[topic.id] }
|
topics.each { |topic| topic.accepted_answer_user_id = answer_user_ids[topic.id] }
|
||||||
user_ids.concat(answer_user_ids.values)
|
user_ids.concat(answer_user_ids.values)
|
||||||
end
|
end
|
||||||
|
|
||||||
module AddSolvedToTopicPostersSummary
|
module AddSolvedToTopicPostersSummary
|
||||||
def descriptions_by_id
|
def descriptions_by_id
|
||||||
if !defined? @descriptions_by_id
|
if !defined? @descriptions_by_id
|
||||||
super(ids: old_user_ids)
|
super(ids: old_user_ids)
|
||||||
|
|
||||||
if id = topic.accepted_answer_user_id
|
if id = topic.accepted_answer_user_id
|
||||||
@descriptions_by_id[id] ||= []
|
@descriptions_by_id[id] ||= []
|
||||||
@descriptions_by_id[id] << I18n.t(:accepted_answer)
|
@descriptions_by_id[id] << I18n.t(:accepted_answer)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def last_poster_is_topic_creator?
|
|
||||||
super || topic.accepted_answer_user_id == topic.last_post_user_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def user_ids
|
|
||||||
if id = topic.accepted_answer_user_id
|
|
||||||
super.insert(1, id)
|
|
||||||
else
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def last_poster_is_topic_creator?
|
||||||
|
super || topic.accepted_answer_user_id == topic.last_post_user_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_ids
|
||||||
|
if id = topic.accepted_answer_user_id
|
||||||
|
super.insert(1, id)
|
||||||
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
TopicPostersSummary.class_eval do
|
||||||
|
alias :old_user_ids :user_ids
|
||||||
|
|
||||||
|
prepend AddSolvedToTopicPostersSummary
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
TopicPostersSummary.class_eval do
|
|
||||||
alias :old_user_ids :user_ids
|
|
||||||
|
|
||||||
prepend AddSolvedToTopicPostersSummary
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue