scinote-web/app/models/concerns/generate_notification_model.rb

28 lines
614 B
Ruby
Raw Normal View History

2021-02-25 14:43:04 +08:00
# frozen_string_literal: true
module GenerateNotificationModel
extend ActiveSupport::Concern
include GlobalActivitiesHelper
included do
after_create :generate_notification
end
def generate_notification_from_activity
params = { activity_id: id, type: "#{type_of}_activity".to_sym }
ActivityNotification.send_notifications(params, later: true)
2021-02-25 14:43:04 +08:00
end
protected
def notifiable?
NotificationExtends::NOTIFICATIONS_TYPES.key?("#{type_of}_activity".to_sym)
2021-02-25 14:43:04 +08:00
end
2021-02-25 18:58:15 +08:00
private
def generate_notification
CreateNotificationFromActivityJob.perform_later(self) if notifiable?
end
2021-02-25 14:43:04 +08:00
end