2018-09-09 11:21:23 -07:00
|
|
|
import { set } from 'vue'
|
2020-01-21 14:37:19 -08:00
|
|
|
import { getPreset, applyTheme } from '../services/style_setter/style_setter.js'
|
2020-02-22 00:57:08 -08:00
|
|
|
import { CURRENT_VERSION } from '../services/theme_data/theme_data.service.js'
|
2019-09-29 13:47:26 -07:00
|
|
|
import { instanceDefaultProperties } from './config.js'
|
2018-09-09 11:21:23 -07:00
|
|
|
|
|
|
|
const defaultState = {
|
2018-09-09 11:51:40 -07:00
|
|
|
// Stuff from static/config.json and apiConfig
|
2018-12-02 19:47:35 -08:00
|
|
|
alwaysShowSubjectInput: true,
|
2020-05-13 12:40:46 -07:00
|
|
|
background: '/static/aurora_borealis.jpg',
|
2018-09-09 11:21:23 -07:00
|
|
|
collapseMessageWithSubject: false,
|
2020-05-13 12:40:46 -07:00
|
|
|
disableChat: false,
|
|
|
|
greentext: false,
|
|
|
|
hideFilteredStatuses: false,
|
|
|
|
hideMutedPosts: false,
|
2018-10-16 06:09:29 -07:00
|
|
|
hidePostStats: false,
|
2020-05-13 12:40:46 -07:00
|
|
|
hideSitename: false,
|
2018-10-16 06:09:29 -07:00
|
|
|
hideUserStats: false,
|
2020-05-13 12:40:46 -07:00
|
|
|
logo: '/static/logo.png',
|
|
|
|
logoMargin: '.2em',
|
|
|
|
logoMask: true,
|
|
|
|
minimalScopesMode: false,
|
|
|
|
name: 'Pleroma FE',
|
|
|
|
nsfwCensorImage: undefined,
|
|
|
|
postContentType: 'text/plain',
|
|
|
|
redirectRootLogin: '/main/friends',
|
|
|
|
redirectRootNoLogin: '/main/all',
|
|
|
|
registrationOpen: true,
|
|
|
|
safeDM: true,
|
2018-09-25 05:16:26 -07:00
|
|
|
scopeCopy: true,
|
2020-05-13 12:40:46 -07:00
|
|
|
server: 'http://localhost:4040/',
|
|
|
|
showFeaturesPanel: true,
|
|
|
|
showInstanceSpecificPanel: false,
|
2018-09-25 04:47:02 -07:00
|
|
|
subjectLineBehavior: 'email',
|
2020-05-13 12:40:46 -07:00
|
|
|
textlimit: 5000,
|
|
|
|
theme: 'pleroma-dark',
|
|
|
|
themeData: undefined,
|
2018-12-13 09:41:01 -08:00
|
|
|
vapidPublicKey: undefined,
|
2018-09-09 11:51:40 -07:00
|
|
|
|
2018-09-09 11:21:23 -07:00
|
|
|
// Nasty stuff
|
|
|
|
pleromaBackend: true,
|
2018-09-09 11:51:40 -07:00
|
|
|
emoji: [],
|
2019-10-09 12:50:00 -07:00
|
|
|
emojiFetched: false,
|
2018-09-09 11:21:23 -07:00
|
|
|
customEmoji: [],
|
2019-10-09 12:50:00 -07:00
|
|
|
customEmojiFetched: false,
|
2018-12-26 05:50:48 -08:00
|
|
|
restrictedNicknames: [],
|
2019-03-04 21:29:56 -08:00
|
|
|
postFormats: [],
|
2018-09-09 11:51:40 -07:00
|
|
|
|
|
|
|
// Feature-set, apparently, not everything here is reported...
|
|
|
|
mediaProxyAvailable: false,
|
|
|
|
chatAvailable: false,
|
|
|
|
gopherAvailable: false,
|
|
|
|
suggestionsEnabled: false,
|
|
|
|
suggestionsWeb: '',
|
|
|
|
|
2018-09-09 11:21:23 -07:00
|
|
|
// Html stuff
|
|
|
|
instanceSpecificPanelContent: '',
|
2019-03-10 16:58:12 -07:00
|
|
|
tos: '',
|
|
|
|
|
|
|
|
// Version Information
|
|
|
|
backendVersion: '',
|
2019-06-18 13:28:31 -07:00
|
|
|
frontendVersion: '',
|
|
|
|
|
|
|
|
pollsAvailable: false,
|
|
|
|
pollLimits: {
|
|
|
|
max_options: 4,
|
|
|
|
max_option_chars: 255,
|
|
|
|
min_expiration: 60,
|
|
|
|
max_expiration: 60 * 60 * 24
|
|
|
|
}
|
2018-09-09 11:21:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const instance = {
|
|
|
|
state: defaultState,
|
|
|
|
mutations: {
|
|
|
|
setInstanceOption (state, { name, value }) {
|
2018-09-17 08:54:08 -07:00
|
|
|
if (typeof value !== 'undefined') {
|
|
|
|
set(state, name, value)
|
|
|
|
}
|
2018-09-09 11:21:23 -07:00
|
|
|
}
|
|
|
|
},
|
2019-09-29 13:47:26 -07:00
|
|
|
getters: {
|
|
|
|
instanceDefaultConfig (state) {
|
|
|
|
return instanceDefaultProperties
|
|
|
|
.map(key => [key, state[key]])
|
|
|
|
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {})
|
|
|
|
}
|
|
|
|
},
|
2018-09-09 11:21:23 -07:00
|
|
|
actions: {
|
|
|
|
setInstanceOption ({ commit, dispatch }, { name, value }) {
|
2019-07-05 00:02:14 -07:00
|
|
|
commit('setInstanceOption', { name, value })
|
2018-09-09 11:21:23 -07:00
|
|
|
switch (name) {
|
|
|
|
case 'name':
|
|
|
|
dispatch('setPageTitle')
|
|
|
|
break
|
2019-08-17 01:18:42 -07:00
|
|
|
case 'chatAvailable':
|
|
|
|
if (value) {
|
|
|
|
dispatch('initializeSocket')
|
|
|
|
}
|
|
|
|
break
|
2020-01-21 14:37:19 -08:00
|
|
|
case 'theme':
|
|
|
|
dispatch('setTheme', value)
|
|
|
|
break
|
2018-09-09 11:21:23 -07:00
|
|
|
}
|
2019-02-09 01:26:35 -08:00
|
|
|
},
|
2019-10-09 12:50:00 -07:00
|
|
|
async getStaticEmoji ({ commit }) {
|
|
|
|
try {
|
|
|
|
const res = await window.fetch('/static/emoji.json')
|
|
|
|
if (res.ok) {
|
|
|
|
const values = await res.json()
|
|
|
|
const emoji = Object.keys(values).map((key) => {
|
|
|
|
return {
|
|
|
|
displayText: key,
|
|
|
|
imageUrl: false,
|
|
|
|
replacement: values[key]
|
|
|
|
}
|
|
|
|
}).sort((a, b) => a.displayText - b.displayText)
|
|
|
|
commit('setInstanceOption', { name: 'emoji', value: emoji })
|
|
|
|
} else {
|
|
|
|
throw (res)
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("Can't load static emoji")
|
|
|
|
console.warn(e)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async getCustomEmoji ({ commit, state }) {
|
|
|
|
try {
|
|
|
|
const res = await window.fetch('/api/pleroma/emoji.json')
|
|
|
|
if (res.ok) {
|
|
|
|
const result = await res.json()
|
|
|
|
const values = Array.isArray(result) ? Object.assign({}, ...result) : result
|
|
|
|
const emoji = Object.entries(values).map(([key, value]) => {
|
|
|
|
const imageUrl = value.image_url
|
|
|
|
return {
|
|
|
|
displayText: key,
|
|
|
|
imageUrl: imageUrl ? state.server + imageUrl : value,
|
|
|
|
tags: imageUrl ? value.tags.sort((a, b) => a > b ? 1 : 0) : ['utf'],
|
|
|
|
replacement: `:${key}: `
|
|
|
|
}
|
|
|
|
// Technically could use tags but those are kinda useless right now,
|
|
|
|
// should have been "pack" field, that would be more useful
|
|
|
|
}).sort((a, b) => a.displayText.toLowerCase() > b.displayText.toLowerCase() ? 1 : 0)
|
|
|
|
commit('setInstanceOption', { name: 'customEmoji', value: emoji })
|
|
|
|
} else {
|
|
|
|
throw (res)
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("Can't load custom emojis")
|
|
|
|
console.warn(e)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-21 14:37:19 -08:00
|
|
|
setTheme ({ commit, rootState }, themeName) {
|
2019-02-09 01:26:35 -08:00
|
|
|
commit('setInstanceOption', { name: 'theme', value: themeName })
|
2020-01-21 14:37:19 -08:00
|
|
|
getPreset(themeName)
|
|
|
|
.then(themeData => {
|
|
|
|
commit('setInstanceOption', { name: 'themeData', value: themeData })
|
|
|
|
// No need to apply theme if there's user theme already
|
|
|
|
const { customTheme } = rootState.config
|
|
|
|
if (customTheme) return
|
2020-02-22 00:57:08 -08:00
|
|
|
|
|
|
|
// New theme presets don't have 'theme' property, they use 'source'
|
|
|
|
const themeSource = themeData.source
|
2020-02-28 09:20:40 -08:00
|
|
|
if (!themeData.theme || (themeSource && themeSource.themeEngineVersion === CURRENT_VERSION)) {
|
2020-02-22 00:57:08 -08:00
|
|
|
applyTheme(themeSource)
|
|
|
|
} else {
|
|
|
|
applyTheme(themeData.theme)
|
|
|
|
}
|
2020-01-21 14:37:19 -08:00
|
|
|
})
|
2019-10-09 12:50:00 -07:00
|
|
|
},
|
|
|
|
fetchEmoji ({ dispatch, state }) {
|
|
|
|
if (!state.customEmojiFetched) {
|
|
|
|
state.customEmojiFetched = true
|
|
|
|
dispatch('getCustomEmoji')
|
|
|
|
}
|
|
|
|
if (!state.emojiFetched) {
|
|
|
|
state.emojiFetched = true
|
|
|
|
dispatch('getStaticEmoji')
|
|
|
|
}
|
2018-09-09 11:21:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default instance
|