diff --git a/src/global/cache.ts b/src/global/cache.ts index 2a0bf94c5..c3e25efdf 100644 --- a/src/global/cache.ts +++ b/src/global/cache.ts @@ -35,7 +35,7 @@ import { onBeforeUnload, throttle } from '../util/schedulers'; import { hasStoredSession } from '../util/sessions'; import { selectThreadInfo } from './selectors/threads'; import { addActionHandler, getGlobal } from './index'; -import { INITIAL_GLOBAL_STATE, INITIAL_PERFORMANCE_STATE_MED } from './initialState'; +import { INITIAL_GLOBAL_STATE, INITIAL_PERFORMANCE_STATE_MED, INITIAL_SHARED_STATE } from './initialState'; import { clearGlobalForLockScreen, clearSharedStateForLockScreen } from './reducers'; import { selectChatLastMessageId, @@ -336,6 +336,7 @@ function unsafeMigrateCache(cached: GlobalState, initialState: GlobalState) { shouldCollectDebugLogs: untypedCached.settings.byKey.shouldCollectDebugLogs, shouldDebugExportedSenders: untypedCached.settings.byKey.shouldDebugExportedSenders, shouldWarnAboutFiles: untypedCached.settings.byKey.shouldWarnAboutFiles, + ayuLike: INITIAL_SHARED_STATE.settings.ayuLike, }; } @@ -365,6 +366,10 @@ function unsafeMigrateCache(cached: GlobalState, initialState: GlobalState) { cachedSharedSettings.foldersPosition = FOLDERS_POSITION_DEFAULT; } + if (!cachedSharedSettings.ayuLike) { + cachedSharedSettings.ayuLike = INITIAL_SHARED_STATE.settings.ayuLike; + } + if (!cached.appConfig) { cached.appConfig = initialState.appConfig; } diff --git a/src/global/initialState.ts b/src/global/initialState.ts index bf7a2d073..e6c358f74 100644 --- a/src/global/initialState.ts +++ b/src/global/initialState.ts @@ -97,6 +97,10 @@ export const INITIAL_SHARED_STATE: SharedState = { canDisplayChatInTitle: true, shouldAllowHttpTransport: true, shouldWarnAboutFiles: true, + ayuLike: { + hideSponsoredMessages: true, + messageFilters: [], + }, }, isInitial: true, }; diff --git a/src/global/types/sharedState.ts b/src/global/types/sharedState.ts index 385695f4d..4cff96018 100644 --- a/src/global/types/sharedState.ts +++ b/src/global/types/sharedState.ts @@ -3,6 +3,23 @@ import type { AnimationLevel, FoldersPosition, PerformanceType, Point, Size, ThemeKey, TimeFormat, } from '../../types'; +export interface MessageFilterRule { + id: string; + enabled: boolean; + reversed?: boolean; + caseInsensitive?: boolean; + keyword?: string; + regex?: string; + chatIds?: string[]; + senderIds?: string[]; + mediaTypes?: string[]; +} + +export interface AyuLikeSettings { + hideSponsoredMessages: boolean; + messageFilters: MessageFilterRule[]; +} + export interface SharedState { settings: SharedSettings; isInitial?: true; @@ -32,4 +49,5 @@ export interface SharedSettings { shouldDebugExportedSenders?: boolean; shouldWarnAboutFiles?: boolean; shouldSkipWebAppCloseConfirmation: boolean; + ayuLike: AyuLikeSettings; }