2013-02-06 03:16:51 +08:00
|
|
|
class UserEmailObserver < ActiveRecord::Observer
|
|
|
|
observe :notification
|
|
|
|
|
|
|
|
def after_commit(notification)
|
|
|
|
if notification.send(:transaction_include_action?, :create)
|
2013-03-01 20:07:44 +08:00
|
|
|
notification_type = Notification.types[notification.notification_type]
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
# Delegate to email_user_{{NOTIFICATION_TYPE}} if exists
|
|
|
|
email_method = :"email_user_#{notification_type.to_s}"
|
|
|
|
send(email_method, notification) if respond_to?(email_method)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def email_user_mentioned(notification)
|
|
|
|
return unless notification.user.email_direct?
|
2013-02-07 23:45:24 +08:00
|
|
|
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
|
|
|
|
:user_email,
|
|
|
|
type: :user_mentioned,
|
2013-02-06 03:16:51 +08:00
|
|
|
user_id: notification.user_id,
|
|
|
|
notification_id: notification.id)
|
|
|
|
end
|
|
|
|
|
2013-02-28 04:38:44 +08:00
|
|
|
def email_user_posted(notification)
|
|
|
|
return unless notification.user.email_direct?
|
|
|
|
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
|
|
|
|
:user_email,
|
|
|
|
type: :user_posted,
|
|
|
|
user_id: notification.user_id,
|
|
|
|
notification_id: notification.id)
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
def email_user_quoted(notification)
|
|
|
|
return unless notification.user.email_direct?
|
2013-02-07 23:45:24 +08:00
|
|
|
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
|
|
|
|
:user_email,
|
|
|
|
type: :user_quoted,
|
2013-02-06 03:16:51 +08:00
|
|
|
user_id: notification.user_id,
|
|
|
|
notification_id: notification.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def email_user_replied(notification)
|
|
|
|
return unless notification.user.email_direct?
|
2013-02-07 23:45:24 +08:00
|
|
|
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
|
|
|
|
:user_email,
|
|
|
|
type: :user_replied,
|
2013-02-06 03:16:51 +08:00
|
|
|
user_id: notification.user_id,
|
|
|
|
notification_id: notification.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def email_user_invited_to_private_message(notification)
|
|
|
|
return unless notification.user.email_direct?
|
2013-02-07 23:45:24 +08:00
|
|
|
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes,
|
|
|
|
:user_email,
|
|
|
|
type: :user_invited_to_private_message,
|
2013-02-06 03:16:51 +08:00
|
|
|
user_id: notification.user_id,
|
|
|
|
notification_id: notification.id)
|
|
|
|
end
|
|
|
|
end
|