Fix plugin's compatibility with older discourse versions.

Follow-up to d469260bf9
This commit is contained in:
Alan Guo Xiang Tan 2021-06-17 09:10:02 +08:00
parent f5cb5a2ac2
commit 14a7649840
1 changed files with 5 additions and 3 deletions

View File

@ -196,9 +196,11 @@ after_initialize do
end
# TODO: Switch to an official plugin API once support for it has landed.
TopicView.on_preload do |topic_view|
if SiteSetting.discourse_post_event_enabled
topic_view.instance_variable_set(:@posts, topic_view.posts.includes(:event))
if TopicView.respond_to?(:on_preload)
TopicView.on_preload do |topic_view|
if SiteSetting.discourse_post_event_enabled
topic_view.instance_variable_set(:@posts, topic_view.posts.includes(:event))
end
end
end