mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 19:45:42 +08:00
FEATURE: mute/watch/track buttons for private conversations
This commit is contained in:
parent
fc3bad8ff4
commit
7e5a17f277
@ -42,7 +42,12 @@ Discourse.TopicDetails = Discourse.Model.extend({
|
|||||||
|
|
||||||
|
|
||||||
notificationReasonText: function() {
|
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') {
|
if (typeof this.get('notifications_reason_id') === 'number') {
|
||||||
localeString += "_" + this.get('notifications_reason_id');
|
localeString += "_" + this.get('notifications_reason_id');
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,33 @@ Discourse.NotificationsButton = Discourse.DropdownButtonView.extend({
|
|||||||
longDescriptionBinding: 'topic.details.notificationReasonText',
|
longDescriptionBinding: 'topic.details.notificationReasonText',
|
||||||
topic: Em.computed.alias('controller.model'),
|
topic: Em.computed.alias('controller.model'),
|
||||||
hidden: Em.computed.alias('topic.deleted'),
|
hidden: Em.computed.alias('topic.deleted'),
|
||||||
|
isPrivateMessage: Em.computed.alias('topic.isPrivateMessage'),
|
||||||
|
|
||||||
dropDownContent: [
|
dropDownContent: function() {
|
||||||
[Discourse.Topic.NotificationLevel.WATCHING, 'topic.notifications.watching'],
|
var contents = [], postfix = '';
|
||||||
[Discourse.Topic.NotificationLevel.TRACKING, 'topic.notifications.tracking'],
|
|
||||||
[Discourse.Topic.NotificationLevel.REGULAR, 'topic.notifications.regular'],
|
if(this.get('isPrivateMessage')) {
|
||||||
[Discourse.Topic.NotificationLevel.MUTE, 'topic.notifications.muted']
|
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() {
|
text: function() {
|
||||||
var key = (function() {
|
var key = (function() {
|
||||||
|
@ -30,10 +30,8 @@ Discourse.TopicFooterButtonsView = Discourse.ContainerView.extend({
|
|||||||
this.attachViewClass(Discourse.ClearPinButton);
|
this.attachViewClass(Discourse.ClearPinButton);
|
||||||
}
|
}
|
||||||
this.attachViewClass(Discourse.ReplyButton);
|
this.attachViewClass(Discourse.ReplyButton);
|
||||||
|
this.attachViewClass(Discourse.NotificationsButton);
|
||||||
|
|
||||||
if (!topic.get('isPrivateMessage')) {
|
|
||||||
this.attachViewClass(Discourse.NotificationsButton);
|
|
||||||
}
|
|
||||||
this.trigger('additionalButtons', this);
|
this.trigger('additionalButtons', this);
|
||||||
} else {
|
} else {
|
||||||
// If not logged in give them a login control
|
// 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|
|
post.topic.all_allowed_users.reject{ |user| user.id == post.user_id }.each do |user|
|
||||||
next if user.blank?
|
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)
|
destroy_notifications(user, Notification.types[:private_message], post.topic)
|
||||||
unread_post = first_unread_post(user,post.topic) || post
|
unread_post = first_unread_post(user,post.topic) || post
|
||||||
create_notification(user, Notification.types[:private_message], unread_post)
|
create_notification(user, Notification.types[:private_message], unread_post)
|
||||||
|
@ -14,8 +14,8 @@ class TopicNotifier
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def watch_topic!(user_id)
|
def watch_topic!(user_id, reason = :created_topic)
|
||||||
change_level user_id, :watching, :created_topic
|
change_level user_id, :watching, reason
|
||||||
end
|
end
|
||||||
|
|
||||||
# Enable/disable the mute on the topic
|
# 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.'
|
"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": 'You are ignoring all notifications on this topic.'
|
||||||
"0_2": '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:
|
watching:
|
||||||
title: "Watching"
|
title: "Watching"
|
||||||
description: "same as Tracking, plus you will be notified of all new posts."
|
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:
|
tracking:
|
||||||
title: "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."
|
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:
|
regular:
|
||||||
title: "Regular"
|
title: "Regular"
|
||||||
description: "you will be notified only if someone mentions your @name or replies to your post."
|
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:
|
muted:
|
||||||
title: "Muted"
|
title: "Muted"
|
||||||
description: "you will not be notified of anything about this topic, and it will not appear on your unread tab."
|
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
|
unless @opts[:auto_track] == false
|
||||||
@topic.notifier.watch_topic!(@topic.user_id)
|
@topic.notifier.watch_topic!(@topic.user_id)
|
||||||
end
|
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)
|
TopicUser.auto_watch_new_topic(@topic.id)
|
||||||
CategoryUser.auto_watch_new_topic(@topic)
|
CategoryUser.auto_watch_new_topic(@topic)
|
||||||
end
|
end
|
||||||
|
@ -146,6 +146,18 @@ describe TopicUser do
|
|||||||
end
|
end
|
||||||
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
|
context 'auto tracking' do
|
||||||
|
|
||||||
let(:post_creator) { PostCreator.new(new_user, raw: Fabricate.build(:post).raw, topic_id: topic.id) }
|
let(:post_creator) { PostCreator.new(new_user, raw: Fabricate.build(:post).raw, topic_id: topic.id) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user