~cytrogen/masto-fe

02106153ecbe3de078a3dc3bea5a13775bb87cc5 — prplecake 11 months ago 8eba3f5
[feature] Re-enable auto-unfold CW setting (#46)

Fixes #45

Reviewed-on: https://codeberg.org/superseriousbusiness/masto-fe-standalone/pulls/46
Co-authored-by: prplecake <me@prplecake.com>
Co-committed-by: prplecake <me@prplecake.com>
M app/javascript/flavours/glitch/actions/local_settings.js => app/javascript/flavours/glitch/actions/local_settings.js +1 -10
@@ 1,4 1,4 @@
import { expandSpoilers, disableSwiping } from 'flavours/glitch/initial_state';
import { disableSwiping } from 'flavours/glitch/initial_state';

import { openModal } from './modal';



@@ 7,18 7,9 @@ export const LOCAL_SETTING_DELETE = 'LOCAL_SETTING_DELETE';

export function checkDeprecatedLocalSettings() {
  return (dispatch, getState) => {
    const local_auto_unfold = getState().getIn(['local_settings', 'content_warnings', 'auto_unfold']);
    const local_swipe_to_change_columns = getState().getIn(['local_settings', 'swipe_to_change_columns']);
    let changed_settings = [];

    if (local_auto_unfold !== null && local_auto_unfold !== undefined) {
      if (local_auto_unfold === expandSpoilers) {
        dispatch(deleteLocalSetting(['content_warnings', 'auto_unfold']));
      } else {
        changed_settings.push('user_setting_expand_spoilers');
      }
    }

    if (local_swipe_to_change_columns !== null && local_swipe_to_change_columns !== undefined) {
      if (local_swipe_to_change_columns === !disableSwiping) {
        dispatch(deleteLocalSetting(['swipe_to_change_columns']));

M app/javascript/flavours/glitch/features/local_settings/page/index.jsx => app/javascript/flavours/glitch/features/local_settings/page/index.jsx +6 -23
@@ 8,9 8,6 @@ import ImmutablePropTypes from 'react-immutable-proptypes';


//  Our imports
import { expandSpoilers } from 'flavours/glitch/initial_state';

import DeprecatedLocalSettingsPageItem from './deprecated_item';
import LocalSettingsPageItem from './item';

//  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


@@ 308,35 305,21 @@ class LocalSettingsPage extends PureComponent {
        </LocalSettingsPageItem>
        <section>
          <h2><FormattedMessage id='settings.content_warnings_unfold_opts' defaultMessage='Auto-unfolding options' /></h2>
          <DeprecatedLocalSettingsPageItem
          <LocalSettingsPageItem
            settings={settings}
            item={['content_warnings', 'auto_unfold']}
            onChange={onChange}
            id='mastodon-settings--content_warnings-auto_unfold'
            value={expandSpoilers}
          >
            <FormattedMessage id='settings.enable_content_warnings_auto_unfold' defaultMessage='Automatically unfold content-warnings' />
            <span className='hint'>
              <FormattedMessage
                id='settings.deprecated_setting'
                defaultMessage="This setting is now controlled from Mastodon's {settings_page_link}"
                values={{
                  settings_page_link: (
                    <span>
                      <FormattedMessage
                        id='settings.shared_settings_link'
                        defaultMessage='user preferences'
                      />
                    </span>
                  ),
                }}
              />
            </span>
          </DeprecatedLocalSettingsPageItem>
          </LocalSettingsPageItem>
          <LocalSettingsPageItem
            settings={settings}
            item={['content_warnings', 'filter']}
            id='mastodon-settings--content_warnings-auto_unfold'
            onChange={onChange}
            dependsOn={[['content_warnings', 'auto_unfold']]}
            placeholder={intl.formatMessage(messages.regexp)}
            disabled={!expandSpoilers}
          >
            <FormattedMessage id='settings.content_warnings_filter' defaultMessage='Content warnings to not automatically unfold:' />
          </LocalSettingsPageItem>

M app/javascript/flavours/glitch/reducers/local_settings.js => app/javascript/flavours/glitch/reducers/local_settings.js +1 -0
@@ 23,6 23,7 @@ const initialState = ImmutableMap({
  tag_misleading_links: true,
  rewrite_mentions: 'no',
  content_warnings : ImmutableMap({
    auto_unfold  : false,
    filter       : null,
    media_outside: true,
    shared_state : true,

M app/javascript/flavours/glitch/utils/content_warning.js => app/javascript/flavours/glitch/utils/content_warning.js +6 -6
@@ 1,9 1,9 @@
import { expandSpoilers } from 'flavours/glitch/initial_state';

function _autoUnfoldCW(spoiler_text, skip_unfold_regex) {
  if (!expandSpoilers)
function _autoUnfoldCW(spoiler_text, settings) {
  if (!settings.getIn(['content_warnings', 'auto_unfold']))
    return false;

  const skip_unfold_regex = settings.getIn(['content_warnings', 'filter']);

  if (!skip_unfold_regex)
    return true;



@@ 20,12 20,12 @@ function _autoUnfoldCW(spoiler_text, skip_unfold_regex) {
}

export function autoHideCW(settings, spoiler_text) {
  return !_autoUnfoldCW(spoiler_text, settings.getIn(['content_warnings', 'filter']));
  return !_autoUnfoldCW(spoiler_text, settings);
}

export function autoUnfoldCW(settings, status) {
  if (!status)
    return false;

  return _autoUnfoldCW(status.get('spoiler_text'), settings.getIn(['content_warnings', 'filter']));
  return _autoUnfoldCW(status.get('spoiler_text'), settings);
}