afterStoreSetup: refactor.

This commit is contained in:
lain 2019-03-13 11:57:30 +01:00
parent 1387dfb889
commit c030e62254

View file

@ -4,10 +4,10 @@ import routes from './routes'
import App from '../App.vue'
const afterStoreSetup = ({ store, i18n }) => {
window.fetch('/api/statusnet/config.json')
.then((res) => res.json())
.then((data) => {
const getStatusnetConfig = async ({ store }) => {
try {
const res = await window.fetch('/api/statusnet/config.json')
const data = await res.json()
const { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey } = data.site
store.dispatch('setInstanceOption', { name: 'name', value: name })
@ -28,16 +28,25 @@ const afterStoreSetup = ({ store, i18n }) => {
store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey })
}
var apiConfig = data.site.pleromafe
return data.site.pleromafe
} catch (error) {
console.error('Could not load statusnet config, potentially fatal')
console.error(error)
}
}
window.fetch('/static/config.json')
.then((res) => res.json())
.catch((err) => {
const getStaticConfig = async () => {
try {
const res = await window.fetch('/static/config.json')
return res.json()
} catch (error) {
console.warn('Failed to load static/config.json, continuing without it.')
console.warn(err)
console.warn(error)
return {}
})
.then((staticConfig) => {
}
}
const setSettings = async ({ apiConfig, staticConfig, store }) => {
const overrides = window.___pleromafe_dev_overrides || {}
const env = window.___pleromafe_mode.NODE_ENV
@ -89,13 +98,24 @@ const afterStoreSetup = ({ store, i18n }) => {
copyInstanceOption('noAttachmentLinks')
copyInstanceOption('showFeaturesPanel')
if (config.chatDisabled) {
if ((config.chatDisabled)) {
store.dispatch('disableChat')
} else {
store.dispatch('initializeSocket')
}
return store.dispatch('setTheme', config['theme'])
})
.then(() => {
}
const afterStoreSetup = async ({ store, i18n }) => {
const apiConfig = await getStatusnetConfig({ store })
const staticConfig = await getStaticConfig()
await setSettings({ store, apiConfig, staticConfig })
// Now we have the server settings and can try logging in
if (store.state.oauth.token) {
store.dispatch('loginUser', store.state.oauth.token)
}
const router = new VueRouter({
mode: 'history',
routes: routes(store),
@ -115,8 +135,6 @@ const afterStoreSetup = ({ store, i18n }) => {
el: '#app',
render: h => h(App)
})
})
})
window.fetch('/static/terms-of-service.html')
.then((res) => res.text())
@ -157,7 +175,7 @@ const afterStoreSetup = ({ store, i18n }) => {
store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html })
})
window.fetch('/nodeinfo/2.0.json')
return window.fetch('/nodeinfo/2.0.json')
.then((res) => res.json())
.then((data) => {
const metadata = data.metadata
@ -167,8 +185,6 @@ const afterStoreSetup = ({ store, i18n }) => {
store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') })
store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') })
store.dispatch('setInstanceOption', { name: 'postFormats', value: metadata.postFormats })
store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames })
const suggestions = metadata.suggestions