From 902fbd0b7e588431788396be28256ed9725c15c1 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Mon, 28 Sep 2020 13:52:33 +1000 Subject: [PATCH] FIX: when the user is promoted to TL2 invite to advance training (#10752) Invitation to advanced training should be sent as a separate private message instead of hooking into TL2 promotion message. --- .../discourse-narrative-bot/config/locales/server.en.yml | 4 +--- plugins/discourse-narrative-bot/plugin.rb | 7 +++++-- .../advanced_user_narrative_spec.rb | 9 +++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/discourse-narrative-bot/config/locales/server.en.yml b/plugins/discourse-narrative-bot/config/locales/server.en.yml index f1ceb70cef0..8371f666ba0 100644 --- a/plugins/discourse-narrative-bot/config/locales/server.en.yml +++ b/plugins/discourse-narrative-bot/config/locales/server.en.yml @@ -24,10 +24,8 @@ en: bio: "Hi, I’m not a real person. I’m a bot that can teach you about this site. To interact with me, send me a message or mention **`@%{discobot_username}`** anywhere." tl2_promotion_message: - subject_template: "Congratulations on your trust level promotion!" + subject_template: "Now that you’ve been promoted, it’s time to learn about some advanced features!" text_body_template: | - Now that you’ve been promoted, it’s time to learn about some advanced features! - Reply to this message with `@%{discobot_username} %{reset_trigger}` to find out more about what you can do. timeout: diff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rb index 10ddf09c9d7..b6c72c64530 100644 --- a/plugins/discourse-narrative-bot/plugin.rb +++ b/plugins/discourse-narrative-bot/plugin.rb @@ -293,12 +293,15 @@ after_initialize do discobot_username: ::DiscourseNarrativeBot::Base.new.discobot_username, reset_trigger: "#{::DiscourseNarrativeBot::TrackSelector.reset_trigger} #{::DiscourseNarrativeBot::AdvancedUserNarrative.reset_trigger}") + recipient = args[:post].topic.topic_users.where.not(user_id: args[:post].user_id).last.user + PostCreator.create!( ::DiscourseNarrativeBot::Base.new.discobot_user, title: I18n.t("discourse_narrative_bot.tl2_promotion_message.subject_template"), raw: raw, - topic_id: args[:post].topic_id, - skip_validations: true + skip_validations: true, + archetype: Archetype.private_message, + target_usernames: recipient.username ) end end diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb index 10b499e9fea..31b94e83eab 100644 --- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb +++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/advanced_user_narrative_spec.rb @@ -732,4 +732,13 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do end end end + + it 'invites to advanced training when user is promoted to TL2' do + recipient = Fabricate(:user) + expect { + DiscourseEvent.trigger(:system_message_sent, post: Post.last, message_type: 'tl2_promotion_message') + }.to change { Topic.count } + expect(Topic.last.title).to eq(I18n.t("discourse_narrative_bot.tl2_promotion_message.subject_template")) + expect(Topic.last.topic_users.map(&:user_id).sort).to eq([DiscourseNarrativeBot::Base.new.discobot_user.id, recipient.id]) + end end