diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js --- a/lib/reducers/master-reducer.js +++ b/lib/reducers/master-reducer.js @@ -182,6 +182,11 @@ const { enabledApps } = reduceEnabledApps(state.enabledApps, action); + const { globalThemeInfo } = reduceGlobalThemeInfo( + state.globalThemeInfo, + action, + ); + const { syncedMetadataStore, syncedMetadataStoreOperations } = reduceSyncedMetadataStore(state.syncedMetadataStore, action); @@ -252,7 +257,7 @@ inviteLinksStore: reduceInviteLinks(state.inviteLinksStore, action), keyserverStore, integrityStore, - globalThemeInfo: reduceGlobalThemeInfo(state.globalThemeInfo, action), + globalThemeInfo, customServer: reduceCustomerServer(state.customServer, action), communityStore, dbOpsStore: reduceDBOpsStore(state.dbOpsStore, action), diff --git a/lib/reducers/theme-reducer.js b/lib/reducers/theme-reducer.js --- a/lib/reducers/theme-reducer.js +++ b/lib/reducers/theme-reducer.js @@ -1,9 +1,12 @@ // @flow +import { setClientDBStoreActionType } from '../actions/client-db-store-actions.js'; import { updateThemeInfoActionType } from '../actions/theme-actions.js'; import { legacyLogInActionTypes } from '../actions/user-actions.js'; import { setNewSessionActionType } from '../keyserver-conn/keyserver-conn-types.js'; +import type { SyncedMetadataStoreOperation } from '../ops/synced-metadata-store-ops.js'; import type { BaseAction } from '../types/redux-types.js'; +import { syncedMetadataNames } from '../types/synced-metadata-types.js'; import { defaultGlobalThemeInfo, type GlobalThemeInfo, @@ -11,24 +14,63 @@ import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js'; import { relyingOnAuthoritativeKeyserver } from '../utils/services-utils.js'; +type ReduceGlobalThemeInfoResult = { + +globalThemeInfo: GlobalThemeInfo, + +syncedMetadataStoreOperations: $ReadOnlyArray, +}; + +function getUpdatedGlobalThemeInfoResult( + globalThemeInfo: GlobalThemeInfo, +): ReduceGlobalThemeInfoResult { + return { + globalThemeInfo, + syncedMetadataStoreOperations: [ + { + type: 'replace_synced_metadata_entry', + payload: { + name: syncedMetadataNames.GLOBAL_THEME_INFO, + data: JSON.stringify(globalThemeInfo), + }, + }, + ], + }; +} + export default function reduceGlobalThemeInfo( state: GlobalThemeInfo, action: BaseAction, -): GlobalThemeInfo { +): ReduceGlobalThemeInfoResult { if (action.type === legacyLogInActionTypes.success) { - return defaultGlobalThemeInfo; + return getUpdatedGlobalThemeInfoResult(defaultGlobalThemeInfo); } else if ( action.type === setNewSessionActionType && action.payload.sessionChange.cookieInvalidated && action.payload.keyserverID === authoritativeKeyserverID() && relyingOnAuthoritativeKeyserver ) { - return defaultGlobalThemeInfo; + return getUpdatedGlobalThemeInfoResult(defaultGlobalThemeInfo); } else if (action.type === updateThemeInfoActionType) { - return { + return getUpdatedGlobalThemeInfoResult({ ...state, ...action.payload, + }); + } else if (action.type === setClientDBStoreActionType) { + let globalThemeInfo = { ...state }; + const globalThemeInfoString = + action.payload.syncedMetadata?.[syncedMetadataNames.GLOBAL_THEME_INFO]; + if (globalThemeInfoString) { + globalThemeInfo = { + ...globalThemeInfo, + ...JSON.parse(globalThemeInfoString), + }; + } + return { + globalThemeInfo, + syncedMetadataStoreOperations: [], }; } - return state; + return { + globalThemeInfo: state, + syncedMetadataStoreOperations: [], + }; } diff --git a/lib/types/synced-metadata-types.js b/lib/types/synced-metadata-types.js --- a/lib/types/synced-metadata-types.js +++ b/lib/types/synced-metadata-types.js @@ -10,6 +10,7 @@ CURRENT_USER_FID: 'current_user_fid', STORE_VERSION: 'store_version', ENABLED_APPS: 'enabled_apps', + GLOBAL_THEME_INFO: 'global_theme_info', }); type SyncedMetadataName = $Values;