Class: Decidim::NotificationsSubscriptionsPersistor
- Inherits:
-
Object
- Object
- Decidim::NotificationsSubscriptionsPersistor
- Defined in:
- app/services/decidim/notifications_subscriptions_persistor.rb
Overview
This class manages the creation and deletion of user notifications
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #add_subscription(params) ⇒ Object
- #delete_subscription(auth_key) ⇒ Object
-
#initialize(user) ⇒ NotificationsSubscriptionsPersistor
constructor
A new instance of NotificationsSubscriptionsPersistor.
Constructor Details
#initialize(user) ⇒ NotificationsSubscriptionsPersistor
Returns a new instance of NotificationsSubscriptionsPersistor.
9 10 11 |
# File 'app/services/decidim/notifications_subscriptions_persistor.rb', line 9 def initialize(user) @user = user end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
7 8 9 |
# File 'app/services/decidim/notifications_subscriptions_persistor.rb', line 7 def user @user end |
Instance Method Details
#add_subscription(params) ⇒ Object
13 14 15 16 17 18 19 |
# File 'app/services/decidim/notifications_subscriptions_persistor.rb', line 13 def add_subscription(params) subscriptions = user.notification_settings["subscriptions"] || {} filtered_params = filter_params(params) new_subscription = { filtered_params[:auth] => filtered_params } user.notification_settings["subscriptions"] = subscriptions.merge(new_subscription) user.save end |
#delete_subscription(auth_key) ⇒ Object
21 22 23 24 25 |
# File 'app/services/decidim/notifications_subscriptions_persistor.rb', line 21 def delete_subscription(auth_key) subscriptions = user.notification_settings["subscriptions"] || {} user.notification_settings["subscriptions"] = subscriptions.except(auth_key) user.save end |