Display group rules correctly in slash commands
This commit is contained in:
parent
c06a4aa4f6
commit
01d7fb47ef
|
@ -82,6 +82,9 @@ module DiscourseChat
|
||||||
i = 1
|
i = 1
|
||||||
rules.each do |rule|
|
rules.each do |rule|
|
||||||
category_id = rule.category_id
|
category_id = rule.category_id
|
||||||
|
|
||||||
|
case rule.type
|
||||||
|
when "normal"
|
||||||
if category_id.nil?
|
if category_id.nil?
|
||||||
category_name = I18n.t("chat_integration.all_categories")
|
category_name = I18n.t("chat_integration.all_categories")
|
||||||
else
|
else
|
||||||
|
@ -92,6 +95,14 @@ module DiscourseChat
|
||||||
category_name = I18n.t("chat_integration.deleted_category")
|
category_name = I18n.t("chat_integration.deleted_category")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
when "group_mention", "group_message"
|
||||||
|
group = Group.find_by(id: rule.group_id)
|
||||||
|
if group
|
||||||
|
category_name = I18n.t("chat_integration.#{rule.type}_template", name: group.name)
|
||||||
|
else
|
||||||
|
category_name = I18n.t("chat_integration.deleted_group")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
text << I18n.t("chat_integration.provider.#{provider}.status.rule_string",
|
text << I18n.t("chat_integration.provider.#{provider}.status.rule_string",
|
||||||
index: i,
|
index: i,
|
||||||
|
|
|
@ -62,6 +62,9 @@ en:
|
||||||
deleted_category: "(deleted category)"
|
deleted_category: "(deleted category)"
|
||||||
deleted_group: "(deleted group)"
|
deleted_group: "(deleted group)"
|
||||||
|
|
||||||
|
group_mention_template: "mentions of: @%{name}"
|
||||||
|
group_message_template: "messages to: @%{name}"
|
||||||
|
|
||||||
provider:
|
provider:
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
|
|
|
@ -152,16 +152,18 @@ RSpec.describe DiscourseChat::Manager do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with some rules' do
|
context 'with some rules' do
|
||||||
|
let(:group){Fabricate(:group)}
|
||||||
before do
|
before do
|
||||||
DiscourseChat::Rule.create!(channel: chan1, filter:'watch', category_id:category.id, tags:nil)
|
DiscourseChat::Rule.create!(channel: chan1, filter:'watch', category_id:category.id, tags:nil)
|
||||||
DiscourseChat::Rule.create!(channel: chan1, filter:'mute', category_id:nil, tags:nil)
|
DiscourseChat::Rule.create!(channel: chan1, filter:'mute', category_id:nil, tags:nil)
|
||||||
DiscourseChat::Rule.create!(channel: chan1, filter:'follow', category_id:nil, tags:[tag1.name])
|
DiscourseChat::Rule.create!(channel: chan1, filter:'follow', category_id:nil, tags:[tag1.name])
|
||||||
|
DiscourseChat::Rule.create!(channel: chan1, filter:'watch', type: 'group_message', group_id:group.id)
|
||||||
DiscourseChat::Rule.create!(channel: chan2, filter:'watch', category_id:1, tags:nil)
|
DiscourseChat::Rule.create!(channel: chan2, filter:'watch', category_id:1, tags:nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'displays the correct rules' do
|
it 'displays the correct rules' do
|
||||||
string = DiscourseChat::Helper.status_for_channel(chan1)
|
string = DiscourseChat::Helper.status_for_channel(chan1)
|
||||||
expect(string.scan('status.rule_string').size).to eq(3)
|
expect(string.scan('status.rule_string').size).to eq(4)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'only displays tags for rules with tags' do
|
it 'only displays tags for rules with tags' do
|
||||||
|
|
Loading…
Reference in New Issue