FIX: Don't set notification level to `watching` when already watching.

This commit is contained in:
Guo Xiang Tan 2018-09-07 15:00:53 +08:00
parent 7663268584
commit ed1f942c52
2 changed files with 22 additions and 5 deletions

View File

@ -149,13 +149,20 @@ SQL
publish_topic_tracking_state(@topic, assign_to.id)
TopicUser.change(
assign_to.id,
@topic.id,
notification_level: TopicUser.notification_levels[:watching],
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed]
if !TopicUser.exists?(
user_id: assign_to.id,
topic_id: @topic.id,
notification_level: TopicUser.notification_levels[:watching]
)
TopicUser.change(
assign_to.id,
@topic.id,
notification_level: TopicUser.notification_levels[:watching],
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed]
)
end
if SiteSetting.assign_mailer_enabled
if !@topic.muted?(assign_to)
message = AssignMailer.send_assignment(assign_to.email, @topic, @assigned_by)

View File

@ -49,6 +49,16 @@ RSpec.describe TopicAssigner do
.to eq(TopicUser.notification_levels[:tracking])
end
it 'does not update notification level if already watching' do
TopicUser.change(moderator.id, topic.id,
notification_level: TopicUser.notification_levels[:watching]
)
expect do
assigner.assign(moderator)
end.to_not change { TopicUser.last.notifications_reason_id }
end
it 'does not update notification level if it is not set by the plugin' do
assigner.assign(moderator)