diff --git a/ui/constants/action_types.js b/ui/constants/action_types.js index 4a1d2e46d..c2f85b14f 100644 --- a/ui/constants/action_types.js +++ b/ui/constants/action_types.js @@ -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'; diff --git a/ui/redux/actions/app.js b/ui/redux/actions/app.js index 098aea012..342cccb71 100644 --- a/ui/redux/actions/app.js +++ b/ui/redux/actions/app.js @@ -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()); } diff --git a/ui/redux/actions/sync.js b/ui/redux/actions/sync.js index 95a95b149..b5d410d1e 100644 --- a/ui/redux/actions/sync.js +++ b/ui/redux/actions/sync.js @@ -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, diff --git a/ui/redux/reducers/app.js b/ui/redux/reducers/app.js index 66bb53ed6..6b805dcca 100644 --- a/ui/redux/reducers/app.js +++ b/ui/redux/reducers/app.js @@ -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, diff --git a/ui/redux/reducers/blocked.js b/ui/redux/reducers/blocked.js index b1ed5b887..28a202b41 100644 --- a/ui/redux/reducers/blocked.js +++ b/ui/redux/reducers/blocked.js @@ -23,7 +23,7 @@ export default handleActions( blockedChannels: newBlockedChannels, }; }, - [ACTIONS.USER_STATE_POPULATE]: (state: BlocklistState, action: { data: { blocked: ?Array } }) => { + [ACTIONS.SYNC_STATE_POPULATE]: (state: BlocklistState, action: { data: { blocked: ?Array } }) => { const { blocked } = action.data; const sanitizedBlocked = blocked && blocked.filter((e) => typeof e === 'string'); return { diff --git a/ui/redux/reducers/coinSwap.js b/ui/redux/reducers/coinSwap.js index 57c9f6f35..3d5983a59 100644 --- a/ui/redux/reducers/coinSwap.js +++ b/ui/redux/reducers/coinSwap.js @@ -117,7 +117,7 @@ export default handleActions( coinSwaps: newCoinSwaps, }; }, - [ACTIONS.USER_STATE_POPULATE]: (state: CoinSwapState, action: { data: { coinSwapCodes: ?Array } }) => { + [ACTIONS.SYNC_STATE_POPULATE]: (state: CoinSwapState, action: { data: { coinSwapCodes: ?Array } }) => { const { coinSwapCodes } = action.data; const newCoinSwaps = []; diff --git a/ui/redux/reducers/collections.js b/ui/redux/reducers/collections.js index 7747169a0..856111d9e 100644 --- a/ui/redux/reducers/collections.js +++ b/ui/redux/reducers/collections.js @@ -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, diff --git a/ui/redux/reducers/settings.js b/ui/redux/reducers/settings.js index c52635966..9c2d5d027 100644 --- a/ui/redux/reducers/settings.js +++ b/ui/redux/reducers/settings.js @@ -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, diff --git a/ui/redux/reducers/subscriptions.js b/ui/redux/reducers/subscriptions.js index 9e42e9c75..cfabff449 100644 --- a/ui/redux/reducers/subscriptions.js +++ b/ui/redux/reducers/subscriptions.js @@ -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, following: ?Array } } ) => { diff --git a/ui/redux/reducers/sync.js b/ui/redux/reducers/sync.js index a53817f0d..df9807209 100644 --- a/ui/redux/reducers/sync.js +++ b/ui/redux/reducers/sync.js @@ -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, { diff --git a/ui/redux/reducers/tags.js b/ui/redux/reducers/tags.js index c3be1baf2..06a1aec76 100644 --- a/ui/redux/reducers/tags.js +++ b/ui/redux/reducers/tags.js @@ -62,7 +62,7 @@ export default handleActions( followedTags: newFollowedTags, }; }, - [ACTIONS.USER_STATE_POPULATE]: (state: TagState, action: { data: { tags: ?Array } }) => { + [ACTIONS.SYNC_STATE_POPULATE]: (state: TagState, action: { data: { tags: ?Array } }) => { const { tags } = action.data; if (Array.isArray(tags)) { const next = tags && tags.filter((tag) => typeof tag === 'string');