Browse Source

Add setting a always mark media as sensitive (#4136)

closed-social-v3
Yamagishi Kazutoshi 7 years ago
committed by Eugen Rochko
parent
commit
2b9721d1b3
9 changed files with 29 additions and 0 deletions
  1. +1
    -0
      app/controllers/settings/preferences_controller.rb
  2. +7
    -0
      app/javascript/mastodon/reducers/compose.js
  3. +5
    -0
      app/lib/user_settings_decorator.rb
  4. +4
    -0
      app/models/user.rb
  5. +1
    -0
      app/serializers/initial_state_serializer.rb
  6. +1
    -0
      app/serializers/rest/credential_account_serializer.rb
  7. +2
    -0
      app/views/settings/preferences/show.html.haml
  8. +1
    -0
      config/locales/simple_form.en.yml
  9. +7
    -0
      spec/lib/user_settings_decorator_spec.rb

+ 1
- 0
app/controllers/settings/preferences_controller.rb View File

@ -34,6 +34,7 @@ class Settings::PreferencesController < ApplicationController
def user_settings_params
params.require(:user).permit(
:setting_default_privacy,
:setting_default_sensitive,
:setting_boost_modal,
:setting_delete_modal,
:setting_auto_play_gif,

+ 7
- 0
app/javascript/mastodon/reducers/compose.js View File

@ -45,6 +45,7 @@ const initialState = Immutable.Map({
suggestions: Immutable.List(),
me: null,
default_privacy: 'public',
default_sensitive: false,
resetFileKey: Math.floor((Math.random() * 0x10000)),
idempotencyKey: null,
});
@ -75,6 +76,8 @@ function clearAll(state) {
};
function appendMedia(state, media) {
const prevSize = state.get('media_attachments').size;
return state.withMutations(map => {
map.update('media_attachments', list => list.push(media));
map.set('is_uploading', false);
@ -82,6 +85,10 @@ function appendMedia(state, media) {
map.update('text', oldText => `${oldText.trim()} ${media.get('text_url')}`);
map.set('focusDate', new Date());
map.set('idempotencyKey', uuid());
if (prevSize === 0 && state.get('default_sensitive')) {
map.set('sensitive', true);
}
});
};

+ 5
- 0
app/lib/user_settings_decorator.rb View File

@ -18,6 +18,7 @@ class UserSettingsDecorator
user.settings['notification_emails'] = merged_notification_emails
user.settings['interactions'] = merged_interactions
user.settings['default_privacy'] = default_privacy_preference
user.settings['default_sensitive'] = default_sensitive_preference
user.settings['boost_modal'] = boost_modal_preference
user.settings['delete_modal'] = delete_modal_preference
user.settings['auto_play_gif'] = auto_play_gif_preference
@ -36,6 +37,10 @@ class UserSettingsDecorator
settings['setting_default_privacy']
end
def default_sensitive_preference
boolean_cast_setting 'setting_default_sensitive'
end
def boost_modal_preference
boolean_cast_setting 'setting_boost_modal'
end

+ 4
- 0
app/models/user.rb View File

@ -79,6 +79,10 @@ class User < ApplicationRecord
settings.default_privacy || (account.locked? ? 'private' : 'public')
end
def setting_default_sensitive
settings.default_sensitive
end
def setting_boost_modal
settings.boost_modal
end

+ 1
- 0
app/serializers/initial_state_serializer.rb View File

@ -23,6 +23,7 @@ class InitialStateSerializer < ActiveModel::Serializer
{
me: object.current_account.id,
default_privacy: object.current_account.user.setting_default_privacy,
default_sensitive: object.current_account.user.setting_default_sensitive,
}
end

+ 1
- 0
app/serializers/rest/credential_account_serializer.rb View File

@ -7,6 +7,7 @@ class REST::CredentialAccountSerializer < REST::AccountSerializer
user = object.user
{
privacy: user.setting_default_privacy,
sensitive: user.setting_default_sensitive,
note: object.note,
}
end

+ 2
- 0
app/views/settings/preferences/show.html.haml View File

@ -24,6 +24,8 @@
= f.input :setting_default_privacy, collection: Status.visibilities.keys - ['direct'], wrapper: :with_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), content_tag(:span, I18n.t("statuses.visibilities.#{visibility}_long"), class: 'hint')]) }, required: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li'
= f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label
.fields-group
= f.simple_fields_for :notification_emails, hash_to_object(current_user.settings.notification_emails) do |ff|
= ff.input :follow, as: :boolean, wrapper: :with_label

+ 1
- 0
config/locales/simple_form.en.yml View File

@ -37,6 +37,7 @@ en:
setting_auto_play_gif: Auto-play animated GIFs
setting_boost_modal: Show confirmation dialog before boosting
setting_default_privacy: Post privacy
setting_default_sensitive: Always mark media as sensitive
setting_delete_modal: Show confirmation dialog before deleting a toot
setting_system_font_ui: Use system's default font
severity: Severity

+ 7
- 0
spec/lib/user_settings_decorator_spec.rb View File

@ -28,6 +28,13 @@ describe UserSettingsDecorator do
expect(user.settings['default_privacy']).to eq 'public'
end
it 'updates the user settings value for sensitive' do
values = { 'setting_default_sensitive' => '1' }
settings.update(values)
expect(user.settings['default_sensitive']).to eq true
end
it 'updates the user settings value for boost modal' do
values = { 'setting_boost_modal' => '1' }

Loading…
Cancel
Save