3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/unotifier/user_notifier.rb', line 3
def self.notify_user(notification, params = {})
locale_key = UNotifier.locale_key_for(notification.key, params)
user_settings = notification.target.notification_settings[notification.key]
user_settings ||= Settings::DEFAULT_URGENCY
notify_with = []
if !params[:external_only] && notify_onsite?(notification, user_settings)
notify_with += UNotifier.configuration.site_providers
end
if !params[:onsite_only] && notify_external?(notification, user_settings)
notify_with += UNotifier.configuration.external_providers
end
notify_with.each do |provider|
title_provider_key = "#{locale_key}.#{provider.class.to_s.split("::").last}.title"
body_provider_key = "#{locale_key}.#{provider.class.to_s.split("::").last}.body"
if UNotifier.configuration.localization_provider.exists?(title_provider_key)
notification.title =
UNotifier.configuration.localization_provider.t(
title_provider_key, params.merge(locale: notification.target.locale)
)
end
if UNotifier.configuration.localization_provider.exists?(body_provider_key)
notification.body =
UNotifier.configuration.localization_provider.t(
body_provider_key, params.merge(locale: notification.target.locale, default: "")
)
end
provider.notify(notification)
end
end
|