Archive: Fix invalid migration; Drop stale migrations (#2750)

This commit is contained in:
Alexander Zinchuk 2023-03-04 03:16:30 +01:00
parent 53827859a2
commit 9afd4e888a

View File

@ -140,33 +140,6 @@ export function migrateCache(cached: GlobalState, initialState: GlobalState) {
}
function unsafeMigrateCache(cached: GlobalState, initialState: GlobalState) {
// Migrate from legacy setting names
if ('shouldAutoDownloadMediaFromContacts' in cached.settings.byKey) {
const {
shouldAutoDownloadMediaFromContacts,
shouldAutoDownloadMediaInPrivateChats,
shouldAutoDownloadMediaInGroups,
shouldAutoDownloadMediaInChannels,
shouldAutoPlayVideos,
shouldAutoPlayGifs,
...rest
} = cached.settings.byKey;
cached.settings.byKey = {
...rest,
canAutoLoadPhotoFromContacts: shouldAutoDownloadMediaFromContacts,
canAutoLoadVideoFromContacts: shouldAutoDownloadMediaFromContacts,
canAutoLoadPhotoInPrivateChats: shouldAutoDownloadMediaInPrivateChats,
canAutoLoadVideoInPrivateChats: shouldAutoDownloadMediaInPrivateChats,
canAutoLoadPhotoInGroups: shouldAutoDownloadMediaInGroups,
canAutoLoadVideoInGroups: shouldAutoDownloadMediaInGroups,
canAutoLoadPhotoInChannels: shouldAutoDownloadMediaInChannels,
canAutoLoadVideoInChannels: shouldAutoDownloadMediaInChannels,
canAutoPlayVideos: shouldAutoPlayVideos,
canAutoPlayGifs: shouldAutoPlayGifs,
};
}
// Pre-fill settings with defaults
cached.settings.byKey = {
...initialState.settings.byKey,
@ -183,26 +156,10 @@ function unsafeMigrateCache(cached: GlobalState, initialState: GlobalState) {
...cached.chatFolders,
};
if (!cached.stickers.greeting) {
cached.stickers.greeting = initialState.stickers.greeting;
}
if (!cached.stickers.premium) {
cached.stickers.premium = initialState.stickers.premium;
}
if (!cached.serviceNotifications) {
cached.serviceNotifications = [];
}
if (!cached.users.statusesById) {
cached.users.statusesById = {};
}
if (!cached.messages.sponsoredByChatId) {
cached.messages.sponsoredByChatId = {};
}
if (!cached.attachMenu) {
cached.attachMenu = {
bots: {},
@ -328,6 +285,10 @@ function unsafeMigrateCache(cached: GlobalState, initialState: GlobalState) {
cached.availableReactions = cached.availableReactions
.map((r) => ({ ...r, reaction: { emoticon: r.reaction as unknown as string } }));
}
if (!cached.archiveSettings) {
cached.archiveSettings = initialState.archiveSettings;
}
}
function updateCache() {