Skip to content

Commit 8498d88

Browse files
authored
FIX: Topic changing category was not triggering notifications (#244)
We moved `category_changed` notification to be a `whisper` but we forgot to update the check in `manager.rb` to verify not for a `small_post` but for a whisper. Added a test to cover this case.
1 parent f0cac67 commit 8498d88

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

Diff for: app/services/manager.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ def self.trigger_notifications(post_id)
1515
# Abort if the post is blank
1616
return if post.blank?
1717

18-
# Abort if post is not either regular or a 'category_changed' small action
18+
# Abort if post is not either regular or a 'category_changed' whisper
1919
if (post.post_type != Post.types[:regular]) &&
2020
!(
21-
post.post_type == Post.types[:small_action] &&
21+
post.post_type == Post.types[:whisper] &&
2222
%w[category_changed].include?(post.action_code)
2323
)
2424
return

Diff for: spec/services/manager_spec.rb

+36
Original file line numberDiff line numberDiff line change
@@ -346,5 +346,41 @@
346346
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
347347
end
348348
end
349+
350+
describe "with whispers and actions enabled" do
351+
before do
352+
SiteSetting.create_post_for_category_and_tag_changes = true
353+
SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}"
354+
end
355+
356+
it "should notify about category changes" do
357+
DiscourseChatIntegration::Rule.create!(
358+
channel: chan1,
359+
filter: "watch",
360+
category_id: category.id,
361+
)
362+
363+
new_category = Fabricate(:category)
364+
DiscourseChatIntegration::Rule.create!(
365+
channel: chan1,
366+
filter: "watch",
367+
category_id: new_category.id,
368+
)
369+
370+
manager.trigger_notifications(first_post.id)
371+
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
372+
373+
# Change category
374+
PostRevisor.new(first_post, topic).revise!(
375+
Discourse.system_user,
376+
category_id: new_category.id,
377+
)
378+
379+
last_topic_post = topic.posts.last
380+
manager.trigger_notifications(last_topic_post.id)
381+
expect(provider.sent_messages.count).to eq(2)
382+
expect(provider.sent_messages.last).to eq(post: last_topic_post.id, channel: chan1)
383+
end
384+
end
349385
end
350386
end

0 commit comments

Comments
 (0)