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



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

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

#map_model(user) ⇒ Object



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

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:



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

def meet_push_notifications_requirements?
  Decidim.vapid_public_key.present?
end

#newsletter_notifications_atObject



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

def newsletter_notifications_at
  return nil unless newsletter_notifications

  Time.current
end

#notification_typesObject



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

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