Skip to content
Snippets Groups Projects
Commit 515d5451 authored by HJ's avatar HJ :fire:
Browse files

make a separate file to store all information about fields and their migrations

parent 55be9965
No related branches found
No related tags found
No related merge requests found
Pipeline #52409 failed
export const CONFIG_MIGRATION = 1
import { v4 as uuidv4 } from 'uuid';
// for future use
/*
const simpleDeclaration = {
store: 'server-side',
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
}
})
})
}
}
]
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 { 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 { 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
export const mergeOrAdd = (arr, obj, item) => {
......@@ -637,33 +638,17 @@ const users = {
/**/
const { configMigration } = useServerSideStorageStore().flagStorage
// Wordfilter migration
if (configMigration < 1) {
// Convert existing wordfilter into synced one
store.rootState.config.muteWords.forEach((word, order) => {
const uniqueId = uuidv4()
useServerSideStorageStore().setPreference({
path: 'simple.muteFilters.' + uniqueId,
value: {
type: 'word',
value: word,
name: word,
enabled: true,
expires: null,
hide: false,
order
}
})
declarations
.filter(x => {
return x.store === 'server-side' &&
(x.migrationNum ?? x.migrationNum > configMigration)
})
.toSorted((a, b) => a.configMigration - b.configMigration)
.forEach(value => {
value.migration(useServerSideStorageStore(), store.rootState)
useServerSideStorageStore().setFlag({ flag: 'configMigration', value: value.migrationNum })
useServerSideStorageStore().pushServerSideStorage()
})
}
if (configMigration < CONFIG_MIGRATION) {
// Update the flag
useServerSideStorageStore().setFlag({ flag: 'configMigration', value: CONFIG_MIGRATION })
useServerSideStorageStore().pushServerSideStorage()
}
if (user.token) {
dispatch('setWsToken', user.token)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment