diff --git a/app/models/notifier.rb b/app/models/notifier.rb index 548b3869c..b856c4073 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -4,10 +4,10 @@ class Notifier class << self def for(source) case source - when Event - EventNotifier.new(source) - when Mention - MentionNotifier.new(source) + when Event + "Notifier::#{source.eventable.class}EventNotifier".safe_constantize&.new(source) + when Mention + MentionNotifier.new(source) end end end diff --git a/app/models/notifier/event_notifier.rb b/app/models/notifier/card_event_notifier.rb similarity index 78% rename from app/models/notifier/event_notifier.rb rename to app/models/notifier/card_event_notifier.rb index 9a42af611..899ee53fb 100644 --- a/app/models/notifier/event_notifier.rb +++ b/app/models/notifier/card_event_notifier.rb @@ -1,4 +1,4 @@ -class Notifier::EventNotifier < Notifier +class Notifier::CardEventNotifier < Notifier delegate :creator, to: :source delegate :watchers_and_subscribers, to: :card @@ -17,10 +17,6 @@ class Notifier::EventNotifier < Notifier end def card - if source.eventable.is_a?(Card) - source.eventable - else - source.eventable.card - end + source.eventable end end diff --git a/app/models/notifier/comment_event_notifier.rb b/app/models/notifier/comment_event_notifier.rb new file mode 100644 index 000000000..40a40f4e5 --- /dev/null +++ b/app/models/notifier/comment_event_notifier.rb @@ -0,0 +1,12 @@ +class Notifier::CommentEventNotifier < Notifier + delegate :creator, to: :source + + private + def recipients + card.watchers_and_subscribers.without(creator, *source.eventable.mentionees) + end + + def card + source.eventable.card + end +end diff --git a/test/models/notifier/event_notifier_test.rb b/test/models/notifier/event_notifier_test.rb index 97b7f5f68..aafc2fcc1 100644 --- a/test/models/notifier/event_notifier_test.rb +++ b/test/models/notifier/event_notifier_test.rb @@ -2,7 +2,7 @@ require "test_helper" class Notifier::EventNotifierTest < ActiveSupport::TestCase test "for returns the matching notifier class for the event" do - assert_kind_of Notifier::EventNotifier, Notifier.for(events(:logo_published)) + assert_kind_of Notifier::CardEventNotifier, Notifier.for(events(:logo_published)) end test "generate does not create notifications if the event was system-generated" do