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