Class: NewsmastMastodon::Api::V1::Patchwork::EmailSettingsController

Inherits:
Api::BaseController
  • Object
show all
Includes:
Concerns::ApiResponseHelper, Concerns::EmailNotificationAttributesConcern
Defined in:
app/controllers/newsmast_mastodon/api/v1/patchwork/email_settings_controller.rb

Instance Method Summary collapse

Methods included from Concerns::EmailNotificationAttributesConcern

#email_notification_attributes

Instance Method Details

#email_notificationObject



22
23
24
25
26
27
28
29
# File 'app/controllers/newsmast_mastodon/api/v1/patchwork/email_settings_controller.rb', line 22

def email_notification
  settings = enable_email_notification? ? email_notification_attributes(enabled: true) : email_notification_attributes(enabled: false)
  if current_user.update(settings_attributes: settings)
    render_success({}, 'api.messages.success', :ok)
  else
    render_error('api.errors.unprocessable_entity', :unprocessable_entity)
  end
end

#indexObject



11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/newsmast_mastodon/api/v1/patchwork/email_settings_controller.rb', line 11

def index
  notification_emails = current_user.settings.as_json.select do |key, _|
    key.to_s.start_with?("notification_emails.")
  end
  notification_emails.delete(:'notification_emails.software_updates')
  all_same = notification_emails.values.uniq.size == 1
  result_variable = all_same ? notification_emails.values.first : true
  data = notification_emails.empty? ? false : result_variable
  render_success(data, 'api.messages.success', :ok)
end