Migrate glitch-soc local notification settings to upstream system
This commit is contained in:
parent
d1d9646bfc
commit
860b7f9653
3 changed files with 16 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { Iterable, fromJS } from 'immutable';
|
import { Iterable, fromJS } from 'immutable';
|
||||||
import { hydrateCompose } from './compose';
|
import { hydrateCompose } from './compose';
|
||||||
import { importFetchedAccounts } from './importer';
|
import { importFetchedAccounts } from './importer';
|
||||||
|
import { saveSettings } from './settings';
|
||||||
|
|
||||||
export const STORE_HYDRATE = 'STORE_HYDRATE';
|
export const STORE_HYDRATE = 'STORE_HYDRATE';
|
||||||
export const STORE_HYDRATE_LAZY = 'STORE_HYDRATE_LAZY';
|
export const STORE_HYDRATE_LAZY = 'STORE_HYDRATE_LAZY';
|
||||||
|
@ -9,9 +10,22 @@ const convertState = rawState =>
|
||||||
fromJS(rawState, (k, v) =>
|
fromJS(rawState, (k, v) =>
|
||||||
Iterable.isIndexed(v) ? v.toList() : v.toMap());
|
Iterable.isIndexed(v) ? v.toList() : v.toMap());
|
||||||
|
|
||||||
|
const applyMigrations = (state) => {
|
||||||
|
return state.withMutations(state => {
|
||||||
|
// Migrate glitch-soc local-only “Show unread marker” setting to Mastodon's setting
|
||||||
|
if (state.getIn(['local_settings', 'notifications', 'show_unread']) !== undefined) {
|
||||||
|
// Only change if the Mastodon setting does not deviate from default
|
||||||
|
if (state.getIn(['settings', 'notifications', 'showUnread']) !== false) {
|
||||||
|
state.setIn(['settings', 'notifications', 'showUnread'], state.getIn(['local_settings', 'notifications', 'show_unread']));
|
||||||
|
}
|
||||||
|
state.removeIn(['local_settings', 'notifications', 'show_unread'])
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export function hydrateStore(rawState) {
|
export function hydrateStore(rawState) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
const state = convertState(rawState);
|
const state = applyMigrations(convertState(rawState));
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: STORE_HYDRATE,
|
type: STORE_HYDRATE,
|
||||||
|
@ -20,5 +34,6 @@ export function hydrateStore(rawState) {
|
||||||
|
|
||||||
dispatch(hydrateCompose());
|
dispatch(hydrateCompose());
|
||||||
dispatch(importFetchedAccounts(Object.values(rawState.accounts)));
|
dispatch(importFetchedAccounts(Object.values(rawState.accounts)));
|
||||||
|
dispatch(saveSettings());
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -113,14 +113,6 @@ class LocalSettingsPage extends React.PureComponent {
|
||||||
<FormattedMessage id='settings.notifications.favicon_badge' defaultMessage='Unread notifications favicon badge' />
|
<FormattedMessage id='settings.notifications.favicon_badge' defaultMessage='Unread notifications favicon badge' />
|
||||||
<span className='hint'><FormattedMessage id='settings.notifications.favicon_badge.hint' defaultMessage="Add a badge for unread notifications to the favicon" /></span>
|
<span className='hint'><FormattedMessage id='settings.notifications.favicon_badge.hint' defaultMessage="Add a badge for unread notifications to the favicon" /></span>
|
||||||
</LocalSettingsPageItem>
|
</LocalSettingsPageItem>
|
||||||
<LocalSettingsPageItem
|
|
||||||
settings={settings}
|
|
||||||
item={['notifications', 'show_unread']}
|
|
||||||
id='mastodon-settings--notifications-show_unread'
|
|
||||||
onChange={onChange}
|
|
||||||
>
|
|
||||||
<FormattedMessage id='settings.notifications.show_unread' defaultMessage='Show unread marker' />
|
|
||||||
</LocalSettingsPageItem>
|
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h2><FormattedMessage id='settings.layout_opts' defaultMessage='Layout options' /></h2>
|
<h2><FormattedMessage id='settings.layout_opts' defaultMessage='Layout options' /></h2>
|
||||||
|
|
|
@ -55,7 +55,6 @@ const initialState = ImmutableMap({
|
||||||
notifications : ImmutableMap({
|
notifications : ImmutableMap({
|
||||||
favicon_badge : false,
|
favicon_badge : false,
|
||||||
tab_badge : true,
|
tab_badge : true,
|
||||||
show_unread : true,
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue