2018-06-19 16:17:50 +03:00
|
|
|
import { set, delete as del } from 'vue'
|
2018-12-11 02:46:17 +03:00
|
|
|
import { setPreset, applyTheme } from '../services/style_setter/style_setter.js'
|
2020-06-08 17:22:07 +02:00
|
|
|
import messages from '../i18n/messages'
|
2017-02-14 22:21:23 +01:00
|
|
|
|
2018-08-25 13:12:33 +03:00
|
|
|
const browserLocale = (window.navigator.language || 'en').split('-')[0]
|
|
|
|
|
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',
|
|
|
|
'subjectLineBehavior'
|
|
|
|
]
|
|
|
|
|
2019-09-29 23:47:26 +03:00
|
|
|
export const defaultState = {
|
2017-02-23 00:04:47 +01:00
|
|
|
colors: {},
|
2020-01-22 00:37:19 +02:00
|
|
|
theme: undefined,
|
|
|
|
customTheme: undefined,
|
|
|
|
customThemeSource: undefined,
|
2019-11-10 14:42:01 -05:00
|
|
|
hideISP: false,
|
2020-12-16 18:25:07 +02:00
|
|
|
hideInstanceWallpaper: false,
|
2019-09-29 23:47:26 +03:00
|
|
|
// bad name: actually hides posts of muted USERS
|
2019-03-02 08:07:14 -05:00
|
|
|
hideMutedPosts: undefined, // instance default
|
2018-09-25 14:47:02 +03:00
|
|
|
collapseMessageWithSubject: undefined, // instance default
|
2019-09-23 20:29:01 +03:00
|
|
|
padEmoji: true,
|
2017-02-22 18:38:05 -05:00
|
|
|
hideAttachments: false,
|
2017-03-04 21:25:59 +01:00
|
|
|
hideAttachmentsInConv: false,
|
2019-02-27 14:38:58 +00:00
|
|
|
maxThumbnails: 16,
|
2017-04-09 15:53:23 +02:00
|
|
|
hideNsfw: true,
|
2018-12-12 03:42:29 +05:30
|
|
|
preloadImage: true,
|
2018-08-15 12:51:21 +03:00
|
|
|
loopVideo: true,
|
|
|
|
loopVideoSilentOnly: true,
|
2017-11-13 01:06:48 +02:00
|
|
|
streaming: false,
|
2020-02-11 12:24:51 +00:00
|
|
|
emojiReactionsOnTimeline: true,
|
2019-04-25 19:32:21 +03:00
|
|
|
autohideFloatingPostButton: false,
|
2018-08-15 12:51:21 +03:00
|
|
|
pauseOnUnfocused: true,
|
2018-08-18 13:56:45 +03:00
|
|
|
stopGifs: false,
|
2018-08-24 20:04:26 +01:00
|
|
|
replyVisibility: 'all',
|
2018-08-28 21:21:29 +03:00
|
|
|
notificationVisibility: {
|
|
|
|
follows: true,
|
|
|
|
mentions: true,
|
|
|
|
likes: true,
|
2019-12-11 00:00:10 +09:00
|
|
|
repeats: true,
|
2020-02-11 12:24:51 +00:00
|
|
|
moves: true,
|
2020-04-25 07:04:39 +03:00
|
|
|
emojiReactions: false,
|
2020-05-07 16:10:53 +03:00
|
|
|
followRequest: true,
|
|
|
|
chatMention: true
|
2018-08-28 21:21:29 +03:00
|
|
|
},
|
2018-12-20 09:15:30 +03:00
|
|
|
webPushNotifications: false,
|
2018-06-19 16:17:50 +03:00
|
|
|
muteWords: [],
|
2018-08-25 13:12:33 +03:00
|
|
|
highlight: {},
|
2018-09-25 14:47:02 +03:00
|
|
|
interfaceLanguage: browserLocale,
|
2019-05-07 19:13:45 +03:00
|
|
|
hideScopeNotice: false,
|
2019-12-10 21:30:27 +02:00
|
|
|
useStreamingApi: false,
|
2018-09-25 14:47:02 +03:00
|
|
|
scopeCopy: undefined, // instance default
|
2018-12-03 06:47:35 +03:00
|
|
|
subjectLineBehavior: undefined, // instance default
|
2019-02-05 03:57:11 -08:00
|
|
|
alwaysShowSubjectInput: undefined, // instance default
|
2019-03-03 15:15:41 +02:00
|
|
|
postContentType: undefined, // instance default
|
2019-09-29 23:47:26 +03:00
|
|
|
minimalScopesMode: undefined, // instance default
|
|
|
|
// This hides statuses filtered via a word filter
|
|
|
|
hideFilteredStatuses: undefined, // instance default
|
|
|
|
playVideosInModal: false,
|
|
|
|
useOneClickNsfw: false,
|
|
|
|
useContainFit: false,
|
2019-11-14 00:47:20 +02:00
|
|
|
greentext: undefined, // instance default
|
2019-09-29 23:47:26 +03:00
|
|
|
hidePostStats: undefined, // instance default
|
2020-09-29 10:18:37 +00:00
|
|
|
hideUserStats: undefined, // instance default
|
2021-02-23 10:00:23 +02:00
|
|
|
virtualScrolling: undefined, // instance default
|
|
|
|
sensitiveByDefault: undefined
|
2017-02-14 22:21:23 +01: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,
|
|
|
|
...state
|
2019-09-29 22:33:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2017-02-14 22:21:23 +01:00
|
|
|
mutations: {
|
|
|
|
setOption (state, { name, value }) {
|
|
|
|
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) {
|
|
|
|
set(state.highlight, user, { color: color || data.color, type: type || data.type })
|
2018-06-19 16:17:50 +03:00
|
|
|
} else {
|
|
|
|
del(state.highlight, user)
|
|
|
|
}
|
2017-02-14 22:21:23 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
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
|
|
|
},
|
2017-02-18 20:42:00 +01:00
|
|
|
setOption ({ commit, dispatch }, { name, value }) {
|
2019-07-05 10:02:14 +03:00
|
|
|
commit('setOption', { name, value })
|
2017-02-14 22:21:23 +01:00
|
|
|
switch (name) {
|
|
|
|
case 'theme':
|
2020-01-22 00:37:19 +02:00
|
|
|
setPreset(value)
|
2017-11-14 01:37:49 +02:00
|
|
|
break
|
|
|
|
case 'customTheme':
|
2020-03-04 00:23:14 +02:00
|
|
|
case 'customThemeSource':
|
2020-01-22 00:37:19 +02:00
|
|
|
applyTheme(value)
|
2020-06-08 17:22:07 +02:00
|
|
|
break
|
|
|
|
case 'interfaceLanguage':
|
|
|
|
messages.setLanguage(this.getters.i18n, value)
|
|
|
|
break
|
2017-02-14 22:21:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default config
|