From d42a06fc7404f64ada011554cfd7ea7574c769e9 Mon Sep 17 00:00:00 2001 From: "Renato \"Lond\" Cerqueira" Date: Mon, 1 Oct 2018 19:32:47 +0200 Subject: [PATCH] Add default federation option to settings --- app/controllers/api/v1/accounts/credentials_controller.rb | 1 + app/controllers/settings/preferences_controller.rb | 1 + app/lib/user_settings_decorator.rb | 5 +++++ app/models/user.rb | 2 +- app/serializers/initial_state_serializer.rb | 1 + app/serializers/rest/credential_account_serializer.rb | 1 + app/services/post_status_service.rb | 5 +++-- app/views/settings/preferences/show.html.haml | 2 ++ config/locales/simple_form.en.yml | 1 + config/locales/simple_form.pt-BR.yml | 1 + config/settings.yml | 1 + 11 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/accounts/credentials_controller.rb b/app/controllers/api/v1/accounts/credentials_controller.rb index dcd41b35c..994c11bd6 100644 --- a/app/controllers/api/v1/accounts/credentials_controller.rb +++ b/app/controllers/api/v1/accounts/credentials_controller.rb @@ -33,6 +33,7 @@ class Api::V1::Accounts::CredentialsController < Api::BaseController 'setting_default_privacy' => source_params.fetch(:privacy, @account.user.setting_default_privacy), 'setting_default_sensitive' => source_params.fetch(:sensitive, @account.user.setting_default_sensitive), 'setting_default_language' => source_params.fetch(:language, @account.user.setting_default_language), + 'setting_default_federation' => source_params.fetch(:sensitive, @account.user.setting_default_federation), } end end diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index b475c722d..4044eb579 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -36,6 +36,7 @@ class Settings::PreferencesController < ApplicationController :setting_default_privacy, :setting_default_sensitive, :setting_default_language, + :setting_default_federation, :setting_unfollow_modal, :setting_boost_modal, :setting_delete_modal, diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 833959397..4ec8402eb 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -20,6 +20,7 @@ class UserSettingsDecorator user.settings['default_privacy'] = default_privacy_preference if change?('setting_default_privacy') user.settings['default_sensitive'] = default_sensitive_preference if change?('setting_default_sensitive') user.settings['default_language'] = default_language_preference if change?('setting_default_language') + user.settings['default_federation'] = default_federation_preference if change?('setting_default_federation') user.settings['unfollow_modal'] = unfollow_modal_preference if change?('setting_unfollow_modal') user.settings['boost_modal'] = boost_modal_preference if change?('setting_boost_modal') user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal') @@ -48,6 +49,10 @@ class UserSettingsDecorator boolean_cast_setting 'setting_default_sensitive' end + def default_federation_preference + boolean_cast_setting 'setting_default_federation' + end + def unfollow_modal_preference boolean_cast_setting 'setting_unfollow_modal' end diff --git a/app/models/user.rb b/app/models/user.rb index d83df28c2..2b8d182b1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -96,7 +96,7 @@ class User < ApplicationRecord delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal, :reduce_motion, :system_font_ui, :noindex, :theme, :display_sensitive_media, :hide_network, - :default_language, to: :settings, prefix: :setting, allow_nil: false + :default_language, :default_federation, to: :settings, prefix: :setting, allow_nil: false attr_reader :invite_code diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 78b96298c..6062087a8 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -38,6 +38,7 @@ class InitialStateSerializer < ActiveModel::Serializer store[:me] = object.current_account.id.to_s store[:default_privacy] = object.current_account.user.setting_default_privacy store[:default_sensitive] = object.current_account.user.setting_default_sensitive + store[:default_federation] = object.current_account.user.setting_default_federation end store[:text] = object.text if object.text diff --git a/app/serializers/rest/credential_account_serializer.rb b/app/serializers/rest/credential_account_serializer.rb index fb195eb07..f07f9f058 100644 --- a/app/serializers/rest/credential_account_serializer.rb +++ b/app/serializers/rest/credential_account_serializer.rb @@ -10,6 +10,7 @@ class REST::CredentialAccountSerializer < REST::AccountSerializer privacy: user.setting_default_privacy, sensitive: user.setting_default_sensitive, language: user.setting_default_language, + federation: user.setting_default_federation, note: object.note, fields: object.fields.map(&:to_h), } diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index cdcb6b087..83d661ae2 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -32,7 +32,7 @@ class PostStatusService < BaseService visibility: options[:visibility] || account.user&.setting_default_privacy, language: language_from_option(options[:language]) || account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(text, account), application: options[:application], - local_only: local_only_option(options[:local_only], in_reply_to)) + local_only: local_only_option(options[:local_only], in_reply_to, account.user&.setting_default_federation)) end process_hashtags_service.call(status) @@ -58,8 +58,9 @@ class PostStatusService < BaseService private - def local_only_option(local_only, in_reply_to) + def local_only_option(local_only, in_reply_to, federation_setting) return in_reply_to&.local_only? if local_only.nil? # XXX temporary, just until clients implement to avoid leaking local_only posts + return federation_setting if local_only.nil? local_only end diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml index 43430069f..715ce49ed 100644 --- a/app/views/settings/preferences/show.html.haml +++ b/app/views/settings/preferences/show.html.haml @@ -23,6 +23,8 @@ = f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label + = f.input :setting_default_federation, as: :boolean, wrapper: :with_label + %h4= t 'preferences.other' .fields-group diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 2e4cb1eff..676fa7b5d 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -65,6 +65,7 @@ en: phrase: Keyword or phrase setting_auto_play_gif: Auto-play animated GIFs setting_boost_modal: Show confirmation dialog before boosting + setting_default_federation: Always allow my toots to reach other instances setting_default_language: Posting language setting_default_privacy: Post privacy setting_default_sensitive: Always mark media as sensitive diff --git a/config/locales/simple_form.pt-BR.yml b/config/locales/simple_form.pt-BR.yml index 013b26066..b9a3d2864 100644 --- a/config/locales/simple_form.pt-BR.yml +++ b/config/locales/simple_form.pt-BR.yml @@ -65,6 +65,7 @@ pt-BR: phrase: Palavra-chave ou frase setting_auto_play_gif: Reproduzir GIFs automaticamente setting_boost_modal: Mostrar diálogo de confirmação antes de compartilhar postagem + setting_default_federation: Sempre permitir que meus toots cheguem em outras instâncias setting_default_language: Idioma das postagens setting_default_privacy: Privacidade das postagens setting_default_sensitive: Sempre marcar mídia como sensível diff --git a/config/settings.yml b/config/settings.yml index 78a801406..552ef60f6 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -21,6 +21,7 @@ defaults: &defaults timeline_preview: true show_staff_badge: true default_sensitive: false + default_federation: true hide_network: false unfollow_modal: false boost_modal: false