From ec7046f9122d3b2220f1aa850038dc0ebc9fa71e Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Thu, 25 Apr 2019 14:17:48 +0200 Subject: [PATCH] Add setting to disable some rich text features --- .../settings/preferences_controller.rb | 1 + app/helpers/stream_entries_helper.rb | 11 +++ .../mastodon/components/status_content.js | 5 +- app/javascript/mastodon/initial_state.js | 1 + .../styles/mastodon/components.scss | 93 +++++++++++-------- app/lib/user_settings_decorator.rb | 5 + app/models/user.rb | 3 +- app/serializers/initial_state_serializer.rb | 19 ++-- .../rest/preferences_serializer.rb | 5 + app/views/settings/preferences/show.html.haml | 1 + .../stream_entries/_detailed_status.html.haml | 2 +- .../stream_entries/_simple_status.html.haml | 2 +- config/locales/en.yml | 7 ++ config/locales/simple_form.en.yml | 1 + config/settings.yml | 1 + 15 files changed, 107 insertions(+), 50 deletions(-) diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index 5afdf0eec..aa17ae6ce 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -49,6 +49,7 @@ class Settings::PreferencesController < Settings::BaseController :setting_hide_network, :setting_aggregate_reblogs, :setting_show_application, + :setting_strip_formatting, notification_emails: %i(follow follow_request reblog favourite mention digest report pending_account), interactions: %i(must_be_follower must_be_following) ) diff --git a/app/helpers/stream_entries_helper.rb b/app/helpers/stream_entries_helper.rb index d56efbfb9..189121b3f 100644 --- a/app/helpers/stream_entries_helper.rb +++ b/app/helpers/stream_entries_helper.rb @@ -132,6 +132,17 @@ module StreamEntriesHelper end end + def text_formatting_classes + case current_user&.setting_strip_formatting + when 'none', nil + 'rich-text rich-blocks' + when 'blocks' + 'rich-text' + when 'all' + nil + end + end + def style_classes(status, is_predecessor, is_successor, include_threads) classes = ['entry'] classes << 'entry-predecessor' if is_predecessor diff --git a/app/javascript/mastodon/components/status_content.js b/app/javascript/mastodon/components/status_content.js index fa8901386..9197b7b94 100644 --- a/app/javascript/mastodon/components/status_content.js +++ b/app/javascript/mastodon/components/status_content.js @@ -6,6 +6,7 @@ import { FormattedMessage } from 'react-intl'; import Permalink from './permalink'; import classnames from 'classnames'; import Icon from 'mastodon/components/icon'; +import { stripFormatting } from 'mastodon/initial_state'; const MAX_HEIGHT = 642; // 20px * 32 (+ 2px padding at the top) @@ -153,6 +154,8 @@ export default class StatusContent extends React.PureComponent { 'status__content--with-action': this.props.onClick && this.context.router, 'status__content--with-spoiler': status.get('spoiler_text').length > 0, 'status__content--collapsed': this.state.collapsed === true, + 'rich-text': stripFormatting !== 'all', + 'rich-blocks': stripFormatting === 'none', }); if (isRtl(status.get('search_index'))) { @@ -218,7 +221,7 @@ export default class StatusContent extends React.PureComponent {
('margin-bottom: 0' unless current_account&.user&.setting_expand_spoilers) }< %span.p-summary> #{Formatter.instance.format_spoiler(status, autoplay: autoplay)}  diff --git a/app/views/stream_entries/_simple_status.html.haml b/app/views/stream_entries/_simple_status.html.haml index 0df7497e1..076cdc265 100644 --- a/app/views/stream_entries/_simple_status.html.haml +++ b/app/views/stream_entries/_simple_status.html.haml @@ -19,7 +19,7 @@ %span.display-name__account = acct(status.account) = fa_icon('lock') if status.account.locked? - .status__content.emojify< + .status__content.emojify{ class: text_formatting_classes }< - if status.spoiler_text? %p{ :style => ('margin-bottom: 0' unless current_account&.user&.setting_expand_spoilers) }< %span.p-summary> #{Formatter.instance.format_spoiler(status, autoplay: autoplay)}  diff --git a/config/locales/en.yml b/config/locales/en.yml index 6d59411a5..260ee6a69 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -909,6 +909,13 @@ en: vote: Vote show_more: Show more sign_in_to_participate: Sign in to participate in the conversation + strip_formatting: + all: All + all_long: Strip all advanced formatting + blocks: Block elements + blocks_long: Strip formatting for title headers and block quotes + none: None + none_long: Do not strip any formatting supported by Mastodon title: '%{name}: "%{quote}"' visibilities: private: Followers-only diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 1a43e19e2..fa55c4c74 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -106,6 +106,7 @@ en: setting_noindex: Opt-out of search engine indexing setting_reduce_motion: Reduce motion in animations setting_show_application: Disclose application used to send toots + setting_strip_formatting: Strip advanced formatting from toots setting_system_font_ui: Use system's default font setting_theme: Site theme setting_unfollow_modal: Show confirmation dialog before unfollowing someone diff --git a/config/settings.yml b/config/settings.yml index 1534d45f6..52db7035b 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -31,6 +31,7 @@ defaults: &defaults noindex: false theme: 'mastodon' aggregate_reblogs: true + strip_formatting: 'none' notification_emails: follow: false reblog: false