mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 03:25:32 +08:00
FIX: Polymorphic bookmarks for new user narrative bot (#16683)
This commit allows the new user narrative bot to work with polymorphic bookmarks, gated behind the use_polymorphic_bookmarks site setting.
This commit is contained in:
parent
222c8d9b6a
commit
4d0ac8636c
@ -243,7 +243,6 @@ module DiscourseNarrativeBot
|
|||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO (martin) [POLYBOOK] Fix up narrative bot bookmark interactions in a separate PR.
|
|
||||||
def missing_bookmark
|
def missing_bookmark
|
||||||
return unless valid_topic?(@post.topic_id)
|
return unless valid_topic?(@post.topic_id)
|
||||||
return if @post.user_id == self.discobot_user.id
|
return if @post.user_id == self.discobot_user.id
|
||||||
@ -254,7 +253,6 @@ module DiscourseNarrativeBot
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO (martin) [POLYBOOK] Fix up narrative bot bookmark interactions in a separate PR.
|
|
||||||
def reply_to_bookmark
|
def reply_to_bookmark
|
||||||
return unless valid_topic?(@post.topic_id)
|
return unless valid_topic?(@post.topic_id)
|
||||||
return unless @post.user_id == self.discobot_user.id
|
return unless @post.user_id == self.discobot_user.id
|
||||||
|
@ -281,10 +281,13 @@ after_initialize do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO (martin) [POLYBOOK] Fix up narrative bot bookmark interactions in a separate PR.
|
|
||||||
self.add_model_callback(Bookmark, :after_commit, on: :create) do
|
self.add_model_callback(Bookmark, :after_commit, on: :create) do
|
||||||
if self.post && self.user.enqueue_narrative_bot_job?
|
if self.user.enqueue_narrative_bot_job?
|
||||||
Jobs.enqueue(:bot_input, user_id: self.user_id, post_id: self.post_id, input: "bookmark")
|
if SiteSetting.use_polymorphic_bookmarks && self.bookmarkable_type == "Post"
|
||||||
|
Jobs.enqueue(:bot_input, user_id: self.user_id, post_id: self.bookmarkable_id, input: "bookmark")
|
||||||
|
elsif !SiteSetting.use_polymorphic_bookmarks && self.post.present?
|
||||||
|
Jobs.enqueue(:bot_input, user_id: self.user_id, post_id: self.post_id, input: "bookmark")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -248,7 +248,22 @@ describe DiscourseNarrativeBot::NewUserNarrative do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should create the right reply when bookmarks with reminders are enabled' do
|
it 'adds an after commit model callback to bookmark' do
|
||||||
|
Jobs.run_later!
|
||||||
|
bookmark = Fabricate(:bookmark, post: Fabricate(:post))
|
||||||
|
expect_job_enqueued(job: :bot_input, args: { user_id: bookmark.user_id, post_id: bookmark.post_id, input: "bookmark" })
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'adds an after commit model callback to bookmark for polymorphic bookmarks (but only for post polymorphic bookmarks)' do
|
||||||
|
SiteSetting.use_polymorphic_bookmarks = true
|
||||||
|
Jobs.run_later!
|
||||||
|
bookmark = Fabricate(:bookmark, bookmarkable: Fabricate(:post))
|
||||||
|
expect_job_enqueued(job: :bot_input, args: { user_id: bookmark.user_id, post_id: bookmark.bookmarkable_id, input: "bookmark" })
|
||||||
|
bookmark2 = Fabricate(:bookmark, bookmarkable: Fabricate(:topic))
|
||||||
|
expect_not_enqueued_with(job: :bot_input, args: { user_id: bookmark.user_id, post_id: kind_of(Integer), input: "bookmark" })
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should create the right reply when the bookmark is created' do
|
||||||
post.update!(user: discobot_user)
|
post.update!(user: discobot_user)
|
||||||
narrative.expects(:enqueue_timeout_job).with(user)
|
narrative.expects(:enqueue_timeout_job).with(user)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user