mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 11:53:55 +08:00
Add DiscourseEvent
trigger when user's topic notification level changes.
This commit is contained in:
parent
66a7b0c30b
commit
7cb389a235
|
@ -136,7 +136,17 @@ SQL
|
|||
end
|
||||
|
||||
if attrs[:notification_level]
|
||||
MessageBus.publish("/topic/#{topic_id}", { notification_level_change: attrs[:notification_level] }, user_ids: [user_id])
|
||||
MessageBus.publish(
|
||||
"/topic/#{topic_id}",
|
||||
{ notification_level_change: attrs[:notification_level] },
|
||||
user_ids: [user_id]
|
||||
)
|
||||
|
||||
DiscourseEvent.trigger(:topic_notification_level_changed,
|
||||
attrs[:notification_level],
|
||||
user_id,
|
||||
topic_id
|
||||
)
|
||||
end
|
||||
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
|
|
|
@ -72,7 +72,7 @@ describe TopicUser do
|
|||
guardian = Guardian.new(u)
|
||||
TopicCreator.create(u, guardian, title: "this is my topic title")
|
||||
}
|
||||
let(:topic_user) { TopicUser.get(topic,user) }
|
||||
let(:topic_user) { TopicUser.get(topic, user) }
|
||||
let(:topic_creator_user) { TopicUser.get(topic, topic.user) }
|
||||
|
||||
let(:post) { Fabricate(:post, topic: topic, user: user) }
|
||||
|
@ -99,6 +99,18 @@ describe TopicUser do
|
|||
end
|
||||
|
||||
describe 'notifications' do
|
||||
it 'should trigger the right DiscourseEvent' do
|
||||
begin
|
||||
called = false
|
||||
DiscourseEvent.on(:topic_notification_level_changed) { called = true }
|
||||
|
||||
TopicUser.change(user.id, topic.id, notification_level: TopicUser.notification_levels[:tracking])
|
||||
|
||||
expect(called).to eq(true)
|
||||
ensure
|
||||
DiscourseEvent.off(:topic_notification_level_changed) { called = true }
|
||||
end
|
||||
end
|
||||
|
||||
it 'should be set to tracking if auto_track_topics is enabled' do
|
||||
user.user_option.update_column(:auto_track_topics_after_msecs, 0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user