2eae58725a
Is confusing since "source" already captures the origin of the notifications. It's needed to interpret things at rendering time, so we can query things as needed there.
36 lines
572 B
Ruby
36 lines
572 B
Ruby
class Notifier
|
|
attr_reader :source
|
|
|
|
class << self
|
|
def for(source)
|
|
case source
|
|
when ::Event
|
|
Notifier::Event.new(source)
|
|
when ::Mention
|
|
Notifier::Mention.new(source)
|
|
end
|
|
end
|
|
end
|
|
|
|
def notify
|
|
if should_notify?
|
|
recipients.map do |recipient|
|
|
Notification.create! user: recipient, source: source, creator: creator
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
def initialize(source)
|
|
@source = source
|
|
end
|
|
|
|
def should_notify?
|
|
!creator.system?
|
|
end
|
|
|
|
def resource
|
|
source
|
|
end
|
|
end
|