Add setting to disable some rich text features

This commit is contained in:
Thibaut Girka 2019-04-25 14:17:48 +02:00 committed by asonix
parent 619945045f
commit ec7046f912
15 changed files with 107 additions and 50 deletions

View File

@ -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)
)

View File

@ -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

View File

@ -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 {
<div
tabIndex='0'
ref={this.setRef}
className='status__content'
className={classNames}
style={directionStyle}
dangerouslySetInnerHTML={content}
lang={status.get('language')}

View File

@ -19,5 +19,6 @@ export const version = getMeta('version');
export const mascot = getMeta('mascot');
export const profile_directory = getMeta('profile_directory');
export const isStaff = getMeta('is_staff');
export const stripFormatting = getMeta('strip_formatting');
export default initialState;

View File

@ -691,30 +691,10 @@
h3,
h4,
h5 {
margin-top: 20px;
margin-bottom: 20px;
}
h1,
h2 {
font-weight: 700;
font-size: 18px;
}
h2 {
font-size: 16px;
}
h3,
h4,
h5 {
font-weight: 500;
}
blockquote {
padding-left: 10px;
border-left: 3px solid $darker-text-color;
color: $darker-text-color;
white-space: normal;
p:last-child {
@ -722,31 +702,70 @@
}
}
b,
strong {
font-weight: 700;
}
em,
i {
font-style: italic;
}
ul,
ol {
margin-left: 1em;
p {
margin: 0;
margin-bottom: 0;
}
}
ul {
list-style-type: disc;
&:not(.rich-text) {
del {
text-decoration: none;
}
}
ol {
list-style-type: decimal;
&.rich-text {
h1,
h2 {
font-weight: 700;
}
h3,
h4,
h5 {
font-weight: 500;
}
b,
strong {
font-weight: 700;
}
em,
i {
font-style: italic;
}
}
&.rich-blocks {
h1,
h2 {
font-size: 18px;
}
h2 {
font-size: 16px;
}
blockquote {
padding-left: 10px;
border-left: 3px solid $darker-text-color;
color: $darker-text-color;
}
ul,
ol {
margin-left: 1em;
}
ul {
list-style-type: disc;
}
ol {
list-style-type: decimal;
}
}
a {

View File

@ -33,6 +33,7 @@ class UserSettingsDecorator
user.settings['hide_network'] = hide_network_preference if change?('setting_hide_network')
user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs')
user.settings['show_application'] = show_application_preference if change?('setting_show_application')
user.settings['strip_formatting'] = strip_formatting_preference if change?('setting_strip_formatting')
end
def merged_notification_emails
@ -107,6 +108,10 @@ class UserSettingsDecorator
boolean_cast_setting 'setting_aggregate_reblogs'
end
def strip_formatting_preference
settings['setting_strip_formatting']
end
def boolean_cast_setting(key)
ActiveModel::Type::Boolean.new.cast(settings[key])
end

View File

@ -104,7 +104,8 @@ class User < ApplicationRecord
delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal,
:reduce_motion, :system_font_ui, :noindex, :theme, :display_media, :hide_network,
:expand_spoilers, :default_language, :aggregate_reblogs, :show_application, to: :settings, prefix: :setting, allow_nil: false
:expand_spoilers, :default_language, :aggregate_reblogs, :show_application,
:strip_formatting, to: :settings, prefix: :setting, allow_nil: false
attr_reader :invite_code
attr_writer :external

View File

@ -23,15 +23,16 @@ class InitialStateSerializer < ActiveModel::Serializer
}
if object.current_account
store[:me] = object.current_account.id.to_s
store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal
store[:boost_modal] = object.current_account.user.setting_boost_modal
store[:delete_modal] = object.current_account.user.setting_delete_modal
store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
store[:display_media] = object.current_account.user.setting_display_media
store[:expand_spoilers] = object.current_account.user.setting_expand_spoilers
store[:reduce_motion] = object.current_account.user.setting_reduce_motion
store[:is_staff] = object.current_account.user.staff?
store[:me] = object.current_account.id.to_s
store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal
store[:boost_modal] = object.current_account.user.setting_boost_modal
store[:delete_modal] = object.current_account.user.setting_delete_modal
store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
store[:display_media] = object.current_account.user.setting_display_media
store[:expand_spoilers] = object.current_account.user.setting_expand_spoilers
store[:reduce_motion] = object.current_account.user.setting_reduce_motion
store[:is_staff] = object.current_account.user.staff?
store[:strip_formatting] = object.current_account.user.setting_strip_formatting
end
store

View File

@ -7,6 +7,7 @@ class REST::PreferencesSerializer < ActiveModel::Serializer
attribute :reading_default_sensitive_media, key: 'reading:expand:media'
attribute :reading_default_sensitive_text, key: 'reading:expand:spoilers'
attribute :reading_strip_formatting, key: 'reading:formatting:strip'
def posting_default_privacy
object.user.setting_default_privacy
@ -27,4 +28,8 @@ class REST::PreferencesSerializer < ActiveModel::Serializer
def reading_default_sensitive_text
object.user.setting_expand_spoilers
end
def reading_strip_formatting
object.user.setting_strip_formatting
end
end

View File

@ -55,6 +55,7 @@
= f.input :setting_aggregate_reblogs, as: :boolean, wrapper: :with_label
.fields-group
= f.input :setting_strip_formatting, collection: ['none', 'blocks', 'all'], wrapper: :with_floating_label, include_blank: false, label_method: lambda { |value| safe_join([I18n.t("statuses.strip_formatting.#{value}"), content_tag(:span, I18n.t("statuses.strip_formatting.#{value}_long"), class: 'hint')]) }, required: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', hint: false
= f.input :setting_auto_play_gif, as: :boolean, wrapper: :with_label
= f.input :setting_expand_spoilers, as: :boolean, wrapper: :with_label
= f.input :setting_reduce_motion, as: :boolean, wrapper: :with_label

View File

@ -15,7 +15,7 @@
= account_action_button(status.account)
.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)}&nbsp;

View File

@ -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)}&nbsp;

View File

@ -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

View File

@ -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

View File

@ -31,6 +31,7 @@ defaults: &defaults
noindex: false
theme: 'mastodon'
aggregate_reblogs: true
strip_formatting: 'none'
notification_emails:
follow: false
reblog: false