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: {})
|
2023-01-27 13:53:23 +01:00
|
|
|
receiver = [receiver] unless receiver.respond_to?(:each)
|
2023-01-27 16:21:16 +01:00
|
|
|
notification_type = NotificationType.find_by(name: type)
|
|
|
|
|
2023-01-27 13:53:23 +01:00
|
|
|
receiver.each do |user|
|
|
|
|
Notification.new(
|
|
|
|
meta_data: meta_data,
|
|
|
|
attached_object: attached_object,
|
|
|
|
receiver: user,
|
2023-01-27 16:21:16 +01:00
|
|
|
notification_type: notification_type
|
2023-01-27 13:53:23 +01:00
|
|
|
)
|
2023-01-27 16:21:16 +01:00
|
|
|
.deliver_with_preferences(user, notification_type)
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|