Browse Source

Migrate deprecated auto download settings

master
Eduard Kuzmenko 3 years ago
parent
commit
7955e20a78
  1. 42
      src/lib/appManagers/appStateManager.ts
  2. 2
      src/lib/mtproto/apiFileManager.ts

42
src/lib/appManagers/appStateManager.ts

@ -82,10 +82,10 @@ export type State = { @@ -82,10 +82,10 @@ export type State = {
sendShortcut: 'enter' | 'ctrlEnter',
animationsEnabled: boolean,
autoDownload: {
contacts: boolean,
private: boolean,
groups: boolean,
channels: boolean,
contacts?: boolean, // ! DEPRECATED
private?: boolean, // ! DEPRECATED
groups?: boolean, // ! DEPRECATED
channels?: boolean, // ! DEPRECATED
photo: AutoDownloadPeerTypeSettings,
video: AutoDownloadPeerTypeSettings,
file: AutoDownloadPeerTypeSettings
@ -140,10 +140,6 @@ export const STATE_INIT: State = { @@ -140,10 +140,6 @@ export const STATE_INIT: State = {
sendShortcut: 'enter',
animationsEnabled: true,
autoDownload: {
contacts: true,
private: true,
groups: true,
channels: true,
photo: {
contacts: true,
private: true,
@ -463,6 +459,36 @@ export class AppStateManager extends EventListenerBase<{ @@ -463,6 +459,36 @@ export class AppStateManager extends EventListenerBase<{
}
}
// * migrate auto download settings
const autoDownloadSettings = state.settings.autoDownload;
if(autoDownloadSettings?.private !== undefined) {
const oldTypes = [
'contacts' as const,
'private' as const,
'groups' as const,
'channels' as const
];
const mediaTypes = [
'photo' as const,
'video' as const,
'file' as const
];
mediaTypes.forEach(mediaType => {
const peerTypeSettings: AutoDownloadPeerTypeSettings = autoDownloadSettings[mediaType] = {} as any;
oldTypes.forEach(peerType => {
peerTypeSettings[peerType] = autoDownloadSettings[peerType];
});
});
oldTypes.forEach(peerType => {
delete autoDownloadSettings[peerType];
});
this.pushToState('settings', state.settings);
}
validateInitObject(STATE_INIT, state, (missingKey) => {
// @ts-ignore
this.pushToState(missingKey, state[missingKey]);

2
src/lib/mtproto/apiFileManager.ts

@ -63,7 +63,7 @@ export interface RefreshReferenceTaskResponse extends WorkerTaskVoidTemplate { @@ -63,7 +63,7 @@ export interface RefreshReferenceTaskResponse extends WorkerTaskVoidTemplate {
originalPayload: ReferenceBytes
};
const MAX_FILE_SAVE_SIZE = 20e6;
const MAX_FILE_SAVE_SIZE = 20 * 1024 * 1024;
export class ApiFileManager {
private cacheStorage = new CacheStorageController('cachedFiles');

Loading…
Cancel
Save