Add AyuLike settings types and initial state

Introduce MessageFilterRule, AyuLikeSettings interfaces in SharedSettings.
Default: hideSponsoredMessages=true, messageFilters=[].
Cache migration covers both cold-start and upgrade paths.
This commit is contained in:
Tianrong Zhang 2026-06-11 22:15:41 -04:00
parent 560a29b619
commit 32153e86de
3 changed files with 28 additions and 1 deletions

View File

@ -35,7 +35,7 @@ import { onBeforeUnload, throttle } from '../util/schedulers';
import { hasStoredSession } from '../util/sessions'; import { hasStoredSession } from '../util/sessions';
import { selectThreadInfo } from './selectors/threads'; import { selectThreadInfo } from './selectors/threads';
import { addActionHandler, getGlobal } from './index'; 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 { clearGlobalForLockScreen, clearSharedStateForLockScreen } from './reducers';
import { import {
selectChatLastMessageId, selectChatLastMessageId,
@ -336,6 +336,7 @@ function unsafeMigrateCache(cached: GlobalState, initialState: GlobalState) {
shouldCollectDebugLogs: untypedCached.settings.byKey.shouldCollectDebugLogs, shouldCollectDebugLogs: untypedCached.settings.byKey.shouldCollectDebugLogs,
shouldDebugExportedSenders: untypedCached.settings.byKey.shouldDebugExportedSenders, shouldDebugExportedSenders: untypedCached.settings.byKey.shouldDebugExportedSenders,
shouldWarnAboutFiles: untypedCached.settings.byKey.shouldWarnAboutFiles, 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; cachedSharedSettings.foldersPosition = FOLDERS_POSITION_DEFAULT;
} }
if (!cachedSharedSettings.ayuLike) {
cachedSharedSettings.ayuLike = INITIAL_SHARED_STATE.settings.ayuLike;
}
if (!cached.appConfig) { if (!cached.appConfig) {
cached.appConfig = initialState.appConfig; cached.appConfig = initialState.appConfig;
} }

View File

@ -97,6 +97,10 @@ export const INITIAL_SHARED_STATE: SharedState = {
canDisplayChatInTitle: true, canDisplayChatInTitle: true,
shouldAllowHttpTransport: true, shouldAllowHttpTransport: true,
shouldWarnAboutFiles: true, shouldWarnAboutFiles: true,
ayuLike: {
hideSponsoredMessages: true,
messageFilters: [],
},
}, },
isInitial: true, isInitial: true,
}; };

View File

@ -3,6 +3,23 @@ import type {
AnimationLevel, FoldersPosition, PerformanceType, Point, Size, ThemeKey, TimeFormat, AnimationLevel, FoldersPosition, PerformanceType, Point, Size, ThemeKey, TimeFormat,
} from '../../types'; } 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 { export interface SharedState {
settings: SharedSettings; settings: SharedSettings;
isInitial?: true; isInitial?: true;
@ -32,4 +49,5 @@ export interface SharedSettings {
shouldDebugExportedSenders?: boolean; shouldDebugExportedSenders?: boolean;
shouldWarnAboutFiles?: boolean; shouldWarnAboutFiles?: boolean;
shouldSkipWebAppCloseConfirmation: boolean; shouldSkipWebAppCloseConfirmation: boolean;
ayuLike: AyuLikeSettings;
} }