// Metro module 4001 (f4002). import SelectivelySyncedUserSettingsStore from "../user_settings/SelectivelySyncedUserSettingsStore"; import ThemeStore from "../user_settings/ThemeStore"; import UnsyncedUserSettingsStore from "../user_settings/UnsyncedUserSettingsStore"; import UserSettingsProtoStore from "../user_settings/UserSettingsProtoStore"; import { isGuildTextChannelType } from "../../records/ChannelRecord"; import ChannelStore from "../../stores/ChannelStore"; import UserStore from "../../stores/UserStore"; import { BACKGROUND_GRADIENT_PRESETS_MAP } from "./ClientThemesConstants"; import { SystemThemeState } from "../user_settings/ThemeConstants"; import { isMobileVisualRefreshEnabled } from "../themes/experiments/MobileVisualRefreshExperiment"; import { UNSAFE_isDismissibleContentDismissed } from "../dismissible_content/DismissibleContentUnsafeUtils"; import { DismissibleContent } from "../../_bundle/Module1358"; import { ageEligibleForPremiumUpsell } from "../../utils/UserUtils"; import PremiumUtils from "../../utils/PremiumUtils"; import { ClientThemeSettings } from "../user_settings/UserSettings"; import { isPerModeThemingActive } from "../user_settings/isPerModeThemingActive"; import { setUseSystemTheme } from "../user_settings/ThemeActionCreators"; import Module589 from "../../_bundle/Module589"; import { getLinearGradientForBackgroundGradient } from "./ClientThemesUtils"; import Dispatcher from "../../Dispatcher"; let c2279_3, mobileThemesIndex, c2279_14, c2279_15, handleUserStoreChange, handleSelectivelySyncedStoreChange; const isSyncedModeThemesEnabled = function isSyncedModeThemesEnabled() { return isMobileVisualRefreshEnabled("ClientThemesBackgroundStore"); }; const reset = function reset() { if (c2279_14) { c2279_3 = void 0; } c2279_15 = false; }; handleUserStoreChange = function handleUserStoreChange() { const r2 = !PremiumUtils.canUseClientThemes(UserStore.getCurrentUser()); if (r2 === c2279_14) { return false; } c2279_14 = r2; }; handleSelectivelySyncedStoreChange = function handleSelectivelySyncedStoreChange() { if (SelectivelySyncedUserSettingsStore.shouldSync("appearance")) { const backgroundGradientPresetId = ClientThemeSettings.getSetting().backgroundGradientPresetId; if (backgroundGradientPresetId == null) { if (c2279_3 == null) { return false; } c2279_3 = void 0; } else { const r18 = BACKGROUND_GRADIENT_PRESETS_MAP[backgroundGradientPresetId]; if (r18 === c2279_3) { return false; } c2279_3 = r18; } return void 0; } return false; }; const handleSyncedModeChange = function handleSyncedModeChange() { return isPerModeThemingActive(isSyncedModeThemesEnabled); }; const handleSameAsDeviceThemeToggle = function handleSameAsDeviceThemeToggle() { return isMobileVisualRefreshEnabled("ClientThemesBackgroundStore"); }; const handleUserSettingsProtoStoreUpdate = function handleUserSettingsProtoStoreUpdate() { if (SelectivelySyncedUserSettingsStore.shouldSync("appearance")) { const backgroundGradientPresetId = ClientThemeSettings.getSetting().backgroundGradientPresetId; if (!(UnsyncedUserSettingsStore.useSystemTheme !== SystemThemeState.ON || backgroundGradientPresetId == null || ThemeStore.isSameAsDeviceThemeEnabled())) { setUseSystemTheme(SystemThemeState.OFF); } if (backgroundGradientPresetId != null) { const r32 = BACKGROUND_GRADIENT_PRESETS_MAP[backgroundGradientPresetId]; if (!(r32 == null || c2279_3?.id === r32?.id)) { c2279_3 = r32; } } else if (c2279_3 != null) { c2279_3 = void 0; } return void 0; } return false; }; c2279_14 = true; c2279_15 = false; class ClientThemesBackgroundStore extends Module589.PersistedStore { static displayName = "ClientThemesBackgroundStore"; static persistKey = "ClientThemesBackgroundStore"; migrations = [(a0) => ({ gradientPresetId: a0 == null ? void 0 : a0.gradientPreset?.id })]; initialize(a0) { if (a0 != null) { c2279_3 = a0?.gradientPresetId != null ? BACKGROUND_GRADIENT_PRESETS_MAP[a0.gradientPresetId] : void 0; } this.waitFor(ChannelStore, SelectivelySyncedUserSettingsStore, ThemeStore, UnsyncedUserSettingsStore, UserSettingsProtoStore, UserStore); this.syncWith([UserStore], handleUserStoreChange); this.syncWith([SelectivelySyncedUserSettingsStore], handleSelectivelySyncedStoreChange); } getState() { return c2279_14 ? {} : { gradientPresetId: c2279_3?.id }; } get gradientPreset() { if (isPerModeThemingActive(isSyncedModeThemesEnabled)) { const backgroundGradientPresetId = ThemeStore.getSyncedClientTheme(ThemeStore.systemTheme)?.backgroundGradientPresetId; return backgroundGradientPresetId != null ? BACKGROUND_GRADIENT_PRESETS_MAP[backgroundGradientPresetId] : void 0; } return c2279_3; } getLinearGradient() { return this.gradientPreset != null ? getLinearGradientForBackgroundGradient(this.gradientPreset) : null; } get isPreview() { return c2279_14; } get isCoachmark() { return c2279_15; } get mobilePendingThemeIndex() { return mobileThemesIndex; } } const clientThemesBackgroundStore = new ClientThemesBackgroundStore(Dispatcher, { UPDATE_BACKGROUND_GRADIENT_PRESET: function handleUpdateBackgroundGradientPreset({ presetId }) { c2279_3 = presetId != null ? BACKGROUND_GRADIENT_PRESETS_MAP[presetId] : void 0; }, UPDATE_MOBILE_PENDING_THEME_INDEX: function handleUpdateMobilePendingThemeIndex({ mobileThemesIndex: mobileThemesIndex2 }) { mobileThemesIndex = mobileThemesIndex2 ?? void 0; }, RESET_PREVIEW_CLIENT_THEME: function handleResetPreviewClientTheme() { c2279_3 = void 0; }, CLIENT_THEMES_EDITOR_CLOSE: reset, CHANNEL_SELECT: function handleChannelSelect({ channelId, guildId }) { const currentUser = UserStore.getCurrentUser(); if (channelId != null && guildId != null && !UNSAFE_isDismissibleContentDismissed(DismissibleContent.CLIENT_THEMES_COACHMARK) && ageEligibleForPremiumUpsell(currentUser)) { const channel = ChannelStore.getChannel(channelId); if (channel != null && isGuildTextChannelType(channel.type)) { c2279_15 = true; } } }, LOGOUT: reset, CACHE_LOADED: handleUserSettingsProtoStoreUpdate, CONNECTION_OPEN: handleUserSettingsProtoStoreUpdate, OVERLAY_INITIALIZE: handleUserSettingsProtoStoreUpdate, SELECTIVELY_SYNCED_USER_SETTINGS_UPDATE: handleUserSettingsProtoStoreUpdate, UNSYNCED_USER_SETTINGS_UPDATE: handleUserSettingsProtoStoreUpdate, USER_SETTINGS_PROTO_UPDATE: handleUserSettingsProtoStoreUpdate, SYSTEM_THEME_CHANGE: handleSyncedModeChange, UPDATE_SYNCED_CLIENT_THEME: handleSyncedModeChange, SET_SAME_AS_DEVICE_THEME_ENABLED: handleSameAsDeviceThemeToggle, CLEAR_SYNCED_CLIENT_THEMES: handleSameAsDeviceThemeToggle }); export default clientThemesBackgroundStore;