Class: Thredded::UserPreferencesForm
- Inherits:
-
Object
- Object
- Thredded::UserPreferencesForm
- Includes:
- ActiveModel::Model
- Defined in:
- app/forms/thredded/user_preferences_form.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #for_every_notifier(prefs) ⇒ Object
-
#initialize(user:, messageboard: nil, messageboards: nil, params: {}) ⇒ UserPreferencesForm
constructor
A new instance of UserPreferencesForm.
- #messageboard_groups ⇒ Object
- #messageboard_notifications_for_followed_topics ⇒ Object
- #notifications_for_followed_topics ⇒ Object
- #notifications_for_private_topics ⇒ Object
- #save ⇒ Boolean
- #update_path ⇒ Object
Constructor Details
#initialize(user:, messageboard: nil, messageboards: nil, params: {}) ⇒ UserPreferencesForm
Returns a new instance of UserPreferencesForm.
27 28 29 30 31 32 |
# File 'app/forms/thredded/user_preferences_form.rb', line 27 def initialize(user:, messageboard: nil, messageboards: nil, params: {}) @user = user @messageboard = @messageboards = super(params) end |
Instance Attribute Details
#messageboard ⇒ Thredded::Messageboard? (readonly)
8 9 10 |
# File 'app/forms/thredded/user_preferences_form.rb', line 8 def @messageboard end |
Instance Method Details
#for_every_notifier(prefs) ⇒ Object
73 74 75 76 77 |
# File 'app/forms/thredded/user_preferences_form.rb', line 73 def for_every_notifier(prefs) Thredded.notifiers.map do |notifier| prefs.find { |n| n.notifier_key == notifier.key } || prefs.build(notifier_key: notifier.key) end end |
#messageboard_groups ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/forms/thredded/user_preferences_form.rb', line 52 def @messageboard_groups ||= Thredded::MessageboardGroupView.grouped( @messageboards, user: @user, with_unread_topics_counts: false ) end |
#messageboard_notifications_for_followed_topics ⇒ Object
68 69 70 71 |
# File 'app/forms/thredded/user_preferences_form.rb', line 68 def return nil unless for_every_notifier(user_preference..()) end |
#notifications_for_followed_topics ⇒ Object
64 65 66 |
# File 'app/forms/thredded/user_preferences_form.rb', line 64 def notifications_for_followed_topics for_every_notifier(user_preference.notifications_for_followed_topics) end |
#notifications_for_private_topics ⇒ Object
60 61 62 |
# File 'app/forms/thredded/user_preferences_form.rb', line 60 def notifications_for_private_topics for_every_notifier(user_preference.notifications_for_private_topics) end |
#save ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/forms/thredded/user_preferences_form.rb', line 35 def save return false unless valid? Thredded::UserPreference.transaction do user_preference.save! # Update all of the messageboards' auto_follow_topics if the global preference has changed. if user_preference.previous_changes.include?('auto_follow_topics') Thredded::UserMessageboardPreference.where(user: @user) .update_all(auto_follow_topics: user_preference.auto_follow_topics) .auto_follow_topics_will_change! if end .save! if end true end |
#update_path ⇒ Object
79 80 81 82 83 84 85 |
# File 'app/forms/thredded/user_preferences_form.rb', line 79 def update_path if @messageboard Thredded::UrlsHelper.(@messageboard) else Thredded::UrlsHelper.global_preferences_path end end |