A platform for community discussion. Free, open, simple.
FIX: Allow triggering Discobot when bookmarking the entire topic (#27255)
Jan Cernik28fe3c339ea8
diff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rbindex fceda47e80b..76cb1e34275 100644--- a/plugins/discourse-narrative-bot/plugin.rb+++ b/plugins/discourse-narrative-bot/plugin.rb@@ -170,11 +170,15 @@ after_initialize doself.add_model_callback(Bookmark, :after_commit, on: :create) doif self.user.enqueue_narrative_bot_job?- if self.bookmarkable_type == "Post"+ if self.bookmarkable_type == "Post" || self.bookmarkable_type == "Topic"+ is_topic = self.bookmarkable_type == "Topic"+ first_post_id =+ Post.where(topic_id: self.bookmarkable_id, post_number: 1).pick(:id) if is_topic+Jobs.enqueue(:bot_input,user_id: self.user_id,- post_id: self.bookmarkable_id,+ post_id: is_topic ? first_post_id : self.bookmarkable_id,input: "bookmark",)enddiff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rbindex 6a05d12755e..1bd32f8fe13 100644--- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb+++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb@@ -287,6 +287,22 @@ RSpec.describe DiscourseNarrativeBot::NewUserNarrative do)end+ it "triggers the response when bookmarking the topic" do+ Jobs.run_later!+ topic = Fabricate(:topic)+ post = Fabricate(:post, topic: topic)+ bookmark = Fabricate(:bookmark, bookmarkable: topic)++ expect_job_enqueued(+ job: :bot_input,+ args: {+ user_id: bookmark.user_id,+ post_id: post.id,+ input: "bookmark",+ },+ )+ end+context "when the bookmark is created" dolet(:profile_page_url) { "#{Discourse.base_url_no_prefix}/prefix/u/#{user.username}" }let(:new_post) { Post.last }