make a separate file to store all information about fields and their migrations
This commit is contained in:
parent
55be9965db
commit
dfbd17ea37
3 changed files with 55 additions and 29 deletions
42
src/modules/config_declaration.js
Normal file
42
src/modules/config_declaration.js
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
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.setPreference({ path: 'simple.' + 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 (serverside, rootState) {
|
||||||
|
rootState.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
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { compact, map, each, mergeWith, last, concat, uniq, isArray } from 'lodash'
|
import { compact, map, each, mergeWith, last, concat, uniq, isArray } from 'lodash'
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
|
||||||
|
|
||||||
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
|
||||||
import { windowWidth, windowHeight } from '../services/window_utils/window_utils'
|
import { windowWidth, windowHeight } from '../services/window_utils/window_utils'
|
||||||
|
|
@ -9,7 +8,9 @@ import { registerPushNotifications, unregisterPushNotifications } from '../servi
|
||||||
|
|
||||||
import { useInterfaceStore } from 'src/stores/interface.js'
|
import { useInterfaceStore } from 'src/stores/interface.js'
|
||||||
import { useOAuthStore } from 'src/stores/oauth.js'
|
import { useOAuthStore } from 'src/stores/oauth.js'
|
||||||
import { useServerSideStorageStore, CONFIG_MIGRATION } from 'src/stores/serverSideStorage'
|
import { useServerSideStorageStore } from 'src/stores/serverSideStorage'
|
||||||
|
|
||||||
|
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) => {
|
||||||
|
|
@ -637,33 +638,17 @@ const users = {
|
||||||
/**/
|
/**/
|
||||||
|
|
||||||
const { configMigration } = useServerSideStorageStore().flagStorage
|
const { configMigration } = useServerSideStorageStore().flagStorage
|
||||||
|
declarations
|
||||||
// Wordfilter migration
|
.filter(x => {
|
||||||
if (configMigration < 1) {
|
return x.store === 'server-side' &&
|
||||||
// Convert existing wordfilter into synced one
|
(x.migrationNum ?? x.migrationNum > configMigration)
|
||||||
store.rootState.config.muteWords.forEach((word, order) => {
|
})
|
||||||
const uniqueId = uuidv4()
|
.toSorted((a, b) => a.configMigration - b.configMigration)
|
||||||
|
.forEach(value => {
|
||||||
useServerSideStorageStore().setPreference({
|
value.migration(useServerSideStorageStore(), store.rootState)
|
||||||
path: 'simple.muteFilters.' + uniqueId,
|
useServerSideStorageStore().setFlag({ flag: 'configMigration', value: value.migrationNum })
|
||||||
value: {
|
useServerSideStorageStore().pushServerSideStorage()
|
||||||
type: 'word',
|
|
||||||
value: word,
|
|
||||||
name: word,
|
|
||||||
enabled: true,
|
|
||||||
expires: null,
|
|
||||||
hide: false,
|
|
||||||
order
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
if (configMigration < CONFIG_MIGRATION) {
|
|
||||||
// Update the flag
|
|
||||||
useServerSideStorageStore().setFlag({ flag: 'configMigration', value: CONFIG_MIGRATION })
|
|
||||||
useServerSideStorageStore().pushServerSideStorage()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user.token) {
|
if (user.token) {
|
||||||
dispatch('setWsToken', user.token)
|
dispatch('setWsToken', user.token)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import {
|
||||||
import { CURRENT_UPDATE_COUNTER } from 'src/components/update_notification/update_notification.js'
|
import { CURRENT_UPDATE_COUNTER } from 'src/components/update_notification/update_notification.js'
|
||||||
|
|
||||||
export const VERSION = 1
|
export const VERSION = 1
|
||||||
export const CONFIG_MIGRATION = 1
|
|
||||||
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
|
||||||
|
|
||||||
export const COMMAND_TRIM_FLAGS = 1000
|
export const COMMAND_TRIM_FLAGS = 1000
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue