mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FEATURE: mute/watch/track buttons for private conversations
This commit is contained in:
parent
fc3bad8ff4
commit
7e5a17f277
8 changed files with 66 additions and 12 deletions
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in a new issue