Skip to content

Commit

Permalink
Change build subscription and subscribe to use subscribe_to_email_as_…
Browse files Browse the repository at this point in the history
…default config
  • Loading branch information
kiskoza committed Mar 26, 2021
1 parent 104b0a3 commit a0ca838
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/activity_notification/apis/subscription_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def as_json(options = {})
# @return [Boolean] If successfully updated subscription instance
def subscribe(options = {})
subscribed_at = options[:subscribed_at] || Time.current
with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] : true
with_optional_targets = options.has_key?(:with_optional_targets) ? options[:with_optional_targets] : true
with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] : ActivityNotification.config.subscribe_to_email_as_default
with_optional_targets = options.has_key?(:with_optional_targets) ? options[:with_optional_targets] : ActivityNotification.config.subscribe_to_optional_targets_as_default
new_attributes = { subscribing: true, subscribed_at: subscribed_at, optional_targets: optional_targets }
new_attributes = new_attributes.merge(subscribing_to_email: true, subscribed_to_email_at: subscribed_at) if with_email_subscription
if with_optional_targets
Expand Down
2 changes: 2 additions & 0 deletions lib/activity_notification/models/concerns/subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def build_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]
elsif subscription_params[:subscribing_to_email].nil?
subscription_params[:subscribing_to_email] = ActivityNotification.config.subscribe_to_email_as_default
end
subscription = Subscription.new(subscription_params)
subscription.assign_attributes(target: self)
Expand Down

0 comments on commit a0ca838

Please sign in to comment.