Compare commits

..

No commits in common. "b21685cb0c497633774221a3e34021aea7a36eb7" and "d03ca88eba05c8ca900c5a9339b2dded6d05a9bd" have entirely different histories.

13 changed files with 63 additions and 79 deletions

View file

@ -4,7 +4,6 @@ import { mapGetters } from 'vuex'
import { useAnnouncementsStore } from 'src/stores/announcements.js'
import { useInterfaceStore } from 'src/stores/interface.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js'
import { library } from '@fortawesome/fontawesome-svg-core'
import {

View file

@ -325,8 +325,7 @@ const PostStatusForm = {
},
hideScopeNotice() {
return (
this.disableNotice ||
useMergedConfigStore().mergedConfig.hideScopeNotice
this.disableNotice || useMergedConfigStore().mergedConfig.hideScopeNotice
)
},
pollContentError() {

View file

@ -10,8 +10,8 @@ import Popover from '../popover/popover.vue'
import { useInterfaceStore } from 'src/stores/interface.js'
import { useLocalConfigStore } from 'src/stores/local_config.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { LOCAL_ONLY_KEYS } from 'src/modules/default_config_state.js'
import {

View file

@ -1,9 +1,9 @@
import { useEditStatusStore } from 'src/stores/editStatus.js'
import { useInstanceStore } from 'src/stores/instance.js'
import { useInstanceCapabilitiesStore } from 'src/stores/instance_capabilities.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useReportsStore } from 'src/stores/reports.js'
import { useStatusHistoryStore } from 'src/stores/statusHistory.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
const PRIVATE_SCOPES = new Set(['private', 'direct'])
const PUBLIC_SCOPES = new Set(['public', 'unlisted'])

View file

@ -661,8 +661,8 @@ export const SYNC_DEFAULT_CONFIG_DEFINITIONS = {
},
collapseNav: {
description: 'Collapse navigation panel to header only',
default: false,
},
default: false
}
}
export const SYNC_DEFAULT_CONFIG = convertDefinitions(
SYNC_DEFAULT_CONFIG_DEFINITIONS,
@ -675,14 +675,12 @@ export const THEME_CONFIG_DEFINITIONS = {
default: null,
},
colors: {
description:
'VERY old theme store, just colors of V1, probably not even used anymore',
description: 'VERY old theme store, just colors of V1, probably not even used anymore',
default: {},
},
// V2
customTheme: {
description:
'"Snapshot", previously was used as actual theme store for V2 so it\'s still used in case of PleromaFE downgrade event.',
description: '"Snapshot", previously was used as actual theme store for V2 so it\'s still used in case of PleromaFE downgrade event.',
default: null,
},
customThemeSource: {
@ -707,7 +705,9 @@ export const THEME_CONFIG_DEFINITIONS = {
default: null,
},
}
export const THEME_CONFIG = convertDefinitions(THEME_CONFIG_DEFINITIONS)
export const THEME_CONFIG = convertDefinitions(
THEME_CONFIG_DEFINITIONS,
)
export const makeUndefined = (c) =>
Object.fromEntries(Object.keys(c).map((key) => [key, undefined]))

View file

@ -7,8 +7,8 @@ import { useInstanceStore } from 'src/stores/instance'
import {
LOCAL_DEFAULT_CONFIG,
LOCAL_DEFAULT_CONFIG_DEFINITIONS,
makeUndefined,
validateSetting,
makeUndefined,
} from 'src/modules/default_config_state'
export const defaultState = {
@ -57,9 +57,7 @@ export const useLocalConfigStore = defineStore('local_config', {
persist: {
afterLoad(state) {
return {
prefsStorage: state.prefsStorage ?? {
...makeUndefined(LOCAL_DEFAULT_CONFIG),
},
prefsStorage: state.prefsStorage ?? { ...makeUndefined(LOCAL_DEFAULT_CONFIG) },
tempStorage: { ...makeUndefined(LOCAL_DEFAULT_CONFIG) },
}
},

View file

@ -7,8 +7,8 @@ import { useSyncConfigStore } from 'src/stores/sync_config.js'
import {
INSTANCE_DEFAULT_CONFIG,
LOCAL_DEFAULT_CONFIG,
LOCAL_ONLY_KEYS,
THEME_CONFIG,
LOCAL_ONLY_KEYS,
} from 'src/modules/default_config_state.js'
const ROOT_CONFIG = {
@ -35,7 +35,10 @@ export const useMergedConfigStore = defineStore('merged_config', {
const getDefault = (k) => instancePrefs[k] ?? ROOT_CONFIG[k]
const result = Object.fromEntries(
Object.keys(ROOT_CONFIG).map((k) => [k, getValue(k) ?? getDefault(k)]),
Object.keys(ROOT_CONFIG).map((k) => [
k,
getValue(k) ?? getDefault(k),
]),
)
return result
},
@ -45,7 +48,10 @@ export const useMergedConfigStore = defineStore('merged_config', {
const getDefault = (k) => instancePrefs[k] ?? ROOT_CONFIG[k]
const result = Object.fromEntries(
Object.keys(ROOT_CONFIG).map((k) => [k, getDefault(k)]),
Object.keys(ROOT_CONFIG).map((k) => [
k,
getDefault(k),
]),
)
return result
},
@ -59,7 +65,10 @@ export const useMergedConfigStore = defineStore('merged_config', {
tempPrefs[k] ?? localPrefs[k] ?? syncPrefs.simple[k] ?? instancePrefs[k]
const result = Object.fromEntries(
Object.keys(ROOT_CONFIG).map(([k, value]) => [k, getValue(k)]),
Object.keys(ROOT_CONFIG).map(([k, value]) => [
k,
getValue(k),
]),
)
return result
},

View file

@ -24,10 +24,10 @@ import { useLocalConfigStore } from 'src/stores/local_config.js'
import { storage } from 'src/lib/storage.js'
import {
makeUndefined,
ROOT_CONFIG,
ROOT_CONFIG_DEFINITIONS,
validateSetting,
makeUndefined,
} from 'src/modules/default_config_state.js'
import { oldDefaultConfigSync } from 'src/modules/old_default_config_state.js'
@ -297,7 +297,7 @@ export const _mergePrefs = (recent, stale) => {
)
}
switch (operation) {
case 'set': {
case 'set':
if (path.startsWith('collections')) {
return console.error('Illegal operation "set" on a collection')
}
@ -306,22 +306,8 @@ export const _mergePrefs = (recent, stale) => {
`Calling set on depth <= 1 (path: ${path}) is not allowed`,
)
}
const definition = path.startsWith('simple.muteFilters')
? { default: {} }
: ROOT_CONFIG_DEFINITIONS[path.split('.')[1]]
const finalValue = validateSetting({
path: path.split('.')[1],
value: args[0],
definition,
throwError: false,
defaultState: ROOT_CONFIG,
})
set(resultOutput, path, finalValue)
set(resultOutput, path, args[0])
break
}
case 'unset':
if (path.startsWith('collections')) {
return console.error('Illegal operation "unset" on a collection')
@ -502,8 +488,8 @@ export const useSyncConfigStore = defineStore('sync_config', {
}
const definition = path.startsWith('simple.muteFilters')
? { default: {} }
: ROOT_CONFIG_DEFINITIONS[path.split('.')[1]]
? { default: {} }
: ROOT_CONFIG_DEFINITIONS[path.split('.')[1]]
const finalValue = validateSetting({
path: path.split('.')[1],

View file

@ -153,9 +153,8 @@ const _mergeJournal = (...journals) => {
export const _mergeHighlights = (recent, stale) => {
if (!stale) return recent
if (!recent) return stale
const { _journal: recentJournal, highlight: recentHighlight } = recent
const { _journal: recentJournal, ...recentData } = recent
const { _journal: staleJournal } = stale
console.log(recentHighlight)
/** Journal entry format:
* user: user to entry in highlight storage
* timestamp: timestamp of the change
@ -165,7 +164,7 @@ export const _mergeHighlights = (recent, stale) => {
* currently only supported operation type is "set" which just sets the value
* to requested one. Intended only to be used with simple preferences (boolean, number)
*/
const resultHighlight = { ...recentHighlight }
const resultOutput = { ...recentData }
const Journal = _mergeJournal(staleJournal, recentJournal)
Journal.forEach(({ user, operation, args }) => {
if (user.startsWith('_')) {
@ -175,16 +174,16 @@ export const _mergeHighlights = (recent, stale) => {
}
switch (operation) {
case 'set':
resultHighlight[user] = args[0]
resultOutput[user] = args[0]
break
case 'unset':
delete resultHighlight[user]
delete resultOutput[user]
break
default:
return console.error(`Unknown journal operation: '${operation}'`)
}
})
return { highlight: resultHighlight, _journal: Journal }
return { ...resultOutput, _journal: Journal }
}
export const useUserHighlightStore = defineStore('user_highlight', {
@ -334,6 +333,7 @@ export const useUserHighlightStore = defineStore('user_highlight', {
this.cache._timestamp = Math.min(stale._timestamp, recent._timestamp)
}
this.highlight = this.cache.highlight
this.pushHighlight()
},
pushHighlight({ force = false } = {}) {
const needPush = this.dirty || force

View file

@ -6,7 +6,7 @@ import { nextTick } from 'vue'
import PostStatusForm from 'src/components/post_status_form/post_status_form.vue'
import { $t, mountOpts, waitForEvent } from '../../../fixtures/setup_test'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js'
const autoSaveOrNot = (caseFn, caseTitle, runFn) => {
caseFn(`${caseTitle} with auto-save`, function () {
@ -48,7 +48,7 @@ describe('Draft saving', () => {
'should save when the button is clicked',
async (autoSave) => {
const wrapper = mount(PostStatusForm, mountOpts())
const store = useMergedConfigStore()
const store = useSyncConfigStore()
store.mergedConfig = {
autoSaveDraft: autoSave,
}
@ -68,7 +68,7 @@ describe('Draft saving', () => {
it('should auto-save if it is enabled', async function () {
vi.useFakeTimers()
const wrapper = mount(PostStatusForm, mountOpts())
const store = useMergedConfigStore()
const store = useSyncConfigStore()
store.mergedConfig = {
autoSaveDraft: true,
}
@ -91,7 +91,7 @@ describe('Draft saving', () => {
},
}),
)
const store = useMergedConfigStore()
const store = useSyncConfigStore()
store.mergedConfig = {
autoSaveDraft: true,
}
@ -112,7 +112,7 @@ describe('Draft saving', () => {
},
}),
)
const store = useMergedConfigStore()
const store = useSyncConfigStore()
store.mergedConfig = {
autoSaveDraft: false,
unsavedPostAction: 'save',
@ -134,7 +134,7 @@ describe('Draft saving', () => {
},
}),
)
const store = useMergedConfigStore()
const store = useSyncConfigStore()
store.mergedConfig = {
autoSaveDraft: false,
unsavedPostAction: 'discard',
@ -156,7 +156,7 @@ describe('Draft saving', () => {
},
}),
)
const store = useMergedConfigStore(createTestingPinia())
const store = useSyncConfigStore(createTestingPinia())
store.mergedConfig = {
autoSaveDraft: false,
unsavedPostAction: 'confirm',

View file

@ -7,7 +7,7 @@ createTestingPinia()
import EmojiInput from 'src/components/emoji_input/emoji_input.vue'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js'
const generateInput = (value, padEmoji = true) => {
const wrapper = shallowMount(EmojiInput, {
@ -45,7 +45,7 @@ const generateInput = (value, padEmoji = true) => {
describe('EmojiInput', () => {
beforeEach(() => {
const store = useMergedConfigStore(createTestingPinia())
const store = useSyncConfigStore(createTestingPinia())
store.mergedConfig = {
padEmoji: true,
}
@ -113,7 +113,7 @@ describe('EmojiInput', () => {
it('inserts string without any padding if padEmoji setting is set to false', () => {
const initialString = 'Eat some spam!'
const wrapper = generateInput(initialString, false)
const store = useMergedConfigStore(createTestingPinia())
const store = useSyncConfigStore(createTestingPinia())
store.mergedConfig = {
padEmoji: false,
}
@ -152,7 +152,7 @@ describe('EmojiInput', () => {
it('correctly sets caret after insertion if padEmoji setting is set to false', async () => {
const initialString = '1234'
const wrapper = generateInput(initialString, false)
const store = useMergedConfigStore(createTestingPinia())
const store = useSyncConfigStore(createTestingPinia())
store.mergedConfig = {
padEmoji: false,
}

View file

@ -1,6 +1,8 @@
import { cloneDeep } from 'lodash'
import { createPinia, setActivePinia } from 'pinia'
import { CURRENT_UPDATE_COUNTER } from 'src/components/update_notification/update_notification.js'
import {
_getAllFlags,
_getRecentData,
@ -73,7 +75,7 @@ describe('The SyncConfig store', () => {
_version: VERSION,
flagStorage: {
...defaultState.flagStorage,
updateCounter: 1,
updateCounter: CURRENT_UPDATE_COUNTER,
},
prefsStorage: {
...defaultState.prefsStorage,
@ -83,7 +85,7 @@ describe('The SyncConfig store', () => {
expect(store.flagStorage).to.eql({
...defaultState.flagStorage,
updateCounter: 1,
updateCounter: CURRENT_UPDATE_COUNTER,
})
})
@ -116,7 +118,7 @@ describe('The SyncConfig store', () => {
_version: VERSION,
flagStorage: {
...defaultState.flagStorage,
updateCounter: 1,
updateCounter: CURRENT_UPDATE_COUNTER,
},
prefsStorage: {
...defaultState.prefsStorage,

View file

@ -3,7 +3,7 @@ import { createPinia, setActivePinia } from 'pinia'
import {
_getRecentData,
_mergeHighlights,
_mergePrefs,
_moveItemInArray,
useUserHighlightStore,
} from 'src/stores/user_highlight.js'
@ -11,15 +11,6 @@ import {
describe('The UserHighlight store', () => {
beforeEach(() => {
setActivePinia(createPinia())
window.vuex = {
state: {
users: {
currentUser: {
fqn: 'foo@bar.tld',
},
},
},
}
})
describe('mutations', () => {
@ -29,23 +20,23 @@ describe('The UserHighlight store', () => {
storage: {},
}
it('should initialize storage if none present', async () => {
it('should initialize storage if none present', () => {
const store = useUserHighlightStore()
await store.initUserHighlight({ ...user })
store.initUserHighlight({ ...user })
expect(store.cache._timestamp).to.be.a('number')
expect(store.cache.highlight).to.eql({ _journal: [] })
})
it('should initialize storage for new users if none present', async () => {
it('should initialize storage for new users if none present', () => {
const store = useUserHighlightStore()
await store.initUserHighlight({ ...user, created_at: new Date() })
store.initUserHighlight({ ...user, created_at: new Date() })
expect(store.cache._timestamp).to.be.a('number')
expect(store.cache.highlight).to.eql({ _journal: [] })
})
it('should use remote version if local missing', async () => {
it('should use remote version if local missing', () => {
const store = useUserHighlightStore()
await store.initUserHighlight(store, user)
store.initUserHighlight(store, user)
expect(store.cache._timestamp).to.be.a('number')
})
})
@ -170,10 +161,10 @@ describe('The UserHighlight store', () => {
})
})
describe('_mergeHighlights', () => {
describe('_mergePrefs', () => {
it('should prefer recent and apply journal to it', () => {
expect(
_mergeHighlights(
_mergePrefs(
// RECENT
{
highlight: {
@ -236,7 +227,7 @@ describe('The UserHighlight store', () => {
it('should work with objects', () => {
expect(
_mergeHighlights(
_mergePrefs(
// RECENT
{
highlight: { 'a@test.xyz': { type: 'foo' } },
@ -277,7 +268,7 @@ describe('The UserHighlight store', () => {
it('should work with unset', () => {
expect(
_mergeHighlights(
_mergePrefs(
// RECENT
{
highlight: { 'a@test.xyz': { type: 'foo' } },