2022-05-22 16:40:59 +00:00
|
|
|
import Cookies from 'js-cookie'
|
2024-07-10 22:49:56 +03:00
|
|
|
import { applyConfig } from '../services/style_setter/style_setter.js'
|
2020-06-08 17:22:07 +02:00
|
|
|
import messages from '../i18n/messages'
|
2023-03-12 14:32:13 +02:00
|
|
|
import { set } from 'lodash'
|
2022-05-22 16:40:59 +00:00
|
|
|
import localeService from '../services/locale/locale.service.js'
|
2025-02-03 13:02:14 +02:00
|
|
|
import { useI18nStore } from 'src/stores/i18n.js'
|
|
|
|
|
import { useInterfaceStore } from 'src/stores/interface.js'
|
2022-05-22 16:40:59 +00:00
|
|
|
|
2025-01-30 21:56:07 +02:00
|
|
|
import { defaultState } from './default_config_state.js'
|
|
|
|
|
|
2022-05-22 16:40:59 +00:00
|
|
|
const BACKEND_LANGUAGE_COOKIE_NAME = 'userLanguage'
|
2024-07-10 22:49:56 +03:00
|
|
|
const APPEARANCE_SETTINGS_KEYS = new Set([
|
|
|
|
|
'sidebarColumnWidth',
|
|
|
|
|
'contentColumnWidth',
|
|
|
|
|
'notifsColumnWidth',
|
|
|
|
|
'textSize',
|
|
|
|
|
'navbarSize',
|
|
|
|
|
'panelHeaderSize',
|
|
|
|
|
'forcedRoundness',
|
|
|
|
|
'emojiSize',
|
|
|
|
|
'emojiReactionsScale'
|
|
|
|
|
])
|
2017-02-14 22:21:23 +01:00
|
|
|
|
2020-05-26 22:50:37 +03:00
|
|
|
/* TODO this is a bit messy.
|
|
|
|
|
* We need to declare settings with their types and also deal with
|
|
|
|
|
* instance-default settings in some way, hopefully try to avoid copy-pasta
|
|
|
|
|
* in general.
|
|
|
|
|
*/
|
|
|
|
|
export const multiChoiceProperties = [
|
|
|
|
|
'postContentType',
|
2022-01-10 01:16:33 -05:00
|
|
|
'subjectLineBehavior',
|
2021-08-06 20:18:27 -04:00
|
|
|
'conversationDisplay', // tree | linear
|
2021-09-05 16:35:47 -04:00
|
|
|
'conversationOtherRepliesButton', // below | inside
|
2022-08-09 10:44:20 +03:00
|
|
|
'mentionLinkDisplay', // short | full_for_remote | full
|
2023-04-06 14:15:57 -04:00
|
|
|
'userPopoverAvatarAction', // close | zoom | open
|
|
|
|
|
'unsavedPostAction' // save | discard | confirm
|
2020-05-26 22:50:37 +03:00
|
|
|
]
|
|
|
|
|
|
2019-09-29 22:33:15 +03:00
|
|
|
// caching the instance default properties
|
|
|
|
|
export const instanceDefaultProperties = Object.entries(defaultState)
|
|
|
|
|
.filter(([key, value]) => value === undefined)
|
|
|
|
|
.map(([key, value]) => key)
|
|
|
|
|
|
2017-02-14 22:21:23 +01:00
|
|
|
const config = {
|
2020-10-01 01:43:07 +03:00
|
|
|
state: { ...defaultState },
|
2019-09-29 22:33:15 +03:00
|
|
|
getters: {
|
2020-10-01 01:43:07 +03:00
|
|
|
defaultConfig (state, getters, rootState, rootGetters) {
|
2019-09-29 22:33:15 +03:00
|
|
|
const { instance } = rootState
|
2020-10-01 01:43:07 +03:00
|
|
|
return {
|
|
|
|
|
...defaultState,
|
|
|
|
|
...Object.fromEntries(
|
|
|
|
|
instanceDefaultProperties.map(key => [key, instance[key]])
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mergedConfig (state, getters, rootState, rootGetters) {
|
|
|
|
|
const { defaultConfig } = rootGetters
|
2019-09-29 22:33:15 +03:00
|
|
|
return {
|
2020-10-01 01:43:07 +03:00
|
|
|
...defaultConfig,
|
2021-06-14 10:58:32 +03:00
|
|
|
// Do not override with undefined
|
|
|
|
|
...Object.fromEntries(Object.entries(state).filter(([k, v]) => v !== undefined))
|
2019-09-29 22:33:15 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2017-02-14 22:21:23 +01:00
|
|
|
mutations: {
|
2024-05-22 19:54:19 +03:00
|
|
|
setOptionTemporarily (state, { name, value }) {
|
|
|
|
|
set(state, name, value)
|
|
|
|
|
applyConfig(state)
|
|
|
|
|
},
|
2017-02-14 22:21:23 +01:00
|
|
|
setOption (state, { name, value }) {
|
2023-03-12 14:32:13 +02:00
|
|
|
set(state, name, value)
|
2018-06-19 16:17:50 +03:00
|
|
|
},
|
2018-08-05 05:18:04 +03:00
|
|
|
setHighlight (state, { user, color, type }) {
|
|
|
|
|
const data = this.state.config.highlight[user]
|
|
|
|
|
if (color || type) {
|
2021-04-25 13:24:08 +03:00
|
|
|
state.highlight[user] = { color: color || data.color, type: type || data.type }
|
2018-06-19 16:17:50 +03:00
|
|
|
} else {
|
2021-04-25 13:24:08 +03:00
|
|
|
delete state.highlight[user]
|
2018-06-19 16:17:50 +03:00
|
|
|
}
|
2017-02-14 22:21:23 +01:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
actions: {
|
2021-03-08 19:53:30 +02:00
|
|
|
loadSettings ({ dispatch }, data) {
|
2021-03-08 21:56:20 +02:00
|
|
|
const knownKeys = new Set(Object.keys(defaultState))
|
2021-03-08 21:14:03 +02:00
|
|
|
const presentKeys = new Set(Object.keys(data))
|
|
|
|
|
const intersection = new Set()
|
2022-07-31 12:35:48 +03:00
|
|
|
for (const elem of presentKeys) {
|
2021-03-08 21:14:03 +02:00
|
|
|
if (knownKeys.has(elem)) {
|
|
|
|
|
intersection.add(elem)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 21:56:20 +02:00
|
|
|
intersection.forEach(
|
2021-03-08 19:53:30 +02:00
|
|
|
name => dispatch('setOption', { name, value: data[name] })
|
|
|
|
|
)
|
|
|
|
|
},
|
2018-08-05 05:18:04 +03:00
|
|
|
setHighlight ({ commit, dispatch }, { user, color, type }) {
|
2019-07-05 10:02:14 +03:00
|
|
|
commit('setHighlight', { user, color, type })
|
2018-06-19 16:17:50 +03:00
|
|
|
},
|
2024-05-22 19:54:19 +03:00
|
|
|
setOptionTemporarily ({ commit, dispatch, state, rootState }, { name, value }) {
|
2025-01-30 21:56:07 +02:00
|
|
|
if (useInterfaceStore().temporaryChangesTimeoutId !== null) {
|
2024-05-22 19:54:19 +03:00
|
|
|
console.warn('Can\'t track more than one temporary change')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
const oldValue = state[name]
|
|
|
|
|
|
|
|
|
|
commit('setOptionTemporarily', { name, value })
|
|
|
|
|
|
|
|
|
|
const confirm = () => {
|
|
|
|
|
dispatch('setOption', { name, value })
|
|
|
|
|
commit('clearTemporaryChanges')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const revert = () => {
|
|
|
|
|
commit('setOptionTemporarily', { name, value: oldValue })
|
|
|
|
|
commit('clearTemporaryChanges')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
commit('setTemporaryChanges', {
|
|
|
|
|
timeoutId: setTimeout(revert, 10000),
|
|
|
|
|
confirm,
|
|
|
|
|
revert
|
|
|
|
|
})
|
|
|
|
|
},
|
2024-07-12 02:40:57 +03:00
|
|
|
setThemeV2 ({ commit, dispatch }, { customTheme, customThemeSource }) {
|
2024-07-17 22:10:11 +03:00
|
|
|
commit('setOption', { name: 'theme', value: 'custom' })
|
2024-07-12 02:40:57 +03:00
|
|
|
commit('setOption', { name: 'customTheme', value: customTheme })
|
|
|
|
|
commit('setOption', { name: 'customThemeSource', value: customThemeSource })
|
|
|
|
|
dispatch('setTheme', { themeData: customThemeSource, recompile: true })
|
|
|
|
|
},
|
2022-06-05 17:10:44 +03:00
|
|
|
setOption ({ commit, dispatch, state }, { name, value }) {
|
2023-03-12 16:51:50 +02:00
|
|
|
const exceptions = new Set([
|
|
|
|
|
'useStreamingApi'
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
if (exceptions.has(name)) {
|
|
|
|
|
switch (name) {
|
|
|
|
|
case 'useStreamingApi': {
|
|
|
|
|
const action = value ? 'enableMastoSockets' : 'disableMastoSockets'
|
|
|
|
|
|
|
|
|
|
dispatch(action).then(() => {
|
|
|
|
|
commit('setOption', { name: 'useStreamingApi', value })
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
console.error('Failed starting MastoAPI Streaming socket', e)
|
|
|
|
|
dispatch('disableMastoSockets')
|
|
|
|
|
dispatch('setOption', { name: 'useStreamingApi', value: false })
|
|
|
|
|
})
|
2024-07-12 02:40:57 +03:00
|
|
|
break
|
2023-03-12 16:51:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
commit('setOption', { name, value })
|
2024-07-16 21:01:20 +03:00
|
|
|
if (APPEARANCE_SETTINGS_KEYS.has(name)) {
|
2022-06-05 17:10:44 +03:00
|
|
|
applyConfig(state)
|
2024-07-10 22:49:56 +03:00
|
|
|
}
|
2024-07-16 21:01:20 +03:00
|
|
|
if (name.startsWith('theme3hacks')) {
|
2024-12-22 16:49:42 +02:00
|
|
|
dispatch('applyTheme', { recompile: true })
|
2024-07-16 21:01:20 +03:00
|
|
|
}
|
2023-03-12 16:51:50 +02:00
|
|
|
switch (name) {
|
|
|
|
|
case 'theme':
|
2024-07-17 22:10:11 +03:00
|
|
|
if (value === 'custom') break
|
|
|
|
|
dispatch('setTheme', { themeName: value, recompile: true, saveData: true })
|
2023-03-12 16:51:50 +02:00
|
|
|
break
|
2024-06-21 23:28:24 +03:00
|
|
|
case 'themeDebug': {
|
2024-07-10 22:49:56 +03:00
|
|
|
dispatch('setTheme', { recompile: true })
|
2023-03-12 16:51:50 +02:00
|
|
|
break
|
2024-06-21 23:28:24 +03:00
|
|
|
}
|
2023-03-12 16:51:50 +02:00
|
|
|
case 'interfaceLanguage':
|
2025-01-30 18:08:05 +02:00
|
|
|
messages.setLanguage(useI18nStore().i18n, value)
|
2023-03-12 16:51:50 +02:00
|
|
|
dispatch('loadUnicodeEmojiData', value)
|
|
|
|
|
Cookies.set(
|
|
|
|
|
BACKEND_LANGUAGE_COOKIE_NAME,
|
|
|
|
|
localeService.internalToBackendLocaleMulti(value)
|
|
|
|
|
)
|
|
|
|
|
break
|
|
|
|
|
case 'thirdColumnMode':
|
2025-01-30 18:08:05 +02:00
|
|
|
useInterfaceStore().setLayoutWidth(undefined)
|
2023-03-12 16:51:50 +02:00
|
|
|
break
|
|
|
|
|
}
|
2017-02-14 22:21:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default config
|