Class: Decidim::NotificationsSettingsForm

Inherits:
Form
  • Object
show all
Defined in:
app/forms/decidim/notifications_settings_form.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#direct_message_typesObject



40
41
42
# File 'app/forms/decidim/notifications_settings_form.rb', line 40

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

#map_model(user) ⇒ Object



15
16
17
18
19
20
# File 'app/forms/decidim/notifications_settings_form.rb', line 15

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"
end

#newsletter_notifications_atObject



22
23
24
25
26
# File 'app/forms/decidim/notifications_settings_form.rb', line 22

def newsletter_notifications_at
  return nil unless newsletter_notifications

  Time.current
end

#notification_typesObject



28
29
30
31
32
33
34
35
36
37
38
# File 'app/forms/decidim/notifications_settings_form.rb', line 28

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