2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

FEATURE: add option to skip new user tips in first notification. (#10462)

This commit is contained in:
Vinoth Kannan 2020-08-18 13:43:40 +05:30 committed by GitHub
parent 2a7490149c
commit 562180dd9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 100 additions and 10 deletions

View file

@ -156,6 +156,7 @@ en:
reset_trigger: "tutorial"
title: "New user tutorial completion certificate"
cert_title: "In recognition of successful completion of the new user tutorial"
delete_reason: "User skipped the new user tips"
hello:
title: "Greetings!"

View file

@ -150,6 +150,12 @@ after_initialize do
user.enqueue_bot_welcome_post
end
self.add_model_callback(UserOption, :after_save) do
if saved_change_to_skip_new_user_tips? && self.skip_new_user_tips
user.delete_bot_welcome_post
end
end
self.add_to_class(:user, :enqueue_bot_welcome_post) do
return if SiteSetting.disable_discourse_narrative_bot_welcome_post
@ -173,9 +179,26 @@ after_initialize do
self.human? &&
!self.anonymous? &&
!self.staged &&
!user_option.skip_new_user_tips &&
!SiteSetting.discourse_narrative_bot_ignored_usernames.split('|'.freeze).include?(self.username)
end
self.add_to_class(:user, :delete_bot_welcome_post) do
data = DiscourseNarrativeBot::Store.get(self.id) || {}
topic_id = data[:topic_id]
return if topic_id.blank? || data[:track] != DiscourseNarrativeBot::NewUserNarrative.to_s
topic_user = topic_users.find_by(topic_id: topic_id)
return if topic_user.present? && (topic_user.last_read_post_number.present? || topic_user.highest_seen_post_number.present?)
topic = Topic.find_by(id: topic_id)
return if topic.blank?
first_post = topic.ordered_posts.first
PostDestroyer.new(Discourse.system_user, first_post, context: I18n.t('discourse_narrative_bot.new_user_narrative.delete_reason')).destroy
DiscourseNarrativeBot::Store.remove(self.id)
end
self.on(:post_created) do |post, options|
user = post.user

View file

@ -108,6 +108,21 @@ describe User do
end
end
context 'when user skipped the new user tips' do
let(:user) { Fabricate(:user) }
it 'should not initiate the bot' do
SiteSetting.default_other_skip_new_user_tips = true
expect { user }.to_not change { Post.count }
end
it 'should delete the existing PM' do
user.user_option.skip_new_user_tips = true
expect { user.user_option.save! }.to change { Topic.count }.by(-1)
end
end
context 'when user is anonymous?' do
before do
SiteSetting.allow_anonymous_posting = true