From 01d7fb47ef3963d95fa1af0e970c119688a0942e Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 1 Aug 2017 19:16:47 +0100 Subject: [PATCH] Display group rules correctly in slash commands --- app/helpers/helper.rb | 25 ++++++++++++++++++------- config/locales/server.en.yml | 3 +++ spec/helpers/helper_spec.rb | 4 +++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/helpers/helper.rb b/app/helpers/helper.rb index 7deca25..c50aac6 100644 --- a/app/helpers/helper.rb +++ b/app/helpers/helper.rb @@ -82,14 +82,25 @@ module DiscourseChat i = 1 rules.each do |rule| category_id = rule.category_id - if category_id.nil? - category_name = I18n.t("chat_integration.all_categories") - else - category = Category.find_by(id: category_id) - if category - category_name = category.slug + + case rule.type + when "normal" + if category_id.nil? + category_name = I18n.t("chat_integration.all_categories") else - category_name = I18n.t("chat_integration.deleted_category") + category = Category.find_by(id: category_id) + if category + category_name = category.slug + else + category_name = I18n.t("chat_integration.deleted_category") + 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 diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 7b889d1..c04bad2 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -62,6 +62,9 @@ en: deleted_category: "(deleted category)" deleted_group: "(deleted group)" + group_mention_template: "mentions of: @%{name}" + group_message_template: "messages to: @%{name}" + provider: ####################################### diff --git a/spec/helpers/helper_spec.rb b/spec/helpers/helper_spec.rb index 61214de..d627968 100644 --- a/spec/helpers/helper_spec.rb +++ b/spec/helpers/helper_spec.rb @@ -152,16 +152,18 @@ RSpec.describe DiscourseChat::Manager do end context 'with some rules' do + let(:group){Fabricate(:group)} before do 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:'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) end it 'displays the correct rules' do 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 it 'only displays tags for rules with tags' do