rename prefs to highlight, fix highlight journal replay

This commit is contained in:
Henry Jameson 2026-03-13 12:18:09 +02:00
commit 314dc3888c

View file

@ -51,7 +51,7 @@ const _wrapData = (data, userName) => {
const _checkValidity = (data) => data._timestamp > 0 const _checkValidity = (data) => data._timestamp > 0
const _verifyPrefs = (state) => { const _verifyHighlights = (state) => {
state.highlight = state.highlight || {} state.highlight = state.highlight || {}
// Simple // Simple
@ -148,7 +148,7 @@ const _mergeJournal = (...journals) => {
) )
} }
export const _mergePrefs = (recent, stale) => { export const _mergeHighlights = (recent, stale) => {
if (!stale) return recent if (!stale) return recent
if (!recent) return stale if (!recent) return stale
const { _journal: recentJournal, ...recentData } = recent const { _journal: recentJournal, ...recentData } = recent
@ -163,8 +163,8 @@ export const _mergePrefs = (recent, stale) => {
* to requested one. Intended only to be used with simple preferences (boolean, number) * to requested one. Intended only to be used with simple preferences (boolean, number)
*/ */
const resultOutput = { ...recentData } const resultOutput = { ...recentData }
const totalJournal = _mergeJournal(staleJournal, recentJournal) const Journal = _mergeJournal(staleJournal, recentJournal)
totalJournal.forEach(({ user, operation, args }) => { Journal.forEach(({ user, operation, args }) => {
if (user.startsWith('_')) { if (user.startsWith('_')) {
throw new Error( throw new Error(
`journal contains entry to edit internal (starts with _) field '${user}', something is incorrect here, ignoring.`, `journal contains entry to edit internal (starts with _) field '${user}', something is incorrect here, ignoring.`,
@ -172,16 +172,16 @@ export const _mergePrefs = (recent, stale) => {
} }
switch (operation) { switch (operation) {
case 'set': case 'set':
resultOutput.highlight[user] = args[0] resultOutput[user] = args[0]
break break
case 'unset': case 'unset':
delete resultOutput.highlight[user] delete resultOutput[user]
break break
default: default:
return console.error(`Unknown journal operation: '${operation}'`) return console.error(`Unknown journal operation: '${operation}'`)
} }
}) })
return { ...resultOutput, _journal: totalJournal } return { ...resultOutput, _journal: Journal }
} }
export const useUserHighlightStore = defineStore('user_highlight', { export const useUserHighlightStore = defineStore('user_highlight', {
@ -305,17 +305,17 @@ export const useUserHighlightStore = defineStore('user_highlight', {
console.debug(`Data ${dirty ? 'needs' : "doesn't need"} merging`) console.debug(`Data ${dirty ? 'needs' : "doesn't need"} merging`)
} }
let totalPrefs let highlights
if (dirty) { if (dirty) {
console.debug('Merging the data...') console.debug('Merging the data...')
_verifyPrefs(recent) _verifyHighlights(recent)
_verifyPrefs(stale) _verifyHighlights(stale)
totalPrefs = _mergePrefs(recent.highlight, stale.highlight) highlights = _mergeHighlights(recent.highlight, stale.highlight)
} else { } else {
totalPrefs = recent.highlight highlights = recent.highlight
} }
recent.highlight = { ...defaultState.highlight, ...totalPrefs } recent.highlight = { ...defaultState.highlight, ...highlights }
this.dirty = dirty || needUpload this.dirty = dirty || needUpload
this.cache = recent this.cache = recent