diff --git a/ts/RemoteConfig.ts b/ts/RemoteConfig.ts index 742ad37bd6..2e0a5350ca 100644 --- a/ts/RemoteConfig.ts +++ b/ts/RemoteConfig.ts @@ -182,8 +182,12 @@ export async function forceRefreshRemoteConfig( await _refreshRemoteConfig(server); } -export function isEnabled(name: ConfigKeyType): boolean { - return get(config, [name, 'enabled'], false); +export function isEnabled( + name: ConfigKeyType, + // when called from UI component, provide redux config (items.remoteConfig) + reduxConfig?: ConfigMapType +): boolean { + return get(reduxConfig ?? config, [name, 'enabled'], false); } export function getValue(name: ConfigKeyType): string | undefined { diff --git a/ts/state/smart/Preferences.tsx b/ts/state/smart/Preferences.tsx index 450a3efecf..990265ebf4 100644 --- a/ts/state/smart/Preferences.tsx +++ b/ts/state/smart/Preferences.tsx @@ -23,7 +23,7 @@ import { } from '../selectors/items'; import { DEFAULT_AUTO_DOWNLOAD_ATTACHMENT } from '../../textsecure/Storage'; import { DEFAULT_CONVERSATION_COLOR } from '../../types/Colors'; -import { isBackupFeatureEnabledForRedux } from '../../util/isBackupEnabled'; +import { isBackupFeatureEnabled } from '../../util/isBackupEnabled'; import { format } from '../../types/PhoneNumber'; import { getIntl, @@ -68,7 +68,7 @@ import { SmartToastManager } from './ToastManager'; import { useToastActions } from '../ducks/toast'; import { DataReader } from '../../sql/Client'; import { deleteAllMyStories } from '../../util/deleteAllMyStories'; -import { isLocalBackupsEnabledForRedux } from '../../util/isLocalBackupsEnabled'; +import { isLocalBackupsEnabled } from '../../util/isLocalBackupsEnabled'; import { SmartPreferencesDonations } from './PreferencesDonations'; import { useDonationsActions } from '../ducks/donations'; import { generateDonationReceiptBlob } from '../../util/generateDonationReceipt'; @@ -519,12 +519,8 @@ export function SmartPreferences(): JSX.Element | null { Settings.isContentProtectionSupported(OS); const isContentProtectionNeeded = Settings.isContentProtectionNeeded(OS); - const backupFeatureEnabled = isBackupFeatureEnabledForRedux( - items.remoteConfig - ); - const backupLocalBackupsEnabled = isLocalBackupsEnabledForRedux( - items.remoteConfig - ); + const backupFeatureEnabled = isBackupFeatureEnabled(items.remoteConfig); + const backupLocalBackupsEnabled = isLocalBackupsEnabled(items.remoteConfig); const donationsFeatureEnabled = items.remoteConfig?.['desktop.internalUser']?.enabled ?? items.remoteConfig?.['desktop.donations']?.enabled ?? diff --git a/ts/util/isBackupEnabled.ts b/ts/util/isBackupEnabled.ts index e3c40a4f79..eca7dcb8ac 100644 --- a/ts/util/isBackupEnabled.ts +++ b/ts/util/isBackupEnabled.ts @@ -4,6 +4,7 @@ import * as RemoteConfig from '../RemoteConfig'; import { isTestOrMockEnvironment } from '../environment'; import { isStagingServer } from './isStagingServer'; +import { isNightly } from './version'; export function areRemoteBackupsTurnedOn(): boolean { return isBackupFeatureEnabled() && window.storage.get('backupTier') != null; @@ -14,18 +15,18 @@ export function canAttemptRemoteBackupDownload(): boolean { return isBackupFeatureEnabled() && isTestOrMockEnvironment(); } -export function isBackupFeatureEnabled(): boolean { - if (isStagingServer() || isTestOrMockEnvironment()) { - return true; - } - return Boolean(RemoteConfig.isEnabled('desktop.backup.credentialFetch')); -} - -export function isBackupFeatureEnabledForRedux( - config: RemoteConfig.ConfigMapType | undefined +export function isBackupFeatureEnabled( + reduxConfig?: RemoteConfig.ConfigMapType ): boolean { if (isStagingServer() || isTestOrMockEnvironment()) { return true; } - return Boolean(config?.['desktop.backup.credentialFetch']?.enabled); + + if (isNightly(window.getVersion())) { + return true; + } + + return Boolean( + RemoteConfig.isEnabled('desktop.backup.credentialFetch', reduxConfig) + ); } diff --git a/ts/util/isLocalBackupsEnabled.ts b/ts/util/isLocalBackupsEnabled.ts index 7dad06f320..29588dbbc1 100644 --- a/ts/util/isLocalBackupsEnabled.ts +++ b/ts/util/isLocalBackupsEnabled.ts @@ -6,31 +6,14 @@ import { isTestOrMockEnvironment } from '../environment'; import { isStagingServer } from './isStagingServer'; import { isNightly } from './version'; -export function isLocalBackupsEnabled(): boolean { - if (isStagingServer() || isTestOrMockEnvironment()) { - return true; - } - - if (RemoteConfig.isEnabled('desktop.internalUser')) { - return true; - } - - const version = window.getVersion?.(); - if (version != null) { - return isNightly(version); - } - - return false; -} - -export function isLocalBackupsEnabledForRedux( - config: Pick | undefined +export function isLocalBackupsEnabled( + reduxConfig?: RemoteConfig.ConfigMapType ): boolean { if (isStagingServer() || isTestOrMockEnvironment()) { return true; } - if (config?.['desktop.internalUser']?.enabled) { + if (RemoteConfig.isEnabled('desktop.internalUser', reduxConfig)) { return true; }