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
|
2023-10-17 18:02:55 +08:00
|
|
|
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?
|
2023-10-17 18:02:55 +08:00
|
|
|
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
|