migration
This commit is contained in:
parent
d358b8370f
commit
914df47a35
2 changed files with 146 additions and 10 deletions
129
src/modules/old_default_config_state.js
Normal file
129
src/modules/old_default_config_state.js
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
// this is a snapshot of config keys used prior to sync config.
|
||||||
|
// used to migrate from old config.
|
||||||
|
export const defaultStateKeys = [
|
||||||
|
'expertLevel',
|
||||||
|
'hideISP',
|
||||||
|
'hideInstanceWallpaper',
|
||||||
|
'hideShoutbox',
|
||||||
|
'hideMutedPosts',
|
||||||
|
'hideMutedThreads',
|
||||||
|
'hideWordFilteredPosts',
|
||||||
|
'muteBotStatuses',
|
||||||
|
'muteSensitiveStatuses',
|
||||||
|
'collapseMessageWithSubject',
|
||||||
|
'padEmoji',
|
||||||
|
'hideAttachments',
|
||||||
|
'hideAttachmentsInConv',
|
||||||
|
'hideScrobbles',
|
||||||
|
'hideScrobblesAfter',
|
||||||
|
'maxThumbnails',
|
||||||
|
'hideNsfw',
|
||||||
|
'preloadImage',
|
||||||
|
'loopVideo',
|
||||||
|
'loopVideoSilentOnly',
|
||||||
|
'streaming',
|
||||||
|
'emojiReactionsOnTimeline',
|
||||||
|
'alwaysShowNewPostButton',
|
||||||
|
'autohideFloatingPostButton',
|
||||||
|
'pauseOnUnfocused',
|
||||||
|
'stopGifs',
|
||||||
|
'replyVisibility',
|
||||||
|
'thirdColumnMode',
|
||||||
|
'notificationVisibility',
|
||||||
|
'notificationNative',
|
||||||
|
'webPushNotifications',
|
||||||
|
'webPushAlwaysShowNotifications',
|
||||||
|
'interfaceLanguage',
|
||||||
|
'hideScopeNotice',
|
||||||
|
'useStreamingApi',
|
||||||
|
'sidebarRight',
|
||||||
|
'scopeCopy',
|
||||||
|
'subjectLineBehavior',
|
||||||
|
'alwaysShowSubjectInput',
|
||||||
|
'postContentType',
|
||||||
|
'minimalScopesMode',
|
||||||
|
'hideFilteredStatuses',
|
||||||
|
'modalOnRepeat',
|
||||||
|
'modalOnUnfollow',
|
||||||
|
'modalOnBlock',
|
||||||
|
'modalOnMute',
|
||||||
|
'modalOnMuteConversation',
|
||||||
|
'modalOnMuteDomain',
|
||||||
|
'modalOnDelete',
|
||||||
|
'modalOnLogout',
|
||||||
|
'modalOnApproveFollow',
|
||||||
|
'modalOnDenyFollow',
|
||||||
|
'modalOnRemoveUserFromFollowers',
|
||||||
|
'onMuteDefaultAction',
|
||||||
|
'onBlockDefaultAction',
|
||||||
|
'modalMobileCenter',
|
||||||
|
'playVideosInModal',
|
||||||
|
'useOneClickNsfw',
|
||||||
|
'useContainFit',
|
||||||
|
'disableStickyHeaders',
|
||||||
|
'showScrollbars',
|
||||||
|
'userPopoverAvatarAction',
|
||||||
|
'userPopoverOverlay',
|
||||||
|
'userCardLeftJustify',
|
||||||
|
'userCardHidePersonalMarks',
|
||||||
|
'sidebarColumnWidth',
|
||||||
|
'contentColumnWidth',
|
||||||
|
'notifsColumnWidth',
|
||||||
|
'themeEditorMinWidth',
|
||||||
|
'emojiReactionsScale',
|
||||||
|
'textSize',
|
||||||
|
'emojiSize',
|
||||||
|
'navbarSize',
|
||||||
|
'panelHeaderSize',
|
||||||
|
'forcedRoundness',
|
||||||
|
'navbarColumnStretch',
|
||||||
|
'greentext',
|
||||||
|
'mentionLinkDisplay',
|
||||||
|
'mentionLinkShowTooltip',
|
||||||
|
'mentionLinkShowAvatar',
|
||||||
|
'mentionLinkFadeDomain',
|
||||||
|
'mentionLinkShowYous',
|
||||||
|
'mentionLinkBoldenYou',
|
||||||
|
'hidePostStats',
|
||||||
|
'hideBotIndication',
|
||||||
|
'hideUserStats',
|
||||||
|
'virtualScrolling',
|
||||||
|
'sensitiveByDefault',
|
||||||
|
'conversationDisplay',
|
||||||
|
'conversationTreeAdvanced',
|
||||||
|
'conversationOtherRepliesButton',
|
||||||
|
'conversationTreeFadeAncestors',
|
||||||
|
'showExtraNotifications',
|
||||||
|
'showExtraNotificationsTip',
|
||||||
|
'showChatsInExtraNotifications',
|
||||||
|
'showAnnouncementsInExtraNotifications',
|
||||||
|
'showFollowRequestsInExtraNotifications',
|
||||||
|
'maxDepthInThread',
|
||||||
|
'autocompleteSelect',
|
||||||
|
'closingDrawerMarksAsSeen',
|
||||||
|
'unseenAtTop',
|
||||||
|
'ignoreInactionableSeen',
|
||||||
|
'unsavedPostAction',
|
||||||
|
'autoSaveDraft',
|
||||||
|
'useAbsoluteTimeFormat',
|
||||||
|
'absoluteTimeFormatMinAge',
|
||||||
|
'absoluteTime12h',
|
||||||
|
'imageCompression',
|
||||||
|
'alwaysUseJpeg',
|
||||||
|
'theme',
|
||||||
|
|
||||||
|
'colors',
|
||||||
|
|
||||||
|
'customTheme',
|
||||||
|
'customThemeSource',
|
||||||
|
|
||||||
|
'style',
|
||||||
|
'styleCustomData',
|
||||||
|
'palette',
|
||||||
|
'paletteCustomData',
|
||||||
|
'themeDebug',
|
||||||
|
'forceThemeRecompilation',
|
||||||
|
'theme3hacks',
|
||||||
|
// 'muteWords', // mutes migrated separately
|
||||||
|
// 'highlight', // highlight migration is done separately
|
||||||
|
]
|
||||||
|
|
@ -20,7 +20,9 @@ import { CURRENT_UPDATE_COUNTER } from 'src/components/update_notification/updat
|
||||||
import { useInstanceStore } from 'src/stores/instance.js'
|
import { useInstanceStore } from 'src/stores/instance.js'
|
||||||
import { useLocalConfigStore } from 'src/stores/local_config.js'
|
import { useLocalConfigStore } from 'src/stores/local_config.js'
|
||||||
|
|
||||||
import { defaultState as configDefaultState } from 'src/modules/default_config_state'
|
import { defaultState as configDefaultState } from 'src/modules/default_config_state.js'
|
||||||
|
import { defaultStateKeys } from 'src/modules/old_default_config_state.js'
|
||||||
|
import { storage } from 'src/lib/storage.js'
|
||||||
|
|
||||||
export const VERSION = 2
|
export const VERSION = 2
|
||||||
export const NEW_USER_DATE = new Date('2022-08-04') // date of writing this, basically
|
export const NEW_USER_DATE = new Date('2022-08-04') // date of writing this, basically
|
||||||
|
|
@ -411,16 +413,21 @@ export const _resetPrefs = (
|
||||||
return totalPrefs
|
return totalPrefs
|
||||||
}
|
}
|
||||||
|
|
||||||
export const _doMigrations = (cache, live) => {
|
export const _doMigrations = async (data) => {
|
||||||
const data = cache ?? live
|
console.log('TEST', data._version)
|
||||||
|
|
||||||
if (data._version < VERSION) {
|
if (data._version < VERSION) {
|
||||||
console.debug(
|
console.debug(
|
||||||
'Data has older version, seeing if there any migrations that can be applied',
|
'Data has older version, seeing if there any migrations that can be applied',
|
||||||
)
|
)
|
||||||
|
|
||||||
// no migrations right now since we only have one version
|
if (data._version === 1) {
|
||||||
console.debug('No migrations found')
|
// Migrate old config to sync config
|
||||||
|
const vuexState = await storage.getItem('vuex-lz')
|
||||||
|
defaultStateKeys.forEach(key => {
|
||||||
|
this.setPreference({ path: `simple.${key}`, value: vuexState.config[key] })
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data._version > VERSION) {
|
if (data._version > VERSION) {
|
||||||
|
|
@ -442,7 +449,7 @@ export const _doMigrations = (cache, live) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cache
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useSyncConfigStore = defineStore('sync_config', {
|
export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
|
|
@ -602,8 +609,7 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
})
|
})
|
||||||
this.flagStorage.reset = COMMAND_WIPE_JOURNAL_AND_STORAGE
|
this.flagStorage.reset = COMMAND_WIPE_JOURNAL_AND_STORAGE
|
||||||
},
|
},
|
||||||
initSyncConfig(userData) {
|
async initSyncConfig(userData) {
|
||||||
console.log(userData)
|
|
||||||
const live = userData.storage
|
const live = userData.storage
|
||||||
this.raw = live
|
this.raw = live
|
||||||
let cache = this.cache
|
let cache = this.cache
|
||||||
|
|
@ -630,8 +636,8 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
recent = recent && _doMigrations(recent)
|
recent = recent && await _doMigrations(recent)
|
||||||
stale = stale && _doMigrations(stale)
|
stale = stale && await _doMigrations(stale)
|
||||||
|
|
||||||
if (!needUpload && recent && stale) {
|
if (!needUpload && recent && stale) {
|
||||||
console.debug('Checking if data needs merging...')
|
console.debug('Checking if data needs merging...')
|
||||||
|
|
@ -671,6 +677,7 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
}
|
}
|
||||||
this.flagStorage = this.cache.flagStorage
|
this.flagStorage = this.cache.flagStorage
|
||||||
this.prefsStorage = this.cache.prefsStorage
|
this.prefsStorage = this.cache.prefsStorage
|
||||||
|
this.pushSyncConfig()
|
||||||
},
|
},
|
||||||
pushSyncConfig({ force = false } = {}) {
|
pushSyncConfig({ force = false } = {}) {
|
||||||
const needPush = this.dirty || force
|
const needPush = this.dirty || force
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue