2019-02-26 10:45:12 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# send notification to one or several receiver with a type, an attached object and an optional meta data
|
2015-05-05 03:10:25 +02:00
|
|
|
class NotificationCenter
|
2019-02-26 10:45:12 +01:00
|
|
|
def self.call(type: nil, receiver: nil, attached_object: nil, meta_data: {})
|
2015-05-05 03:10:25 +02:00
|
|
|
if receiver.respond_to?(:each)
|
|
|
|
receiver.each do |user|
|
2019-02-26 10:45:12 +01:00
|
|
|
Notification.new(meta_data: meta_data)
|
|
|
|
.send_notification(type: type, attached_object: attached_object)
|
|
|
|
.to(user)
|
|
|
|
.deliver_later
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
else
|
2019-02-26 10:45:12 +01:00
|
|
|
Notification.new(meta_data: meta_data)
|
|
|
|
.send_notification(type: type, attached_object: attached_object)
|
|
|
|
.to(receiver)
|
|
|
|
.deliver_later
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|