2025-01-08 17:25:41 +01:00
|
|
|
import { fromJS, isIndexed } from 'immutable';
|
2023-05-28 16:38:10 +02:00
|
|
|
|
2018-08-28 13:52:18 +02:00
|
|
|
import { hydrateCompose } from './compose';
|
2019-03-05 20:15:43 +01:00
|
|
|
import { importFetchedAccounts } from './importer';
|
2023-09-07 14:56:19 +02:00
|
|
|
import { hydrateSearch } from './search';
|
2021-03-19 13:33:46 +01:00
|
|
|
import { saveSettings } from './settings';
|
2017-01-09 12:37:15 +01:00
|
|
|
|
|
|
|
export const STORE_HYDRATE = 'STORE_HYDRATE';
|
2017-07-08 00:06:02 +02:00
|
|
|
export const STORE_HYDRATE_LAZY = 'STORE_HYDRATE_LAZY';
|
2017-01-09 12:37:15 +01:00
|
|
|
|
|
|
|
const convertState = rawState =>
|
2017-07-11 01:00:14 +02:00
|
|
|
fromJS(rawState, (k, v) =>
|
2025-01-08 17:25:41 +01:00
|
|
|
isIndexed(v) ? v.toList() : v.toMap());
|
2017-01-09 12:37:15 +01:00
|
|
|
|
2021-03-19 13:33:46 +01:00
|
|
|
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']));
|
|
|
|
}
|
2023-02-03 20:52:07 +01:00
|
|
|
state.removeIn(['local_settings', 'notifications', 'show_unread']);
|
2021-03-19 13:33:46 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-11-03 16:00:03 +01:00
|
|
|
|
2017-01-09 12:37:15 +01:00
|
|
|
export function hydrateStore(rawState) {
|
2018-08-28 13:52:18 +02:00
|
|
|
return dispatch => {
|
2021-03-19 13:33:46 +01:00
|
|
|
const state = applyMigrations(convertState(rawState));
|
2017-01-09 12:37:15 +01:00
|
|
|
|
2018-08-28 13:52:18 +02:00
|
|
|
dispatch({
|
|
|
|
type: STORE_HYDRATE,
|
|
|
|
state,
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch(hydrateCompose());
|
2023-09-07 14:56:19 +02:00
|
|
|
dispatch(hydrateSearch());
|
2019-03-05 20:15:43 +01:00
|
|
|
dispatch(importFetchedAccounts(Object.values(rawState.accounts)));
|
2021-03-19 13:33:46 +01:00
|
|
|
dispatch(saveSettings());
|
2017-01-09 12:37:15 +01:00
|
|
|
};
|
2023-02-03 20:52:07 +01:00
|
|
|
}
|