FIX: Switch post handling to DiscourseEvent (#51)

FIX: Switch post handling to DiscourseEvent (#51)

diff --git a/plugin.rb b/plugin.rb
index 8813f6d..f26c24e 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -291,17 +291,12 @@ after_initialize do
     SQL
   end
 
-  NewPostManager.add_handler do |manager|
-    result = manager.perform_create_post
-
-    if result.success?
-      post = result.post
-      handler = CategoryExperts::PostHandler.new(post: post, user: manager.user)
-      handler.process_new_post
-      handler.mark_topic_as_question if manager.args[:is_category_expert_question] && post.is_first_post?
+  on(:post_created) do |post, opts, user|
+    handler = CategoryExperts::PostHandler.new(post: post, user: user)
+    handler.process_new_post
+    if opts[:is_category_expert_question].to_s == "true" && post.is_first_post?
+      handler.mark_topic_as_question
     end
-
-    result
   end
 
   add_to_class(:group, :category_expert_category_ids) do
diff --git a/spec/requests/category_experts_controller_spec.rb b/spec/requests/category_experts_controller_spec.rb
index 6046b98..25adc9f 100644
--- a/spec/requests/category_experts_controller_spec.rb
+++ b/spec/requests/category_experts_controller_spec.rb
@@ -322,6 +322,8 @@ describe CategoryExpertsController do
 
       it "returns the expert group name when the post can be approved" do
         post = create_post(topic_id: topic.id, user: user)
+        post.custom_fields.delete(CategoryExperts::POST_APPROVED_GROUP_NAME)
+        post.save
 
         get "/category-experts/retroactive-approval/#{post.id}.json"
 

GitHub sha: 9e81dcbca477a68ff0389fa44de18a8e5873e81a

This commit appears in #51 which was approved by pmusaraj. It was merged by markvanlan.