Fix precedence for group-based rules
This commit is contained in:
parent
4f9ad4efef
commit
6af31bb244
|
@ -52,9 +52,10 @@ module DiscourseChat
|
|||
end
|
||||
end
|
||||
|
||||
# Sort by order of precedence (mute always wins; watch beats follow)
|
||||
precedence = { 'mute' => 0, 'watch' => 1, 'follow' => 2 }
|
||||
sort_func = proc { |a, b| precedence[a.filter] <=> precedence[b.filter] }
|
||||
# Sort by order of precedence
|
||||
t_prec = { 'group_message' => 0, 'group_mention' => 1, 'normal' => 2 } # Group things win
|
||||
f_prec = { 'mute' => 0, 'watch' => 1, 'follow' => 2 } #(mute always wins; watch beats follow)
|
||||
sort_func = proc { |a, b| [t_prec[a.type], f_prec[a.filter]] <=> [t_prec[b.type], f_prec[b.filter]] }
|
||||
matching_rules = matching_rules.sort(&sort_func)
|
||||
|
||||
# Take the first rule for each channel
|
||||
|
|
|
@ -145,6 +145,20 @@ RSpec.describe DiscourseChat::Manager do
|
|||
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id, chan3.id)
|
||||
end
|
||||
|
||||
|
||||
|
||||
it "should give group rule precedence over normal rules" do
|
||||
third_post = Fabricate(:post, topic: topic, post_number: 3, raw: "let's mention @#{group.name}")
|
||||
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'mute', category_id: category.id) # Mute category
|
||||
manager.trigger_notifications(third_post.id)
|
||||
expect(provider.sent_to_channel_ids).to contain_exactly()
|
||||
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'watch', type: 'group_mention', group_id: group.id) # Watch mentions
|
||||
manager.trigger_notifications(third_post.id)
|
||||
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
|
||||
end
|
||||
|
||||
it "should not notify about posts the chat_user cannot see" do
|
||||
DiscourseChat::Rule.create!(channel: chan1, filter: 'follow', category_id: nil) # Wildcard watch
|
||||
|
||||
|
|
Loading…
Reference in New Issue