Don't persist default settings

Only persist settings if they've been overridden by the user
stable/1.0.x
Alex Gleason 2020-04-28 13:49:39 -05:00
rodzic 178fdf8818
commit a60c47bb19
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
31 zmienionych plików z 86 dodań i 57 usunięć

Wyświetl plik

@ -11,6 +11,7 @@ import { showAlertForError } from './alerts';
import { showAlert } from './alerts';
import { defineMessages } from 'react-intl';
import { openModal, closeModal } from './modal';
import { getSettings } from './settings';
let cancelFetchComposeSuggestionsAccounts;
@ -136,7 +137,7 @@ export function handleComposeSubmit(dispatch, getState, response, status) {
if (timeline && timeline.get('items').size > 0 && timeline.getIn(['items', 0]) !== null && timeline.get('online')) {
let dequeueArgs = {};
if (timelineId === 'community') dequeueArgs.onlyMedia = getState().getIn(['settings', 'community', 'other', 'onlyMedia']);
if (timelineId === 'community') dequeueArgs.onlyMedia = getSettings(getState()).getIn(['community', 'other', 'onlyMedia']);
dispatch(dequeueTimeline(timelineId, null, dequeueArgs));
dispatch(updateTimeline(timelineId, { ...response.data }));
}

Wyświetl plik

@ -1,3 +1,4 @@
import { getSettings } from '../settings';
import { normalizeAccount, normalizeStatus, normalizePoll } from './normalizer';
export const ACCOUNT_IMPORT = 'ACCOUNT_IMPORT';
@ -65,7 +66,7 @@ export function importFetchedStatuses(statuses) {
function processStatus(status) {
const normalOldStatus = getState().getIn(['statuses', status.id]);
const expandSpoilers = getState().getIn(['settings', 'expandSpoilers']);
const expandSpoilers = getSettings(getState()).get('expandSpoilers');
pushUnique(normalStatuses, normalizeStatus(status, normalOldStatus, expandSpoilers));
pushUnique(accounts, status.account);

Wyświetl plik

@ -8,7 +8,7 @@ import {
importFetchedStatus,
importFetchedStatuses,
} from './importer';
import { saveSettings } from './settings';
import { getSettings, saveSettings } from './settings';
import { defineMessages } from 'react-intl';
import { List as ImmutableList } from 'immutable';
import { unescapeHTML } from '../utils/html';
@ -50,7 +50,7 @@ const fetchRelatedRelationships = (dispatch, notifications) => {
export function updateNotifications(notification, intlMessages, intlLocale) {
return (dispatch, getState) => {
const showInColumn = getState().getIn(['settings', 'notifications', 'shows', notification.type], true);
const showInColumn = getSettings(getState()).getIn(['notifications', 'shows', notification.type], true);
if (showInColumn) {
dispatch(importFetchedAccount(notification.account));
@ -71,9 +71,9 @@ export function updateNotifications(notification, intlMessages, intlLocale) {
export function updateNotificationsQueue(notification, intlMessages, intlLocale, curPath) {
return (dispatch, getState) => {
const showAlert = getState().getIn(['settings', 'notifications', 'alerts', notification.type], true);
const showAlert = getSettings(getState()).getIn(['notifications', 'alerts', notification.type], true);
const filters = getFilters(getState(), { contextType: 'notifications' });
const playSound = getState().getIn(['settings', 'notifications', 'sounds', notification.type], true);
const playSound = getSettings(getState()).getIn(['notifications', 'sounds', notification.type], true);
let filtered = false;
@ -140,7 +140,7 @@ export function dequeueNotifications() {
};
};
const excludeTypesFromSettings = state => state.getIn(['settings', 'notifications', 'shows']).filter(enabled => !enabled).keySeq().toJS();
const excludeTypesFromSettings = getState => getSettings(getState()).getIn(['notifications', 'shows']).filter(enabled => !enabled).keySeq().toJS();
const excludeTypesFromFilter = filter => {
const allTypes = ImmutableList(['follow', 'favourite', 'reblog', 'mention', 'poll']);
@ -153,7 +153,7 @@ export function expandNotifications({ maxId } = {}, done = noOp) {
return (dispatch, getState) => {
if (!getState().get('me')) return;
const activeFilter = getState().getIn(['settings', 'notifications', 'quickFilter', 'active']);
const activeFilter = getSettings(getState()).getIn(['notifications', 'quickFilter', 'active']);
const notifications = getState().get('notifications');
const isLoadingMore = !!maxId;
@ -165,7 +165,7 @@ export function expandNotifications({ maxId } = {}, done = noOp) {
const params = {
max_id: maxId,
exclude_types: activeFilter === 'all'
? excludeTypesFromSettings(getState())
? excludeTypesFromSettings(getState)
: excludeTypesFromFilter(activeFilter),
};

Wyświetl plik

@ -98,9 +98,7 @@ const defaultSettings = ImmutableMap({
}),
});
export function getSettings(getState) {
const state = getState();
export function getSettings(state) {
const soapboxSettings = state.getIn(['soapbox', 'defaultSettings']);
return defaultSettings
.mergeDeep(soapboxSettings)
@ -122,7 +120,7 @@ export function changeSetting(path, value) {
const debouncedSave = debounce((dispatch, getState) => {
const state = getState();
if (!state.get('me')) return;
if (state.getIn(['settings', 'saved'])) return;
if (getSettings(state).getIn(['saved'])) return;
const data = state.get('settings').delete('saved').toJS();

Wyświetl plik

@ -2,9 +2,10 @@ import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { getSettings } from 'gabsocial/actions/settings';
const mapStateToProps = state => ({
animate: state.getIn(['settings', 'autoPlayGif']),
animate: getSettings(state).get('autoPlayGif'),
});
export default @connect(mapStateToProps)

Wyświetl plik

@ -2,9 +2,10 @@ import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { getSettings } from 'gabsocial/actions/settings';
const mapStateToProps = state => ({
animate: state.getIn(['settings', 'autoPlayGif']),
animate: getSettings(state).get('autoPlayGif'),
});
export default @connect(mapStateToProps)

Wyświetl plik

@ -2,9 +2,10 @@ import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { getSettings } from 'gabsocial/actions/settings';
const mapStateToProps = state => ({
animate: state.getIn(['settings', 'autoPlayGif']),
animate: getSettings(state).get('autoPlayGif'),
});
export default @connect(mapStateToProps)

Wyświetl plik

@ -11,13 +11,14 @@ import { displayMedia } from '../initial_state';
import { decode } from 'blurhash';
import { isPanoramic, isPortrait, isNonConformingRatio, minimumAspectRatio, maximumAspectRatio } from '../utils/media_aspect_ratio';
import { Map as ImmutableMap } from 'immutable';
import { getSettings } from 'gabsocial/actions/settings';
const messages = defineMessages({
toggle_visible: { id: 'media_gallery.toggle_visible', defaultMessage: 'Toggle visibility' },
});
const mapStateToProps = state => ({
autoPlayGif: state.getIn(['settings', 'autoPlayGif']),
autoPlayGif: getSettings(state).get('autoPlayGif'),
});
@connect(mapStateToProps)

Wyświetl plik

@ -13,6 +13,7 @@ import {
} from '../actions/accounts';
import { openModal } from '../actions/modal';
import { initMuteModal } from '../actions/mutes';
import { getSettings } from '../actions/settings';
const messages = defineMessages({
unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' },
@ -32,7 +33,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onFollow(account) {
dispatch((_, getState) => {
const unfollowModal = getState().getIn(['settings', 'unfollowModal']);
const unfollowModal = getSettings(getState()).get('unfollowModal');
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
if (unfollowModal) {
dispatch(openModal('CONFIRM', {

Wyświetl plik

@ -22,6 +22,7 @@ import { fetchInstance } from 'gabsocial/actions/instance';
import { fetchSoapboxConfig } from 'gabsocial/actions/soapbox';
import { fetchMe } from 'gabsocial/actions/me';
import PublicLayout from 'gabsocial/features/public_layout';
import { getSettings } from 'gabsocial/actions/settings';
const { localeData, messages } = getLocale();
addLocaleData(localeData);
@ -39,15 +40,16 @@ const mapStateToProps = (state) => {
const me = state.get('me');
const account = state.getIn(['accounts', me]);
const showIntroduction = account ? state.getIn(['settings', 'introductionVersion'], 0) < INTRODUCTION_VERSION : false;
const settings = getSettings(state);
return {
showIntroduction,
me,
theme: state.getIn(['settings', 'theme']),
reduceMotion: state.getIn(['settings', 'reduceMotion']),
systemFont: state.getIn(['settings', 'systemFont']),
dyslexicFont: state.getIn(['settings', 'dyslexicFont']),
demetricator: state.getIn(['settings', 'demetricator']),
theme: settings.get('theme'),
reduceMotion: settings.get('reduceMotion'),
systemFont: settings.get('systemFont'),
dyslexicFont: settings.get('dyslexicFont'),
demetricator: settings.get('demetricator'),
};
};

Wyświetl plik

@ -32,6 +32,7 @@ import {
createRemovedAccount,
groupRemoveStatus,
} from '../actions/groups';
import { getSettings } from '../actions/settings';
const messages = defineMessages({
deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
@ -81,7 +82,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onReblog(status, e) {
dispatch((_, getState) => {
const boostModal = getState().getIn(['settings', 'boostModal']);
const boostModal = getSettings(getState()).get('boostModal');
if (e.shiftKey || !boostModal) {
this.onModalReblog(status);
} else {
@ -115,7 +116,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onDelete(status, history, withRedraft = false) {
dispatch((_, getState) => {
const deleteModal = getState().getIn(['settings', 'deleteModal']);
const deleteModal = getSettings(getState()).get('deleteModal');
if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft));
} else {

Wyświetl plik

@ -15,6 +15,7 @@ import { NavLink } from 'react-router-dom';
import DropdownMenuContainer from 'gabsocial/containers/dropdown_menu_container';
import ProfileInfoPanel from '../../ui/components/profile_info_panel';
import { debounce } from 'lodash';
import { getSettings } from 'gabsocial/actions/settings';
const messages = defineMessages({
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
@ -52,7 +53,7 @@ const mapStateToProps = state => {
return {
me,
isStaff: isStaff(state.getIn(['accounts', me])),
autoPlayGif: state.getIn(['settings', 'autoPlayGif']),
autoPlayGif: getSettings(state).get('autoPlayGif'),
};
};

Wyświetl plik

@ -8,9 +8,10 @@ import { displayMedia } from 'gabsocial/initial_state';
import classNames from 'classnames';
import { decode } from 'blurhash';
import { isIOS } from 'gabsocial/is_mobile';
import { getSettings } from 'gabsocial/actions/settings';
const mapStateToProps = state => ({
autoPlayGif: state.getIn(['settings', 'autoPlayGif']),
autoPlayGif: getSettings(state).get('autoPlayGif'),
});
export default @connect(mapStateToProps)

Wyświetl plik

@ -21,6 +21,7 @@ import { openModal } from '../../../actions/modal';
import { blockDomain, unblockDomain } from '../../../actions/domain_blocks';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { List as ImmutableList } from 'immutable';
import { getSettings } from 'gabsocial/actions/settings';
const messages = defineMessages({
unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' },
@ -44,7 +45,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onFollow(account) {
dispatch((_, getState) => {
const unfollowModal = getState().getIn(['settings', 'unfollowModal']);
const unfollowModal = getSettings(getState()).get('unfollowModal');
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
if (unfollowModal) {
dispatch(openModal('CONFIRM', {

Wyświetl plik

@ -1,9 +1,9 @@
import { connect } from 'react-redux';
import ColumnSettings from '../components/column_settings';
import { changeSetting } from '../../../actions/settings';
import { getSettings, changeSetting } from '../../../actions/settings';
const mapStateToProps = state => ({
settings: state.getIn(['settings', 'community']),
settings: getSettings(state).get('community'),
});
const mapDispatchToProps = (dispatch) => {

Wyświetl plik

@ -8,13 +8,14 @@ import ColumnSettingsContainer from './containers/column_settings_container';
import HomeColumnHeader from '../../components/home_column_header';
import { expandCommunityTimeline } from '../../actions/timelines';
import { connectCommunityStream } from '../../actions/streaming';
import { getSettings } from 'gabsocial/actions/settings';
const messages = defineMessages({
title: { id: 'column.community', defaultMessage: 'Local timeline' },
});
const mapStateToProps = state => {
const onlyMedia = state.getIn(['settings', 'community', 'other', 'onlyMedia']);
const onlyMedia = getSettings(state).getIn(['community', 'other', 'onlyMedia']);
const timelineId = 'community';

Wyświetl plik

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import EmojiPickerDropdown from '../components/emoji_picker_dropdown';
import { changeSetting } from '../../../actions/settings';
import { getSettings, changeSetting } from '../../../actions/settings';
import { createSelector } from 'reselect';
import { Map as ImmutableMap } from 'immutable';
import { useEmoji } from '../../../actions/emojis';
@ -62,7 +62,7 @@ const getCustomEmojis = createSelector([
const mapStateToProps = state => ({
custom_emojis: getCustomEmojis(state),
skinTone: state.getIn(['settings', 'skinTone']),
skinTone: getSettings(state).get('skinTone'),
frequentlyUsedEmojis: getFrequentlyUsedEmojis(state),
});

Wyświetl plik

@ -13,6 +13,7 @@ import spring from 'react-motion/lib/spring';
import SearchResultsContainer from './containers/search_results_container';
import { changeComposing } from '../../actions/compose';
import Icon from 'gabsocial/components/icon';
import { getSettings } from 'gabsocial/actions/settings';
const messages = defineMessages({
start: { id: 'getting_started.heading', defaultMessage: 'Getting started' },
@ -26,7 +27,7 @@ const messages = defineMessages({
});
const mapStateToProps = (state, ownProps) => ({
columns: state.getIn(['settings', 'columns']),
columns: getSettings(state).get('columns'),
showSearch: ownProps.multiColumn ? state.getIn(['search', 'submitted']) && !state.getIn(['search', 'hidden']) : ownProps.isSearchPage,
});

Wyświetl plik

@ -1,9 +1,13 @@
import { connect } from 'react-redux';
import ColumnSettings from '../components/column_settings';
import { changeSetting, saveSettings } from '../../../actions/settings';
import {
getSettings,
changeSetting,
saveSettings,
} from '../../../actions/settings';
const mapStateToProps = state => ({
settings: state.getIn(['settings', 'home']),
settings: getSettings(state).get('home'),
});
const mapDispatchToProps = dispatch => ({

Wyświetl plik

@ -1,7 +1,7 @@
import { connect } from 'react-redux';
import { defineMessages, injectIntl } from 'react-intl';
import ColumnSettings from '../components/column_settings';
import { changeSetting } from '../../../actions/settings';
import { getSettings, changeSetting } from '../../../actions/settings';
import { setFilter } from '../../../actions/notifications';
import { clearNotifications } from '../../../actions/notifications';
import { changeAlerts as changePushNotifications } from '../../../actions/push_notifications';
@ -13,7 +13,7 @@ const messages = defineMessages({
});
const mapStateToProps = state => ({
settings: state.getIn(['settings', 'notifications']),
settings: getSettings(state).get('notifications'),
pushSettings: state.get('push_notifications'),
});

Wyświetl plik

@ -1,11 +1,15 @@
import { connect } from 'react-redux';
import FilterBar from '../components/filter_bar';
import { setFilter } from '../../../actions/notifications';
import { getSettings } from 'gabsocial/actions/settings';
const makeMapStateToProps = state => ({
selectedFilter: state.getIn(['settings', 'notifications', 'quickFilter', 'active']),
advancedMode: state.getIn(['settings', 'notifications', 'quickFilter', 'advanced']),
});
const makeMapStateToProps = state => {
const settings = getSettings(state);
return {
selectedFilter: settings.getIn(['notifications', 'quickFilter', 'active']),
advancedMode: settings.getIn(['notifications', 'quickFilter', 'advanced']),
};
};
const mapDispatchToProps = (dispatch) => ({
selectFilter(newActiveFilter) {

Wyświetl plik

@ -13,6 +13,7 @@ import {
hideStatus,
revealStatus,
} from '../../../actions/statuses';
import { getSettings } from 'gabsocial/actions/settings';
const makeMapStateToProps = () => {
const getNotification = makeGetNotification();
@ -40,7 +41,7 @@ const mapDispatchToProps = dispatch => ({
onReblog(status, e) {
dispatch((_, getState) => {
const boostModal = getState().getIn(['settings', 'boostModal']);
const boostModal = getSettings(getState()).get('boostModal');
if (status.get('reblogged')) {
dispatch(unreblog(status));
} else {

Wyświetl plik

@ -19,15 +19,16 @@ import { debounce } from 'lodash';
import ScrollableList from '../../components/scrollable_list';
import LoadGap from '../../components/load_gap';
import TimelineQueueButtonHeader from '../../components/timeline_queue_button_header';
import { getSettings } from 'gabsocial/actions/settings';
const messages = defineMessages({
title: { id: 'column.notifications', defaultMessage: 'Notifications' },
});
const getNotifications = createSelector([
state => state.getIn(['settings', 'notifications', 'quickFilter', 'show']),
state => state.getIn(['settings', 'notifications', 'quickFilter', 'active']),
state => ImmutableList(state.getIn(['settings', 'notifications', 'shows']).filter(item => !item).keys()),
state => getSettings(state).getIn(['notifications', 'quickFilter', 'show']),
state => getSettings(state).getIn(['notifications', 'quickFilter', 'active']),
state => ImmutableList(getSettings(state).getIn(['notifications', 'shows']).filter(item => !item).keys()),
state => state.getIn(['notifications', 'items']),
], (showFilterBar, allowedType, excludedTypes, notifications) => {
if (!showFilterBar || allowedType === 'all') {
@ -40,7 +41,7 @@ const getNotifications = createSelector([
});
const mapStateToProps = state => ({
showFilterBar: state.getIn(['settings', 'notifications', 'quickFilter', 'show']),
showFilterBar: getSettings(state).getIn(['notifications', 'quickFilter', 'show']),
notifications: getNotifications(state),
isLoading: state.getIn(['notifications', 'isLoading'], true),
isUnread: state.getIn(['notifications', 'unread']) > 0,

Wyświetl plik

@ -1,9 +1,9 @@
import { connect } from 'react-redux';
import ColumnSettings from '../components/column_settings';
import { changeSetting } from '../../../actions/settings';
import { getSettings, changeSetting } from '../../../actions/settings';
const mapStateToProps = state => ({
settings: state.getIn(['settings', 'public']),
settings: getSettings(state).get('public'),
});
const mapDispatchToProps = (dispatch) => {

Wyświetl plik

@ -10,13 +10,14 @@ import ExplanationBox from '../ui/components/explanation_box';
import { expandPublicTimeline } from '../../actions/timelines';
import { connectPublicStream } from '../../actions/streaming';
import { Link } from 'react-router-dom';
import { getSettings } from 'gabsocial/actions/settings';
const messages = defineMessages({
title: { id: 'column.public', defaultMessage: 'Federated timeline' },
});
const mapStateToProps = state => {
const onlyMedia = state.getIn(['settings', 'public', 'other', 'onlyMedia']);
const onlyMedia = getSettings(state).getIn(['public', 'other', 'onlyMedia']);
const timelineId = 'public';

Wyświetl plik

@ -28,6 +28,7 @@ import { initReport } from '../../../actions/reports';
import { openModal } from '../../../actions/modal';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { showAlertForError } from '../../../actions/alerts';
import { getSettings } from 'gabsocial/actions/settings';
const messages = defineMessages({
deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
@ -74,7 +75,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onReblog(status, e) {
dispatch((_, getState) => {
const boostModal = getState().getIn(['settings', 'boostModal']);
const boostModal = getSettings(getState()).get('boostModal');
if (status.get('reblogged')) {
dispatch(unreblog(status));
} else {
@ -112,7 +113,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onDelete(status, history, withRedraft = false) {
dispatch((_, getState) => {
const deleteModal = getState().getIn(['settings', 'deleteModal']);
const deleteModal = getSettings(getState()).get('deleteModal');
if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft));
} else {

Wyświetl plik

@ -42,6 +42,7 @@ import { HotKeys } from 'react-hotkeys';
import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../ui/util/fullscreen';
import { textForScreenReader, defaultMediaVisibility } from '../../components/status';
import Icon from 'gabsocial/components/icon';
import { getSettings } from 'gabsocial/actions/settings';
const messages = defineMessages({
deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
@ -195,7 +196,7 @@ class Status extends ImmutablePureComponent {
handleReblogClick = (status, e) => {
this.props.dispatch((_, getState) => {
const boostModal = getState().getIn(['settings', 'boostModal']);
const boostModal = getSettings(getState()).get('boostModal');
if (status.get('reblogged')) {
this.props.dispatch(unreblog(status));
} else {
@ -212,7 +213,7 @@ class Status extends ImmutablePureComponent {
const { dispatch, intl } = this.props;
this.props.dispatch((_, getState) => {
const deleteModal = getState().getIn(['settings', 'deleteModal']);
const deleteModal = getSettings(getState()).get('deleteModal');
if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft));
} else {

Wyświetl plik

@ -9,6 +9,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
import Avatar from 'gabsocial/components/avatar';
import { shortNumberFormat } from 'gabsocial/utils/numbers';
import { acctFull } from 'gabsocial/utils/accounts';
import { getSettings } from 'gabsocial/actions/settings';
class UserPanel extends ImmutablePureComponent {
@ -90,7 +91,7 @@ const mapStateToProps = state => {
return {
account: getAccount(state, me),
autoPlayGif: state.getIn(['settings', 'autoPlayGif']),
autoPlayGif: getSettings(state).get('autoPlayGif'),
};
};

Wyświetl plik

@ -1,8 +1,9 @@
import { connect } from 'react-redux';
import ColumnsArea from '../components/columns_area';
import { getSettings } from 'gabsocial/actions/settings';
const mapStateToProps = state => ({
columns: state.getIn(['settings', 'columns']),
columns: getSettings(state).get('columns'),
});
export default connect(mapStateToProps, null, null, { forwardRef: true })(ColumnsArea);

Wyświetl plik

@ -9,7 +9,7 @@ import uuid from '../uuid';
// Default settings are in action/settings.js
//
// Settings should be accessed with `getSettings(getState).getIn(...)`
// Settings should be accessed with `getSettings(getState()).getIn(...)`
// instead of directly from the state.
const initialState = ImmutableMap({
saved: true,

Wyświetl plik

@ -16,5 +16,6 @@
},
"defaultSettings": {
"autoPlayGif": false,
"theme": "lime"
},
}