diff --git a/app/models/topic.rb b/app/models/topic.rb index 86feb633a3d..161d5ba3615 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1022,8 +1022,9 @@ SQL def set_or_create_timer(status_type, time, by_user: nil, timezone_offset: 0, based_on_last_post: false, category_id: SiteSetting.uncategorized_category_id) return delete_topic_timer(status_type, by_user: by_user) if time.blank? - topic_timer_options = { topic: self } - topic_timer_options.merge!(user: by_user) unless TopicTimer.public_types[status_type] + public_topic_timer = !!TopicTimer.public_types[status_type] + topic_timer_options = { topic: self, public_type: public_topic_timer } + topic_timer_options.merge!(user: by_user) unless public_topic_timer topic_timer = TopicTimer.find_or_initialize_by(topic_timer_options) topic_timer.status_type = status_type diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index c152875acc0..ce3ece7a4f4 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1333,6 +1333,14 @@ describe Topic do }.to change { TopicTimer.count }.by(1) end + it 'should not be override when setting a public topic timer' do + reminder + + expect do + topic.set_or_create_timer(TopicTimer.types[:close], 3, by_user: reminder.user) + end.to change { TopicTimer.count }.by(1) + end + it "can update a user's existing record" do freeze_time now