wip proper migration of mutewords/theme3hacks
This commit is contained in:
parent
59ebce47bd
commit
e05ffbb350
4 changed files with 34 additions and 91 deletions
|
|
@ -1,47 +0,0 @@
|
||||||
import { storage } from 'src/lib/storage.js'
|
|
||||||
|
|
||||||
export const CONFIG_MIGRATION = 1
|
|
||||||
|
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
|
||||||
|
|
||||||
// for future use
|
|
||||||
/*
|
|
||||||
const simpleDeclaration = {
|
|
||||||
store: 'server-side',
|
|
||||||
migrationFlag: 'configMigration',
|
|
||||||
migration(serverside, rootState) {
|
|
||||||
serverside.setSimplePrefAndSave({ path: field, value: rootState.config[oldField ?? field] })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const declarations = [
|
|
||||||
{
|
|
||||||
field: 'muteFilters',
|
|
||||||
store: 'server-side',
|
|
||||||
migrationFlag: 'configMigration',
|
|
||||||
migrationNum: 1,
|
|
||||||
description: 'Mute filters, wordfilter/regexp/etc',
|
|
||||||
valueType: 'complex',
|
|
||||||
migration: async (serverside, rootState) => {
|
|
||||||
const vuexState = (await storage.getItem('vuex-lz')) ?? {}
|
|
||||||
|
|
||||||
vuexState.config?.muteWords?.forEach((word, order) => {
|
|
||||||
const uniqueId = uuidv4()
|
|
||||||
|
|
||||||
serverside.setPreference({
|
|
||||||
path: 'simple.muteFilters.' + uniqueId,
|
|
||||||
value: {
|
|
||||||
type: 'word',
|
|
||||||
value: word,
|
|
||||||
name: word,
|
|
||||||
enabled: true,
|
|
||||||
expires: null,
|
|
||||||
hide: false,
|
|
||||||
order,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
@ -531,18 +531,17 @@ export const INSTANCE_DEFAULT_CONFIG_DEFINITIONS = {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
theme3hacks: {
|
|
||||||
description: 'Theme 3 hacks (need separation)',
|
|
||||||
type: 'object',
|
|
||||||
required: false,
|
|
||||||
default: {},
|
|
||||||
},
|
|
||||||
highlights: {
|
highlights: {
|
||||||
description: 'User highlights',
|
description: 'User highlights',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: false,
|
required: false,
|
||||||
default: {},
|
default: {},
|
||||||
},
|
},
|
||||||
|
underlay: {
|
||||||
|
description: 'Underlay override',
|
||||||
|
required: true,
|
||||||
|
default: 'none',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
export const INSTANCE_DEFAULT_CONFIG = convertDefinitions(
|
export const INSTANCE_DEFAULT_CONFIG = convertDefinitions(
|
||||||
INSTANCE_DEFAULT_CONFIG_DEFINITIONS,
|
INSTANCE_DEFAULT_CONFIG_DEFINITIONS,
|
||||||
|
|
@ -634,11 +633,6 @@ export const LOCAL_DEFAULT_CONFIG_DEFINITIONS = {
|
||||||
description: 'Streaming API (WebSocket)',
|
description: 'Streaming API (WebSocket)',
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
underlay: {
|
|
||||||
description: 'Underlay override',
|
|
||||||
required: true,
|
|
||||||
default: 'none',
|
|
||||||
},
|
|
||||||
fontInterface: {
|
fontInterface: {
|
||||||
description: 'Interface font override',
|
description: 'Interface font override',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
|
@ -766,6 +760,7 @@ export const validateSetting = ({
|
||||||
if (value === undefined) return undefined // only null is allowed as missing value
|
if (value === undefined) return undefined // only null is allowed as missing value
|
||||||
if (definition === undefined) return undefined // invalid definition
|
if (definition === undefined) return undefined // invalid definition
|
||||||
const path = fullPath.replace(/^simple./, '')
|
const path = fullPath.replace(/^simple./, '')
|
||||||
|
const depth = path.split('.')
|
||||||
if (
|
if (
|
||||||
validateObjects &&
|
validateObjects &&
|
||||||
definition.type === 'object' &&
|
definition.type === 'object' &&
|
||||||
|
|
@ -777,12 +772,6 @@ export const validateSetting = ({
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.includes('muteFilters')) {
|
|
||||||
console.log('##', path, value, definition)
|
|
||||||
console.log(value)
|
|
||||||
console.log(path)
|
|
||||||
console.log('====')
|
|
||||||
}
|
|
||||||
if (get(defaultState, path.split('.')[0]) === undefined) {
|
if (get(defaultState, path.split('.')[0]) === undefined) {
|
||||||
const string = `Unknown option ${fullPath}, value: ${value}`
|
const string = `Unknown option ${fullPath}, value: ${value}`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,6 @@ import { useOAuthStore } from 'src/stores/oauth.js'
|
||||||
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
import { useSyncConfigStore } from 'src/stores/sync_config.js'
|
||||||
import { useUserHighlightStore } from 'src/stores/user_highlight.js'
|
import { useUserHighlightStore } from 'src/stores/user_highlight.js'
|
||||||
|
|
||||||
import { declarations } from 'src/modules/config_declaration'
|
|
||||||
|
|
||||||
// TODO: Unify with mergeOrAdd in statuses.js
|
// TODO: Unify with mergeOrAdd in statuses.js
|
||||||
export const mergeOrAdd = (arr, obj, item) => {
|
export const mergeOrAdd = (arr, obj, item) => {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
|
|
@ -742,25 +740,6 @@ const users = {
|
||||||
useSyncConfigStore().setFlag({ flag: 'configMigration', value: 0 })
|
useSyncConfigStore().setFlag({ flag: 'configMigration', value: 0 })
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
const { configMigration } = useSyncConfigStore().flagStorage
|
|
||||||
declarations
|
|
||||||
.filter((x) => {
|
|
||||||
return (
|
|
||||||
x.store === 'server-side' &&
|
|
||||||
x.migrationNum > 0 &&
|
|
||||||
x.migrationNum > configMigration
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.toSorted((a, b) => a.configMigration - b.configMigration)
|
|
||||||
.forEach((value) => {
|
|
||||||
value.migration(useSyncConfigStore(), store.rootState)
|
|
||||||
useSyncConfigStore().setFlag({
|
|
||||||
flag: 'configMigration',
|
|
||||||
value: value.migrationNum,
|
|
||||||
})
|
|
||||||
useSyncConfigStore().pushSyncConfig()
|
|
||||||
})
|
|
||||||
|
|
||||||
if (user.token) {
|
if (user.token) {
|
||||||
dispatch('setWsToken', user.token)
|
dispatch('setWsToken', user.token)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import {
|
||||||
uniqWith,
|
uniqWith,
|
||||||
unset,
|
unset,
|
||||||
} from 'lodash'
|
} from 'lodash'
|
||||||
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { toRaw } from 'vue'
|
import { toRaw } from 'vue'
|
||||||
|
|
||||||
|
|
@ -676,21 +677,24 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
// Various migrations
|
// Various migrations
|
||||||
console.debug('Migrating from old config')
|
console.debug('Migrating from old config')
|
||||||
const vuexState = (await storage.getItem('vuex-lz')) ?? {}
|
const vuexState = (await storage.getItem('vuex-lz')) ?? {}
|
||||||
vuexState.config = vuexState.config ?? {}
|
const config = vuexState.config ?? {}
|
||||||
|
|
||||||
const migratedEntries = new Set(vuexState.config._syncMigration ?? [])
|
const migratedEntries = new Set(config._syncMigration ?? [])
|
||||||
console.debug(
|
console.debug(
|
||||||
`Already migrated Values: ${[...migratedEntries].join() || '[none]'}`,
|
`Already migrated Values: ${[...migratedEntries].join() || '[none]'}`,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const { configMigration } = useSyncConfigStore().flagStorage
|
||||||
|
|
||||||
Object.entries(oldDefaultConfigSync).forEach(([key, value]) => {
|
Object.entries(oldDefaultConfigSync).forEach(([key, value]) => {
|
||||||
const oldValue = vuexState.config[key]
|
const oldValue = config[key]
|
||||||
const defaultValue = value
|
const defaultValue = value
|
||||||
|
|
||||||
const present = oldValue !== undefined
|
const present = oldValue !== undefined
|
||||||
const migrated = migratedEntries.has(key)
|
const migrated = migratedEntries.has(key)
|
||||||
const different = !isEqual(oldValue, defaultValue)
|
const different = !isEqual(oldValue, defaultValue)
|
||||||
|
|
||||||
|
console.log(key, oldValue)
|
||||||
if (present && !migrated && different) {
|
if (present && !migrated && different) {
|
||||||
console.debug(`Migrating config ${key}: ${oldValue}`)
|
console.debug(`Migrating config ${key}: ${oldValue}`)
|
||||||
if (key === 'theme3hacks') {
|
if (key === 'theme3hacks') {
|
||||||
|
|
@ -710,10 +714,27 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
path: 'fontMonospace',
|
path: 'fontMonospace',
|
||||||
value: oldValue.fonts.monospace,
|
value: oldValue.fonts.monospace,
|
||||||
})
|
})
|
||||||
useLocalConfigStore().set({
|
useSyncConfigStore().set({
|
||||||
path: 'underlay',
|
path: 'underlay',
|
||||||
value: oldValue.underlay,
|
value: oldValue.underlay,
|
||||||
})
|
})
|
||||||
|
} else if (key == 'muteWords') {
|
||||||
|
oldValue.forEach((word, order) => {
|
||||||
|
const uniqueId = uuidv4()
|
||||||
|
|
||||||
|
useSyncConfigStore().setPreference({
|
||||||
|
path: 'simple.muteFilters.' + uniqueId,
|
||||||
|
value: {
|
||||||
|
type: 'word',
|
||||||
|
value: word,
|
||||||
|
name: word,
|
||||||
|
enabled: true,
|
||||||
|
expires: null,
|
||||||
|
hide: false,
|
||||||
|
order,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
this.setPreference({ path: `simple.${key}`, value: oldValue })
|
this.setPreference({ path: `simple.${key}`, value: oldValue })
|
||||||
}
|
}
|
||||||
|
|
@ -722,8 +743,9 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
vuexState.config._syncMigration = [...migratedEntries]
|
config._syncMigration = [...migratedEntries]
|
||||||
storage.setItem('vuex-lz', vuexState)
|
vuexState.config = config
|
||||||
|
//storage.setItem('vuex-lz', vuexState)
|
||||||
|
|
||||||
if (!needUpload && recent && stale) {
|
if (!needUpload && recent && stale) {
|
||||||
console.debug('Checking if data needs merging...')
|
console.debug('Checking if data needs merging...')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue