small sync refactor cleaning up reducers (#7403)
This commit is contained in:
parent
220021964d
commit
78fb559fa2
11 changed files with 35 additions and 32 deletions
|
@ -448,7 +448,7 @@ export const SYNC_APPLY_FAILED = 'SYNC_APPLY_FAILED';
|
|||
export const SYNC_APPLY_BAD_PASSWORD = 'SYNC_APPLY_BAD_PASSWORD';
|
||||
export const SYNC_RESET = 'SYNC_RESET';
|
||||
export const SYNC_FATAL_ERROR = 'SYNC_FATAL_ERROR';
|
||||
export const USER_STATE_POPULATE = 'USER_STATE_POPULATE';
|
||||
export const SYNC_STATE_POPULATE = 'SYNC_STATE_POPULATE';
|
||||
|
||||
export const REACTIONS_LIST_STARTED = 'REACTIONS_LIST_STARTED';
|
||||
export const REACTIONS_LIST_FAILED = 'REACTIONS_LIST_FAILED';
|
||||
|
|
|
@ -575,19 +575,13 @@ export function doGetAndPopulatePreferences() {
|
|||
const syncEnabled = makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state);
|
||||
const hasVerifiedEmail = state.user && state.user.user && state.user.user.has_verified_email;
|
||||
let preferenceKey;
|
||||
// @if TARGET='app'
|
||||
preferenceKey = syncEnabled && hasVerifiedEmail ? 'shared' : 'local';
|
||||
// @endif
|
||||
// @if TARGET='web'
|
||||
preferenceKey = 'shared';
|
||||
// @endif
|
||||
|
||||
function successCb(savedPreferences) {
|
||||
const successState = getState();
|
||||
const daemonSettings = selectDaemonSettings(successState);
|
||||
if (savedPreferences !== null) {
|
||||
dispatch(doPopulateSharedUserState(savedPreferences));
|
||||
// @if TARGET='app'
|
||||
|
||||
const { settings } = savedPreferences.value;
|
||||
if (settings) {
|
||||
|
@ -602,9 +596,9 @@ export function doGetAndPopulatePreferences() {
|
|||
}
|
||||
}
|
||||
}
|
||||
// probably set commentServer here instead of in doPopulateSharedUserState()
|
||||
});
|
||||
}
|
||||
// @endif
|
||||
} else {
|
||||
dispatch(doSetPrefsReady());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// @flow
|
||||
import * as ACTIONS from 'constants/action_types';
|
||||
import * as SETTINGS from 'constants/settings';
|
||||
import * as SHARED_PREFERENCES from 'constants/shared_preferences';
|
||||
import { Lbryio } from 'lbryinc';
|
||||
import Lbry from 'lbry';
|
||||
import { doWalletEncrypt, doWalletDecrypt } from 'redux/actions/wallet';
|
||||
|
@ -14,12 +15,14 @@ import { makeSelectClientSetting } from 'redux/selectors/settings';
|
|||
import { getSavedPassword } from 'util/saved-passwords';
|
||||
import { doAnalyticsTagSync, doHandleSyncComplete } from 'redux/actions/app';
|
||||
import { selectUserVerifiedEmail } from 'redux/selectors/user';
|
||||
import Comments from 'comments';
|
||||
import { getSubsetFromKeysArray } from 'util/sync-settings';
|
||||
|
||||
let syncTimer = null;
|
||||
const SYNC_INTERVAL = 1000 * 60 * 5; // 5 minutes
|
||||
const NO_WALLET_ERROR = 'no wallet found for this user';
|
||||
const BAD_PASSWORD_ERROR_NAME = 'InvalidPasswordError';
|
||||
|
||||
const { CLIENT_SYNC_KEYS } = SHARED_PREFERENCES;
|
||||
export function doSetDefaultAccount(success: () => void, failure: (string) => void) {
|
||||
return (dispatch: Dispatch) => {
|
||||
dispatch({
|
||||
|
@ -429,8 +432,14 @@ function extractUserState(rawObj: SharedData) {
|
|||
return {};
|
||||
}
|
||||
|
||||
/* This action function should anything SYNC_STATE_POPULATE needs to trigger */
|
||||
export function doPopulateSharedUserState(sharedSettings: any) {
|
||||
return (dispatch: Dispatch) => {
|
||||
return (dispatch: Dispatch, getState: GetState) => {
|
||||
const state = getState();
|
||||
const {
|
||||
settings: { clientSettings: currentClientSettings },
|
||||
} = state;
|
||||
|
||||
const {
|
||||
subscriptions,
|
||||
following,
|
||||
|
@ -445,15 +454,25 @@ export function doPopulateSharedUserState(sharedSettings: any) {
|
|||
builtinCollections,
|
||||
savedCollections,
|
||||
} = extractUserState(sharedSettings);
|
||||
const selectedSettings = settings ? getSubsetFromKeysArray(settings, CLIENT_SYNC_KEYS) : {};
|
||||
const mergedClientSettings = { ...currentClientSettings, ...selectedSettings };
|
||||
// possibly move to doGetAndPopulate... in success callback
|
||||
Comments.setServerUrl(
|
||||
mergedClientSettings[SETTINGS.CUSTOM_COMMENTS_SERVER_ENABLED]
|
||||
? mergedClientSettings[SETTINGS.CUSTOM_COMMENTS_SERVER_URL]
|
||||
: undefined
|
||||
);
|
||||
|
||||
dispatch({
|
||||
type: ACTIONS.USER_STATE_POPULATE,
|
||||
type: ACTIONS.SYNC_STATE_POPULATE,
|
||||
data: {
|
||||
subscriptions,
|
||||
following,
|
||||
tags,
|
||||
blocked,
|
||||
coinSwapCodes: coin_swap_codes,
|
||||
settings,
|
||||
walletPrefSettings: settings,
|
||||
mergedClientSettings,
|
||||
welcomeVersion: app_welcome_version,
|
||||
allowAnalytics: sharing_3P,
|
||||
unpublishedCollections,
|
||||
|
|
|
@ -317,7 +317,7 @@ reducers[ACTIONS.SET_INCOGNITO] = (state, action) => {
|
|||
};
|
||||
};
|
||||
|
||||
reducers[ACTIONS.USER_STATE_POPULATE] = (state, action) => {
|
||||
reducers[ACTIONS.SYNC_STATE_POPULATE] = (state, action) => {
|
||||
const { welcomeVersion, allowAnalytics } = action.data;
|
||||
return {
|
||||
...state,
|
||||
|
|
|
@ -23,7 +23,7 @@ export default handleActions(
|
|||
blockedChannels: newBlockedChannels,
|
||||
};
|
||||
},
|
||||
[ACTIONS.USER_STATE_POPULATE]: (state: BlocklistState, action: { data: { blocked: ?Array<string> } }) => {
|
||||
[ACTIONS.SYNC_STATE_POPULATE]: (state: BlocklistState, action: { data: { blocked: ?Array<string> } }) => {
|
||||
const { blocked } = action.data;
|
||||
const sanitizedBlocked = blocked && blocked.filter((e) => typeof e === 'string');
|
||||
return {
|
||||
|
|
|
@ -117,7 +117,7 @@ export default handleActions(
|
|||
coinSwaps: newCoinSwaps,
|
||||
};
|
||||
},
|
||||
[ACTIONS.USER_STATE_POPULATE]: (state: CoinSwapState, action: { data: { coinSwapCodes: ?Array<string> } }) => {
|
||||
[ACTIONS.SYNC_STATE_POPULATE]: (state: CoinSwapState, action: { data: { coinSwapCodes: ?Array<string> } }) => {
|
||||
const { coinSwapCodes } = action.data;
|
||||
const newCoinSwaps = [];
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ const collectionsReducer = handleActions(
|
|||
isResolvingCollectionById: newResolving,
|
||||
});
|
||||
},
|
||||
[ACTIONS.USER_STATE_POPULATE]: (state, action) => {
|
||||
[ACTIONS.SYNC_STATE_POPULATE]: (state, action) => {
|
||||
const { builtinCollections, savedCollections, unpublishedCollections, editedCollections } = action.data;
|
||||
return {
|
||||
...state,
|
||||
|
|
|
@ -5,7 +5,6 @@ import moment from 'moment';
|
|||
import { getSubsetFromKeysArray } from 'util/sync-settings';
|
||||
import { getDefaultLanguage } from 'util/default-languages';
|
||||
import { UNSYNCED_SETTINGS } from 'config';
|
||||
import Comments from 'comments';
|
||||
|
||||
const { CLIENT_SYNC_KEYS } = SHARED_PREFERENCES;
|
||||
const settingsToIgnore = (UNSYNCED_SETTINGS && UNSYNCED_SETTINGS.trim().split(' ')) || [];
|
||||
|
@ -167,18 +166,9 @@ reducers[ACTIONS.SYNC_CLIENT_SETTINGS] = (state, action) => {
|
|||
return Object.assign({}, state, { sharedPreferences: data });
|
||||
};
|
||||
|
||||
reducers[ACTIONS.USER_STATE_POPULATE] = (state, action) => {
|
||||
const { clientSettings: currentClientSettings } = state;
|
||||
const { settings: sharedPreferences } = action.data;
|
||||
const selectedSettings = sharedPreferences ? getSubsetFromKeysArray(sharedPreferences, clientSyncKeys) : {};
|
||||
const mergedClientSettings = { ...currentClientSettings, ...selectedSettings };
|
||||
const newSharedPreferences = sharedPreferences || {};
|
||||
|
||||
Comments.setServerUrl(
|
||||
mergedClientSettings[SETTINGS.CUSTOM_COMMENTS_SERVER_ENABLED]
|
||||
? mergedClientSettings[SETTINGS.CUSTOM_COMMENTS_SERVER_URL]
|
||||
: undefined
|
||||
);
|
||||
reducers[ACTIONS.SYNC_STATE_POPULATE] = (state, action) => {
|
||||
const { walletPrefSettings, mergedClientSettings } = action.data;
|
||||
const newSharedPreferences = walletPrefSettings || {};
|
||||
|
||||
return Object.assign({}, state, {
|
||||
sharedPreferences: newSharedPreferences,
|
||||
|
|
|
@ -80,7 +80,7 @@ export default handleActions(
|
|||
...state,
|
||||
viewMode: action.data,
|
||||
}),
|
||||
[ACTIONS.USER_STATE_POPULATE]: (
|
||||
[ACTIONS.SYNC_STATE_POPULATE]: (
|
||||
state: SubscriptionState,
|
||||
action: { data: { subscriptions: ?Array<string>, following: ?Array<Subscription> } }
|
||||
) => {
|
||||
|
|
|
@ -18,7 +18,7 @@ const defaultState = {
|
|||
fatalError: false,
|
||||
};
|
||||
|
||||
reducers[ACTIONS.USER_STATE_POPULATE] = (state) => {
|
||||
reducers[ACTIONS.SYNC_STATE_POPULATE] = (state) => {
|
||||
const { syncReady } = state;
|
||||
if (!syncReady) {
|
||||
return Object.assign({}, state, {
|
||||
|
|
|
@ -62,7 +62,7 @@ export default handleActions(
|
|||
followedTags: newFollowedTags,
|
||||
};
|
||||
},
|
||||
[ACTIONS.USER_STATE_POPULATE]: (state: TagState, action: { data: { tags: ?Array<string> } }) => {
|
||||
[ACTIONS.SYNC_STATE_POPULATE]: (state: TagState, action: { data: { tags: ?Array<string> } }) => {
|
||||
const { tags } = action.data;
|
||||
if (Array.isArray(tags)) {
|
||||
const next = tags && tags.filter((tag) => typeof tag === 'string');
|
||||
|
|
Loading…
Reference in a new issue