From 20c2c66dd4c407d00fc57f0ce364813a08614dac Mon Sep 17 00:00:00 2001
From: cpradio <forums@cpradio.com>
Date: Thu, 20 Apr 2017 22:33:10 -0400
Subject: [PATCH] FEATURE: Add normal as a preference for topic subscription
 state when replying to a topic

---
 .../discourse/controllers/preferences.js.es6    |  3 ++-
 ...fication_level_when_replying_site_setting.rb |  3 ++-
 lib/post_creator.rb                             |  2 ++
 spec/components/post_creator_spec.rb            | 17 +++++++++++++++++
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/app/assets/javascripts/discourse/controllers/preferences.js.es6 b/app/assets/javascripts/discourse/controllers/preferences.js.es6
index 9173a771539..ac848d3ea29 100644
--- a/app/assets/javascripts/discourse/controllers/preferences.js.es6
+++ b/app/assets/javascripts/discourse/controllers/preferences.js.es6
@@ -124,7 +124,8 @@ export default Ember.Controller.extend(CanCheckEmails, {
                        { name: I18n.t('user.auto_track_options.after_10_minutes'), value: 600000 }],
 
   notificationLevelsForReplying: [{ name: I18n.t('topic.notifications.watching.title'), value: NotificationLevels.WATCHING },
-                                  { name: I18n.t('topic.notifications.tracking.title'), value: NotificationLevels.TRACKING }],
+                                  { name: I18n.t('topic.notifications.tracking.title'), value: NotificationLevels.TRACKING },
+                                  { name: I18n.t('topic.notifications.regular.title'), value: NotificationLevels.REGULAR }],
 
 
   considerNewTopicOptions: [{ name: I18n.t('user.new_topic_duration.not_viewed'), value: -1 },
diff --git a/app/models/notification_level_when_replying_site_setting.rb b/app/models/notification_level_when_replying_site_setting.rb
index 66b07cb5453..296c7c066f9 100644
--- a/app/models/notification_level_when_replying_site_setting.rb
+++ b/app/models/notification_level_when_replying_site_setting.rb
@@ -15,7 +15,8 @@ class NotificationLevelWhenReplyingSiteSetting < EnumSiteSetting
   def self.values
     @values ||= [
       { name: 'topic.notifications.watching.title', value: notification_levels[:watching] },
-      { name: 'topic.notifications.tracking.title', value: notification_levels[:tracking] }
+      { name: 'topic.notifications.tracking.title', value: notification_levels[:tracking] },
+      { name: 'topic.notifications.regular.title', value: notification_levels[:regular] }
     ]
   end
 
diff --git a/lib/post_creator.rb b/lib/post_creator.rb
index 864ea578a7d..9da222b5cd2 100644
--- a/lib/post_creator.rb
+++ b/lib/post_creator.rb
@@ -494,6 +494,8 @@ class PostCreator
       TopicUser.auto_notification_for_staging(@user.id, @topic.id, TopicUser.notification_reasons[:auto_watch])
     elsif @user.user_option.notification_level_when_replying === NotificationLevels.topic_levels[:watching]
       TopicUser.auto_notification(@user.id, @topic.id, TopicUser.notification_reasons[:created_post], NotificationLevels.topic_levels[:watching])
+    elsif @user.user_option.notification_level_when_replying === NotificationLevels.topic_levels[:regular]
+      TopicUser.auto_notification(@user.id, @topic.id, TopicUser.notification_reasons[:created_post], NotificationLevels.topic_levels[:regular])
     else
       TopicUser.auto_notification(@user.id, @topic.id, TopicUser.notification_reasons[:created_post], NotificationLevels.topic_levels[:tracking])
     end
diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb
index d2ee5299cf0..7240aeaf80c 100644
--- a/spec/components/post_creator_spec.rb
+++ b/spec/components/post_creator_spec.rb
@@ -899,6 +899,23 @@ describe PostCreator do
       topic_user = TopicUser.find_by(user_id: user.id, topic_id: post.topic_id)
       expect(topic_user.notification_level).to eq(TopicUser.notification_levels[:tracking])
     end
+
+    it "topic notification level is normal based on preference" do
+      user.user_option.notification_level_when_replying = 1
+
+      admin = Fabricate(:admin)
+      topic = PostCreator.create(admin,
+                                 title: "this is the title of a topic created by an admin for tracking notification",
+                                 raw: "this is the content of a topic created by an admin for keeping a tracking notification state on a topic ;)"
+      )
+
+      post = PostCreator.create(user,
+                                topic_id: topic.topic_id,
+                                raw: "this is a reply to set the tracking state to normal ;)"
+      )
+      topic_user = TopicUser.find_by(user_id: user.id, topic_id: post.topic_id)
+      expect(topic_user.notification_level).to eq(TopicUser.notification_levels[:regular])
+    end
   end
 
   describe '#create!' do