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
11 changed files with 100 additions and 10 deletions

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