Add default federation option to settings

This commit is contained in:
Renato "Lond" Cerqueira 2018-10-01 19:32:47 +02:00
parent 9d6e005849
commit d42a06fc74
11 changed files with 18 additions and 3 deletions

View File

@ -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_privacy' => source_params.fetch(:privacy, @account.user.setting_default_privacy),
'setting_default_sensitive' => source_params.fetch(:sensitive, @account.user.setting_default_sensitive), '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_language' => source_params.fetch(:language, @account.user.setting_default_language),
'setting_default_federation' => source_params.fetch(:sensitive, @account.user.setting_default_federation),
} }
end end
end end

View File

@ -36,6 +36,7 @@ class Settings::PreferencesController < ApplicationController
:setting_default_privacy, :setting_default_privacy,
:setting_default_sensitive, :setting_default_sensitive,
:setting_default_language, :setting_default_language,
:setting_default_federation,
:setting_unfollow_modal, :setting_unfollow_modal,
:setting_boost_modal, :setting_boost_modal,
:setting_delete_modal, :setting_delete_modal,

View File

@ -20,6 +20,7 @@ class UserSettingsDecorator
user.settings['default_privacy'] = default_privacy_preference if change?('setting_default_privacy') 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_sensitive'] = default_sensitive_preference if change?('setting_default_sensitive')
user.settings['default_language'] = default_language_preference if change?('setting_default_language') 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['unfollow_modal'] = unfollow_modal_preference if change?('setting_unfollow_modal')
user.settings['boost_modal'] = boost_modal_preference if change?('setting_boost_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') user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal')
@ -48,6 +49,10 @@ class UserSettingsDecorator
boolean_cast_setting 'setting_default_sensitive' boolean_cast_setting 'setting_default_sensitive'
end end
def default_federation_preference
boolean_cast_setting 'setting_default_federation'
end
def unfollow_modal_preference def unfollow_modal_preference
boolean_cast_setting 'setting_unfollow_modal' boolean_cast_setting 'setting_unfollow_modal'
end end

View File

@ -96,7 +96,7 @@ class User < ApplicationRecord
delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal, delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal,
:reduce_motion, :system_font_ui, :noindex, :theme, :display_sensitive_media, :hide_network, :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 attr_reader :invite_code

View File

@ -38,6 +38,7 @@ class InitialStateSerializer < ActiveModel::Serializer
store[:me] = object.current_account.id.to_s store[:me] = object.current_account.id.to_s
store[:default_privacy] = object.current_account.user.setting_default_privacy store[:default_privacy] = object.current_account.user.setting_default_privacy
store[:default_sensitive] = object.current_account.user.setting_default_sensitive store[:default_sensitive] = object.current_account.user.setting_default_sensitive
store[:default_federation] = object.current_account.user.setting_default_federation
end end
store[:text] = object.text if object.text store[:text] = object.text if object.text

View File

@ -10,6 +10,7 @@ class REST::CredentialAccountSerializer < REST::AccountSerializer
privacy: user.setting_default_privacy, privacy: user.setting_default_privacy,
sensitive: user.setting_default_sensitive, sensitive: user.setting_default_sensitive,
language: user.setting_default_language, language: user.setting_default_language,
federation: user.setting_default_federation,
note: object.note, note: object.note,
fields: object.fields.map(&:to_h), fields: object.fields.map(&:to_h),
} }

View File

@ -32,7 +32,7 @@ class PostStatusService < BaseService
visibility: options[:visibility] || account.user&.setting_default_privacy, 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), language: language_from_option(options[:language]) || account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(text, account),
application: options[:application], 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 end
process_hashtags_service.call(status) process_hashtags_service.call(status)
@ -58,8 +58,9 @@ class PostStatusService < BaseService
private 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 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 local_only
end end

View File

@ -23,6 +23,8 @@
= f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label = f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label
= f.input :setting_default_federation, as: :boolean, wrapper: :with_label
%h4= t 'preferences.other' %h4= t 'preferences.other'
.fields-group .fields-group

View File

@ -65,6 +65,7 @@ en:
phrase: Keyword or phrase phrase: Keyword or phrase
setting_auto_play_gif: Auto-play animated GIFs setting_auto_play_gif: Auto-play animated GIFs
setting_boost_modal: Show confirmation dialog before boosting 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_language: Posting language
setting_default_privacy: Post privacy setting_default_privacy: Post privacy
setting_default_sensitive: Always mark media as sensitive setting_default_sensitive: Always mark media as sensitive

View File

@ -65,6 +65,7 @@ pt-BR:
phrase: Palavra-chave ou frase phrase: Palavra-chave ou frase
setting_auto_play_gif: Reproduzir GIFs automaticamente setting_auto_play_gif: Reproduzir GIFs automaticamente
setting_boost_modal: Mostrar diálogo de confirmação antes de compartilhar postagem 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_language: Idioma das postagens
setting_default_privacy: Privacidade das postagens setting_default_privacy: Privacidade das postagens
setting_default_sensitive: Sempre marcar mídia como sensível setting_default_sensitive: Sempre marcar mídia como sensível

View File

@ -21,6 +21,7 @@ defaults: &defaults
timeline_preview: true timeline_preview: true
show_staff_badge: true show_staff_badge: true
default_sensitive: false default_sensitive: false
default_federation: true
hide_network: false hide_network: false
unfollow_modal: false unfollow_modal: false
boost_modal: false boost_modal: false