Fix plugin's compatibility with older discourse versions.

Fix plugin’s compatibility with older discourse versions.

Follow-up to d469260bf99d1d2f29cd32d3904f8c663e102ed0

diff --git a/plugin.rb b/plugin.rb
index 2eddd23..e9b0765 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -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
 

GitHub sha: 14a76498405d3ef39e6e7abe89a19067650fd4cc

This commit appears in #144 which was approved by martin. It was merged by tgxworld.