Class: Decidim::NotificationsSettingsForm

Inherits:
Form show all
Defined in:
decidim-core/app/forms/decidim/notifications_settings_form.rb

Overview

The form object that handles the data behind updating a user’s notifications settings in their profile page.

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from AttributeObject::Form

#context

Instance Method Summary collapse

Methods inherited from AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#direct_message_typesObject



43
44
45
# File 'decidim-core/app/forms/decidim/notifications_settings_form.rb', line 43

def direct_message_types
  allow_public_contact ? "all" : "followed-only"
end

#map_model(user) ⇒ Object



17
18
19
20
21
22
23
# File 'decidim-core/app/forms/decidim/notifications_settings_form.rb', line 17

def map_model(user)
  self.newsletter_notifications = user.newsletter_notifications_at.present?
  self.notifications_from_followed = ["all", "followed-only"].include? user.notification_types
  self.notifications_from_own_activity = ["all", "own-only"].include? user.notification_types
  self.allow_public_contact = user.direct_message_types == "all"
  self.notifications_sending_frequency = user.notifications_sending_frequency
end

#meet_push_notifications_requirements?Boolean

Returns:



47
48
49
# File 'decidim-core/app/forms/decidim/notifications_settings_form.rb', line 47

def meet_push_notifications_requirements?
  Rails.application.secrets.dig(:vapid, :enabled) || false
end

#newsletter_notifications_atObject



25
26
27
28
29
# File 'decidim-core/app/forms/decidim/notifications_settings_form.rb', line 25

def newsletter_notifications_at
  return nil unless newsletter_notifications

  Time.current
end

#notification_typesObject



31
32
33
34
35
36
37
38
39
40
41
# File 'decidim-core/app/forms/decidim/notifications_settings_form.rb', line 31

def notification_types
  if notifications_from_followed && notifications_from_own_activity
    "all"
  elsif notifications_from_followed
    "followed-only"
  elsif notifications_from_own_activity
    "own-only"
  else
    "none"
  end
end