Split notifiers for comments and cards
This lets us remove the annoying if to check the card
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user