lib/activity_notification/models/concerns/subscriber.rb in activity_notification-1.7.1 vs lib/activity_notification/models/concerns/subscriber.rb in activity_notification-2.0.0
- old
+ new
@@ -50,11 +50,12 @@
def create_subscription(subscription_params = {})
created_at = Time.current
if subscription_params[:subscribing] == false && subscription_params[:subscribing_to_email].nil?
subscription_params[:subscribing_to_email] = subscription_params[:subscribing]
end
- subscription = subscriptions.new(subscription_params)
+ subscription = Subscription.new(subscription_params)
+ subscription.assign_attributes(target: self)
subscription.subscribing? ?
subscription.assign_attributes(subscribing: true, subscribed_at: created_at) :
subscription.assign_attributes(subscribing: false, unsubscribed_at: created_at)
subscription.subscribing_to_email? ?
subscription.assign_attributes(subscribing_to_email: true, subscribed_to_email_at: created_at) :
@@ -63,15 +64,15 @@
optional_targets = {}.with_indifferent_access
subscription.optional_target_names.each do |optional_target_name|
optional_targets = subscription.subscribing_to_optional_target?(optional_target_name) ?
optional_targets.merge(
Subscription.to_optional_target_key(optional_target_name) => true,
- Subscription.to_optional_target_subscribed_at_key(optional_target_name) => created_at
+ Subscription.to_optional_target_subscribed_at_key(optional_target_name) => Subscription.convert_time_as_hash(created_at)
) :
optional_targets.merge(
Subscription.to_optional_target_key(optional_target_name) => false,
- Subscription.to_optional_target_unsubscribed_at_key(optional_target_name) => created_at
+ Subscription.to_optional_target_unsubscribed_at_key(optional_target_name) => Subscription.convert_time_as_hash(created_at)
)
end
subscription.assign_attributes(optional_targets: optional_targets)
subscription.save ? subscription : nil
end
@@ -126,22 +127,22 @@
end
protected
# Returns if the target subscribes to the notification.
- # This method can be overriden.
+ # This method can be overridden.
# @api protected
#
# @param [String] key Key of the notification
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
# @return [Boolean] If the target subscribes to the notification
def _subscribes_to_notification?(key, subscribe_as_default = ActivityNotification.config.subscribe_as_default)
evaluate_subscription(subscriptions.where(key: key).first, :subscribing?, subscribe_as_default)
end
# Returns if the target subscribes to the notification email.
- # This method can be overriden.
+ # This method can be overridden.
# @api protected
#
# @param [String] key Key of the notification
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
# @return [Boolean] If the target subscribes to the notification
@@ -149,10 +150,10 @@
evaluate_subscription(subscriptions.where(key: key).first, :subscribing_to_email?, subscribe_as_default)
end
alias_method :_subscribes_to_email?, :_subscribes_to_notification_email?
# Returns if the target subscribes to the specified optional target.
- # This method can be overriden.
+ # This method can be overridden.
# @api protected
#
# @param [String] key Key of the notification
# @param [String, Symbol] optional_target_name Class name of the optional target implementation (e.g. :amazon_sns, :slack)
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
\ No newline at end of file