Class: NewsmastMastodon::Api::V1::Accounts::PatchworkSettingsController
- Inherits:
-
Api::BaseController
- Object
- Api::BaseController
- NewsmastMastodon::Api::V1::Accounts::PatchworkSettingsController
- Includes:
- Concerns::ApiResponseHelper
- Defined in:
- app/controllers/newsmast_mastodon/api/v1/accounts/patchwork_settings_controller.rb
Instance Method Summary collapse
-
#article_notifications ⇒ Object
get article notifications setting.
-
#leicester_news_notification ⇒ Object
get push notification settings for leicester_news.
-
#update_article_notifications ⇒ Object
update article notifications setting.
-
#update_leicester_news_notification ⇒ Object
update push notification settings for leicester_news.
Instance Method Details
#article_notifications ⇒ Object
get article notifications setting
35 36 37 38 39 40 41 |
# File 'app/controllers/newsmast_mastodon/api/v1/accounts/patchwork_settings_controller.rb', line 35 def article_notifications @patchwork_setting = NewsmastMastodon::PatchworkSetting.find_by(account: @account, app_name: @app_name) settings_hash = @patchwork_setting&.settings || {} is_allowed = settings_hash.dig('article_notifications') || false render_success({ article_notifications: is_allowed }, 'api.messages.success', :ok) end |
#leicester_news_notification ⇒ Object
get push notification settings for leicester_news
10 11 12 13 14 15 16 |
# File 'app/controllers/newsmast_mastodon/api/v1/accounts/patchwork_settings_controller.rb', line 10 def leicester_news_notification @patchwork_setting = NewsmastMastodon::PatchworkSetting.find_by(account: @account, app_name: @app_name) settings_hash = @patchwork_setting&.settings || {} is_allowed = settings_hash.dig("leicester_notification") || false render_success({ leicester_notification: is_allowed }, 'api.messages.success', :ok) end |
#update_article_notifications ⇒ Object
update article notifications setting
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/newsmast_mastodon/api/v1/accounts/patchwork_settings_controller.rb', line 44 def update_article_notifications is_allowed = ActiveModel::Type::Boolean.new.cast(article_notifications_params[:allowed]) @patchwork_setting = NewsmastMastodon::PatchworkSetting.find_or_initialize_by(account: @account, app_name: @app_name) current_settings = (@patchwork_setting.settings || {}).with_indifferent_access updated_settings = current_settings.deep_merge( article_notifications: is_allowed ) if @patchwork_setting.update(settings: updated_settings) render_success({ article_notifications: is_allowed }, 'api.messages.success', :ok) else render_errors('api.errors.unprocessable_entity', :unprocessable_entity) end end |
#update_leicester_news_notification ⇒ Object
update push notification settings for leicester_news
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/newsmast_mastodon/api/v1/accounts/patchwork_settings_controller.rb', line 19 def update_leicester_news_notification is_allowed = ActiveModel::Type::Boolean.new.cast(leicester_notification_params[:allowed]) @patchwork_setting = NewsmastMastodon::PatchworkSetting.find_or_initialize_by(account: @account, app_name: @app_name) current_settings = (@patchwork_setting.settings || {}).with_indifferent_access updated_settings = current_settings.deep_merge( leicester_notification: is_allowed ) if @patchwork_setting.update(settings: updated_settings) render_success({ leicester_notification: is_allowed }, 'api.messages.success', :ok) else render_errors('api.errors.unprocessable_entity', :unprocessable_entity) end end |