diff --git a/app/assets/javascripts/discourse/models/topic_details.js b/app/assets/javascripts/discourse/models/topic_details.js index fe915dcd5..6a5a84614 100644 --- a/app/assets/javascripts/discourse/models/topic_details.js +++ b/app/assets/javascripts/discourse/models/topic_details.js @@ -42,7 +42,12 @@ Discourse.TopicDetails = Discourse.Model.extend({ notificationReasonText: function() { - var localeString = "topic.notifications.reasons." + (this.get('notification_level') || 1); + var level = this.get('notification_level'); + if(typeof level !== 'number'){ + level = 1; + } + + var localeString = "topic.notifications.reasons." + level; if (typeof this.get('notifications_reason_id') === 'number') { localeString += "_" + this.get('notifications_reason_id'); } diff --git a/app/assets/javascripts/discourse/views/buttons/notifications_button.js b/app/assets/javascripts/discourse/views/buttons/notifications_button.js index 0eadf40a5..6c86afced 100644 --- a/app/assets/javascripts/discourse/views/buttons/notifications_button.js +++ b/app/assets/javascripts/discourse/views/buttons/notifications_button.js @@ -12,13 +12,33 @@ Discourse.NotificationsButton = Discourse.DropdownButtonView.extend({ longDescriptionBinding: 'topic.details.notificationReasonText', topic: Em.computed.alias('controller.model'), hidden: Em.computed.alias('topic.deleted'), + isPrivateMessage: Em.computed.alias('topic.isPrivateMessage'), - dropDownContent: [ - [Discourse.Topic.NotificationLevel.WATCHING, 'topic.notifications.watching'], - [Discourse.Topic.NotificationLevel.TRACKING, 'topic.notifications.tracking'], - [Discourse.Topic.NotificationLevel.REGULAR, 'topic.notifications.regular'], - [Discourse.Topic.NotificationLevel.MUTE, 'topic.notifications.muted'] - ], + dropDownContent: function() { + var contents = [], postfix = ''; + + if(this.get('isPrivateMessage')) { + postfix = '_pm'; + } + + _.each([ + ['WATCHING', 'watching'], + ['TRACKING', 'tracking'], + ['REGULAR', 'regular'], + ['MUTE', 'muted'] + ], function(pair){ + + if(pair[1] !== 'regular' && postfix !== 'pm') { + + contents.push([ + Discourse.Topic.NotificationLevel[pair[0]], + 'topic.notifications.' + pair[1] + postfix + ]); + } + }); + + return contents; + }.property(), text: function() { var key = (function() { diff --git a/app/assets/javascripts/discourse/views/topic_footer_buttons_view.js b/app/assets/javascripts/discourse/views/topic_footer_buttons_view.js index 46361bdfd..c1f622506 100644 --- a/app/assets/javascripts/discourse/views/topic_footer_buttons_view.js +++ b/app/assets/javascripts/discourse/views/topic_footer_buttons_view.js @@ -30,10 +30,8 @@ Discourse.TopicFooterButtonsView = Discourse.ContainerView.extend({ this.attachViewClass(Discourse.ClearPinButton); } this.attachViewClass(Discourse.ReplyButton); + this.attachViewClass(Discourse.NotificationsButton); - if (!topic.get('isPrivateMessage')) { - this.attachViewClass(Discourse.NotificationsButton); - } this.trigger('additionalButtons', this); } else { // If not logged in give them a login control diff --git a/app/models/post_alert_observer.rb b/app/models/post_alert_observer.rb index 838d8281e..d33c443f3 100644 --- a/app/models/post_alert_observer.rb +++ b/app/models/post_alert_observer.rb @@ -63,6 +63,11 @@ class PostAlertObserver < ActiveRecord::Observer post.topic.all_allowed_users.reject{ |user| user.id == post.user_id }.each do |user| next if user.blank? + if TopicUser.get(post.topic, user).try(:notification_level) == TopicUser.notification_levels[:tracking] + next unless post.reply_to_post_number + next unless post.reply_to_post.user_id == user.id + end + destroy_notifications(user, Notification.types[:private_message], post.topic) unread_post = first_unread_post(user,post.topic) || post create_notification(user, Notification.types[:private_message], unread_post) diff --git a/app/models/topic_notifier.rb b/app/models/topic_notifier.rb index f464f5106..6cdaab4ee 100644 --- a/app/models/topic_notifier.rb +++ b/app/models/topic_notifier.rb @@ -14,8 +14,8 @@ class TopicNotifier end - def watch_topic!(user_id) - change_level user_id, :watching, :created_topic + def watch_topic!(user_id, reason = :created_topic) + change_level user_id, :watching, reason end # Enable/disable the mute on the topic diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 7d0ead813..5b46f5c71 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -715,15 +715,24 @@ en: "1_2": 'You will be notified only if someone mentions your @name or replies to your post.' "0": 'You are ignoring all notifications on this topic.' "0_2": 'You are ignoring all notifications on this topic.' + watching_pm: + title: "Watching" + description: "same as Tracking, plus you will be notified of all new posts." watching: title: "Watching" description: "same as Tracking, plus you will be notified of all new posts." + tracking_pm: + title: "Tracking" + description: "you will be notified of @name mentions and replies to your posts" tracking: title: "Tracking" description: "you will be notified of @name mentions and replies to your posts, plus you will see a count of unread and new posts." regular: title: "Regular" description: "you will be notified only if someone mentions your @name or replies to your post." + muted_pm: + title: "Muted" + description: "you will not be notified of anything about this private message." muted: title: "Muted" description: "you will not be notified of anything about this topic, and it will not appear on your unread tab." diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb index cd2e296a0..20ae7b56b 100644 --- a/lib/topic_creator.rb +++ b/lib/topic_creator.rb @@ -37,6 +37,11 @@ class TopicCreator unless @opts[:auto_track] == false @topic.notifier.watch_topic!(@topic.user_id) end + + @topic.topic_allowed_users.pluck(:user_id).reject{|id| id == @topic.user_id}.each do |id| + @topic.notifier.watch_topic!(id, nil) + end + TopicUser.auto_watch_new_topic(@topic.id) CategoryUser.auto_watch_new_topic(@topic) end diff --git a/spec/models/topic_user_spec.rb b/spec/models/topic_user_spec.rb index 5b19eb951..cccaf2acd 100644 --- a/spec/models/topic_user_spec.rb +++ b/spec/models/topic_user_spec.rb @@ -146,6 +146,18 @@ describe TopicUser do end end + context 'private messages' do + it 'should ensure recepients and senders are watching' do + ActiveRecord::Base.observers.enable :all + + target_user = Fabricate(:user) + post = create_post(archetype: Archetype.private_message, target_usernames: target_user.username); + + TopicUser.get(post.topic, post.user).notification_level.should == TopicUser.notification_levels[:watching] + TopicUser.get(post.topic, target_user).notification_level.should == TopicUser.notification_levels[:watching] + end + end + context 'auto tracking' do let(:post_creator) { PostCreator.new(new_user, raw: Fabricate.build(:post).raw, topic_id: topic.id) }