From e618c6ffb0b974156b89f3e54737e738e94b12b3 Mon Sep 17 00:00:00 2001 From: slice Date: Sun, 10 Mar 2019 11:23:27 -0700 Subject: Only connect to chat when authenticating in the first place To avoid duplication of the connection, the chat socket is destroyed upon logging out. --- src/boot/after_store.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/boot/after_store.js') diff --git a/src/boot/after_store.js b/src/boot/after_store.js index a8e2bf35..cd88c188 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -89,10 +89,8 @@ 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']) -- cgit v1.2.3-70-g09d2 From 068c9724e45fe801ecedbea491234d0b95695629 Mon Sep 17 00:00:00 2001 From: Edijs Date: Sun, 10 Mar 2019 16:58:12 -0700 Subject: Added new tab to display versions of BE/FE --- src/boot/after_store.js | 6 ++++++ src/components/settings/settings.js | 17 +++++++++++++++-- src/components/settings/settings.vue | 22 ++++++++++++++++++++++ src/i18n/en.json | 5 +++++ src/modules/instance.js | 6 +++++- src/services/version/version.service.js | 10 ++++++++++ 6 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/services/version/version.service.js (limited to 'src/boot/after_store.js') diff --git a/src/boot/after_store.js b/src/boot/after_store.js index a8e2bf35..dfaf4d68 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -176,6 +176,12 @@ const afterStoreSetup = ({ store, i18n }) => { const suggestions = metadata.suggestions store.dispatch('setInstanceOption', { name: 'suggestionsEnabled', value: suggestions.enabled }) store.dispatch('setInstanceOption', { name: 'suggestionsWeb', value: suggestions.web }) + + const software = data.software + store.dispatch('setInstanceOption', { name: 'backendVersion', value: software.version }) + + const frontendVersion = window.___pleromafe_commit_hash + store.dispatch('setInstanceOption', { name: 'frontendVersion', value: frontendVersion }) }) } diff --git a/src/components/settings/settings.js b/src/components/settings/settings.js index 979457a5..d208ee5a 100644 --- a/src/components/settings/settings.js +++ b/src/components/settings/settings.js @@ -1,8 +1,10 @@ /* eslint-env browser */ +import { filter, trim } from 'lodash' + import TabSwitcher from '../tab_switcher/tab_switcher.js' import StyleSwitcher from '../style_switcher/style_switcher.vue' import InterfaceLanguageSwitcher from '../interface_language_switcher/interface_language_switcher.vue' -import { filter, trim } from 'lodash' +import { parseBackendVersionString, parseFrontendVersionString } from '../../services/version/version.service' const settings = { data () { @@ -78,7 +80,10 @@ const settings = { // Future spec, still not supported in Nightly 63 as of 08/2018 Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, 'audioTracks'), playVideosInModal: user.playVideosInModal, - useContainFit: user.useContainFit + useContainFit: user.useContainFit, + + backendVersion: instance.backendVersion, + frontendVersion: instance.frontendVersion } }, components: { @@ -98,6 +103,14 @@ const settings = { }, instanceSpecificPanelPresent () { return this.$store.state.instance.showInstanceSpecificPanel } }, + methods: { + parseBackendVersion (versionString) { + return parseBackendVersionString(versionString) + }, + parseFrontendVersion (versionString) { + return parseFrontendVersionString(versionString) + } + }, watch: { hideAttachmentsLocal (value) { this.$store.dispatch('setOption', { name: 'hideAttachments', value }) diff --git a/src/components/settings/settings.vue b/src/components/settings/settings.vue index d2346747..3ca7bdc0 100644 --- a/src/components/settings/settings.vue +++ b/src/components/settings/settings.vue @@ -261,6 +261,28 @@ +
+
+
    +
  • +

    {{$t('settings.version.backend_version')}}

    +
      +
    • +
      +
    • +
    +
  • +
  • +

    {{$t('settings.version.frontend_version')}}

    +
      +
    • +
      +
    • +
    +
  • +
+
+
diff --git a/src/i18n/en.json b/src/i18n/en.json index 01fe2fba..1fe201a4 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -347,6 +347,11 @@ "checkbox": "I have skimmed over terms and conditions", "link": "a nice lil' link" } + }, + "version": { + "title": "Version", + "backend_version": "Backend Version", + "frontend_version": "Frontend Version" } }, "timeline": { diff --git a/src/modules/instance.js b/src/modules/instance.js index 24c52f9c..155aa2eb 100644 --- a/src/modules/instance.js +++ b/src/modules/instance.js @@ -48,7 +48,11 @@ const defaultState = { // Html stuff instanceSpecificPanelContent: '', - tos: '' + tos: '', + + // Version Information + backendVersion: '', + frontendVersion: '' } const instance = { diff --git a/src/services/version/version.service.js b/src/services/version/version.service.js new file mode 100644 index 00000000..6c5036c1 --- /dev/null +++ b/src/services/version/version.service.js @@ -0,0 +1,10 @@ + +export const parseBackendVersionString = versionString => { + const regex = /(-g)(\w+)$/i + const replacer = '$1$2' + return versionString.replace(regex, replacer) +} + +export const parseFrontendVersionString = versionString => { + return `#${versionString}` +} -- cgit v1.2.3-70-g09d2 From c030e622544346f6359e4df86bf20e503b0f2c3a Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 13 Mar 2019 11:57:30 +0100 Subject: afterStoreSetup: refactor. --- src/boot/after_store.js | 242 ++++++++++++++++++++++++++---------------------- 1 file changed, 129 insertions(+), 113 deletions(-) (limited to 'src/boot/after_store.js') diff --git a/src/boot/after_store.js b/src/boot/after_store.js index cd88c188..d9706960 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -4,119 +4,137 @@ 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 { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey } = data.site - - store.dispatch('setInstanceOption', { name: 'name', value: name }) - store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') }) - store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) }) - store.dispatch('setInstanceOption', { name: 'server', value: server }) - - // TODO: default values for this stuff, added if to not make it break on - // my dev config out of the box. - if (uploadlimit) { - store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) }) - store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) }) - store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) }) - store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) }) - } - - if (vapidPublicKey) { - store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey }) - } - - var apiConfig = data.site.pleromafe - - window.fetch('/static/config.json') - .then((res) => res.json()) - .catch((err) => { - console.warn('Failed to load static/config.json, continuing without it.') - console.warn(err) - return {} - }) - .then((staticConfig) => { - const overrides = window.___pleromafe_dev_overrides || {} - const env = window.___pleromafe_mode.NODE_ENV - - // This takes static config and overrides properties that are present in apiConfig - let config = {} - if (overrides.staticConfigPreference && env === 'development') { - console.warn('OVERRIDING API CONFIG WITH STATIC CONFIG') - config = Object.assign({}, apiConfig, staticConfig) - } else { - config = Object.assign({}, staticConfig, apiConfig) - } +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 }) + store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') }) + store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) }) + store.dispatch('setInstanceOption', { name: 'server', value: server }) + + // TODO: default values for this stuff, added if to not make it break on + // my dev config out of the box. + if (uploadlimit) { + store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) }) + store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) }) + store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) }) + store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) }) + } + + if (vapidPublicKey) { + store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey }) + } + + return data.site.pleromafe + } catch (error) { + console.error('Could not load statusnet config, potentially fatal') + console.error(error) + } +} - const copyInstanceOption = (name) => { - store.dispatch('setInstanceOption', {name, value: config[name]}) - } +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(error) + return {} + } +} - copyInstanceOption('nsfwCensorImage') - copyInstanceOption('background') - copyInstanceOption('hidePostStats') - copyInstanceOption('hideUserStats') - copyInstanceOption('hideFilteredStatuses') - copyInstanceOption('logo') - - store.dispatch('setInstanceOption', { - name: 'logoMask', - value: typeof config.logoMask === 'undefined' - ? true - : config.logoMask - }) - - store.dispatch('setInstanceOption', { - name: 'logoMargin', - value: typeof config.logoMargin === 'undefined' - ? 0 - : config.logoMargin - }) - - copyInstanceOption('redirectRootNoLogin') - copyInstanceOption('redirectRootLogin') - copyInstanceOption('showInstanceSpecificPanel') - copyInstanceOption('scopeOptionsEnabled') - copyInstanceOption('formattingOptionsEnabled') - copyInstanceOption('collapseMessageWithSubject') - copyInstanceOption('loginMethod') - copyInstanceOption('scopeCopy') - copyInstanceOption('subjectLineBehavior') - copyInstanceOption('postContentType') - copyInstanceOption('alwaysShowSubjectInput') - copyInstanceOption('noAttachmentLinks') - copyInstanceOption('showFeaturesPanel') - - if (config.chatDisabled) { - store.dispatch('disableChat') - } +const setSettings = async ({ apiConfig, staticConfig, store }) => { + const overrides = window.___pleromafe_dev_overrides || {} + const env = window.___pleromafe_mode.NODE_ENV + + // This takes static config and overrides properties that are present in apiConfig + let config = {} + if (overrides.staticConfigPreference && env === 'development') { + console.warn('OVERRIDING API CONFIG WITH STATIC CONFIG') + config = Object.assign({}, apiConfig, staticConfig) + } else { + config = Object.assign({}, staticConfig, apiConfig) + } + + const copyInstanceOption = (name) => { + store.dispatch('setInstanceOption', { name, value: config[name] }) + } + + copyInstanceOption('nsfwCensorImage') + copyInstanceOption('background') + copyInstanceOption('hidePostStats') + copyInstanceOption('hideUserStats') + copyInstanceOption('hideFilteredStatuses') + copyInstanceOption('logo') + + store.dispatch('setInstanceOption', { + name: 'logoMask', + value: typeof config.logoMask === 'undefined' + ? true + : config.logoMask + }) + + store.dispatch('setInstanceOption', { + name: 'logoMargin', + value: typeof config.logoMargin === 'undefined' + ? 0 + : config.logoMargin + }) + + copyInstanceOption('redirectRootNoLogin') + copyInstanceOption('redirectRootLogin') + copyInstanceOption('showInstanceSpecificPanel') + copyInstanceOption('scopeOptionsEnabled') + copyInstanceOption('formattingOptionsEnabled') + copyInstanceOption('collapseMessageWithSubject') + copyInstanceOption('loginMethod') + copyInstanceOption('scopeCopy') + copyInstanceOption('subjectLineBehavior') + copyInstanceOption('postContentType') + copyInstanceOption('alwaysShowSubjectInput') + copyInstanceOption('noAttachmentLinks') + copyInstanceOption('showFeaturesPanel') + + if ((config.chatDisabled)) { + store.dispatch('disableChat') + } else { + store.dispatch('initializeSocket') + } + + return store.dispatch('setTheme', config['theme']) +} - return store.dispatch('setTheme', config['theme']) - }) - .then(() => { - const router = new VueRouter({ - mode: 'history', - routes: routes(store), - scrollBehavior: (to, _from, savedPosition) => { - if (to.matched.some(m => m.meta.dontScroll)) { - return false - } - return savedPosition || { x: 0, y: 0 } - } - }) - - /* eslint-disable no-new */ - new Vue({ - router, - store, - i18n, - el: '#app', - render: h => h(App) - }) - }) - }) +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), + scrollBehavior: (to, _from, savedPosition) => { + if (to.matched.some(m => m.meta.dontScroll)) { + return false + } + return savedPosition || { x: 0, y: 0 } + } + }) + + /* eslint-disable no-new */ + new Vue({ + router, + 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 -- cgit v1.2.3-70-g09d2 From f535ccd92583819f48d32c381b234ab26508666d Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 13 Mar 2019 12:10:57 +0100 Subject: afterStoreSetup: refactor TOS and panel fetching, handle 404s. --- src/boot/after_store.js | 65 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 22 deletions(-) (limited to 'src/boot/after_store.js') diff --git a/src/boot/after_store.js b/src/boot/after_store.js index d9706960..c1073012 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -107,10 +107,43 @@ const setSettings = async ({ apiConfig, staticConfig, store }) => { return store.dispatch('setTheme', config['theme']) } +const getTOS = async ({ store }) => { + try { + const res = await window.fetch('/static/terms-of-service.html') + if (res.ok) { + const html = await res.text() + store.dispatch('setInstanceOption', { name: 'tos', value: html }) + } else { + throw (res) + } + } catch (e) { + console.warn("Can't load TOS") + console.warn(e) + } +} + +const getInstancePanel = async ({ store }) => { + try { + const res = await window.fetch('/instance/panel.html') + if (res.ok) { + const html = await res.text() + store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html }) + } else { + throw (res) + } + } catch (e) { + console.warn("Can't load instance panel") + console.log(e) + } +} + const afterStoreSetup = async ({ store, i18n }) => { const apiConfig = await getStatusnetConfig({ store }) const staticConfig = await getStaticConfig() await setSettings({ store, apiConfig, staticConfig }) + await getTOS({ store }) + await getInstancePanel({ store }) + // Now we have the server settings and can try logging in if (store.state.oauth.token) { store.dispatch('loginUser', store.state.oauth.token) @@ -127,21 +160,6 @@ const afterStoreSetup = async ({ store, i18n }) => { } }) - /* eslint-disable no-new */ - new Vue({ - router, - store, - i18n, - el: '#app', - render: h => h(App) - }) - - window.fetch('/static/terms-of-service.html') - .then((res) => res.text()) - .then((html) => { - store.dispatch('setInstanceOption', { name: 'tos', value: html }) - }) - window.fetch('/api/pleroma/emoji.json') .then( (res) => res.json() @@ -169,13 +187,7 @@ const afterStoreSetup = async ({ store, i18n }) => { store.dispatch('setInstanceOption', { name: 'emoji', value: emoji }) }) - window.fetch('/instance/panel.html') - .then((res) => res.text()) - .then((html) => { - store.dispatch('setInstanceOption', { name: 'instanceSpecificPanelContent', value: html }) - }) - - return window.fetch('/nodeinfo/2.0.json') + window.fetch('/nodeinfo/2.0.json') .then((res) => res.json()) .then((data) => { const metadata = data.metadata @@ -191,6 +203,15 @@ const afterStoreSetup = async ({ store, i18n }) => { store.dispatch('setInstanceOption', { name: 'suggestionsEnabled', value: suggestions.enabled }) store.dispatch('setInstanceOption', { name: 'suggestionsWeb', value: suggestions.web }) }) + + /* eslint-disable no-new */ + return new Vue({ + router, + store, + i18n, + el: '#app', + render: h => h(App) + }) } export default afterStoreSetup -- cgit v1.2.3-70-g09d2 From 446785ddce5f78af7087a47d82f45633fc2f7da5 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 13 Mar 2019 12:26:40 +0100 Subject: afterStoreSetup: Emoji and nodeinfo refactor. --- src/boot/after_store.js | 115 +++++++++++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 45 deletions(-) (limited to 'src/boot/after_store.js') diff --git a/src/boot/after_store.js b/src/boot/after_store.js index c1073012..f9e14eb2 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -133,7 +133,73 @@ const getInstancePanel = async ({ store }) => { } } catch (e) { console.warn("Can't load instance panel") - console.log(e) + console.warn(e) + } +} + +const getStaticEmoji = async ({ store }) => { + 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 { shortcode: key, image_url: false, 'utf': values[key] } + }) + store.dispatch('setInstanceOption', { name: 'emoji', value: emoji }) + } else { + throw (res) + } + } catch (e) { + console.warn("Can't load static emoji") + console.warn(e) + } +} + +// This is also used to indicate if we have a 'pleroma backend' or not. +// Somewhat weird, should probably be somewhere else. +const getCustomEmoji = async ({ store }) => { + try { + const res = await window.fetch('/api/pleroma/emoji.json') + if (res.ok) { + const values = await res.json() + const emoji = Object.keys(values).map((key) => { + return { shortcode: key, image_url: values[key] } + }) + store.dispatch('setInstanceOption', { name: 'customEmoji', value: emoji }) + store.dispatch('setInstanceOption', { name: 'pleromaBackend', value: true }) + } else { + throw (res) + } + } catch (e) { + store.dispatch('setInstanceOption', { name: 'pleromaBackend', value: false }) + console.warn("Can't load custom emojis, maybe not a Pleroma instance?") + console.warn(e) + } +} + +const getNodeInfo = async ({ store }) => { + try { + const res = await window.fetch('/nodeinfo/2.0.json') + if (res.ok) { + const data = await res.json() + const metadata = data.metadata + + const features = metadata.features + store.dispatch('setInstanceOption', { name: 'mediaProxyAvailable', value: features.includes('media_proxy') }) + store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') }) + store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') }) + + store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames }) + + const suggestions = metadata.suggestions + store.dispatch('setInstanceOption', { name: 'suggestionsEnabled', value: suggestions.enabled }) + store.dispatch('setInstanceOption', { name: 'suggestionsWeb', value: suggestions.web }) + } else { + throw (res) + } + } catch (e) { + console.warn('Could not load nodeinfo') + console.warn(e) } } @@ -143,6 +209,9 @@ const afterStoreSetup = async ({ store, i18n }) => { await setSettings({ store, apiConfig, staticConfig }) await getTOS({ store }) await getInstancePanel({ store }) + await getStaticEmoji({ store }) + await getCustomEmoji({ store }) + await getNodeInfo({ store }) // Now we have the server settings and can try logging in if (store.state.oauth.token) { @@ -160,50 +229,6 @@ const afterStoreSetup = async ({ store, i18n }) => { } }) - window.fetch('/api/pleroma/emoji.json') - .then( - (res) => res.json() - .then( - (values) => { - const emoji = Object.keys(values).map((key) => { - return { shortcode: key, image_url: values[key] } - }) - store.dispatch('setInstanceOption', { name: 'customEmoji', value: emoji }) - store.dispatch('setInstanceOption', { name: 'pleromaBackend', value: true }) - }, - (failure) => { - store.dispatch('setInstanceOption', { name: 'pleromaBackend', value: false }) - } - ), - (error) => console.log(error) - ) - - window.fetch('/static/emoji.json') - .then((res) => res.json()) - .then((values) => { - const emoji = Object.keys(values).map((key) => { - return { shortcode: key, image_url: false, 'utf': values[key] } - }) - store.dispatch('setInstanceOption', { name: 'emoji', value: emoji }) - }) - - window.fetch('/nodeinfo/2.0.json') - .then((res) => res.json()) - .then((data) => { - const metadata = data.metadata - - const features = metadata.features - store.dispatch('setInstanceOption', { name: 'mediaProxyAvailable', value: features.includes('media_proxy') }) - store.dispatch('setInstanceOption', { name: 'chatAvailable', value: features.includes('chat') }) - store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') }) - - store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames }) - - const suggestions = metadata.suggestions - store.dispatch('setInstanceOption', { name: 'suggestionsEnabled', value: suggestions.enabled }) - store.dispatch('setInstanceOption', { name: 'suggestionsWeb', value: suggestions.web }) - }) - /* eslint-disable no-new */ return new Vue({ router, -- cgit v1.2.3-70-g09d2 From 48ac96cfc7c9c3328d7a18707f00a2fe1bc743a1 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 13 Mar 2019 12:41:39 +0100 Subject: afterStoreSetup: Handle 404 cases. --- src/boot/after_store.js | 50 ++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'src/boot/after_store.js') diff --git a/src/boot/after_store.js b/src/boot/after_store.js index f9e14eb2..a51f895e 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -7,28 +7,32 @@ import App from '../App.vue' 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 }) - store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') }) - store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) }) - store.dispatch('setInstanceOption', { name: 'server', value: server }) - - // TODO: default values for this stuff, added if to not make it break on - // my dev config out of the box. - if (uploadlimit) { - store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) }) - store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) }) - store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) }) - store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) }) - } + if (res.ok) { + const data = await res.json() + const { name, closed: registrationClosed, textlimit, uploadlimit, server, vapidPublicKey } = data.site + + store.dispatch('setInstanceOption', { name: 'name', value: name }) + store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') }) + store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) }) + store.dispatch('setInstanceOption', { name: 'server', value: server }) + + // TODO: default values for this stuff, added if to not make it break on + // my dev config out of the box. + if (uploadlimit) { + store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit.uploadlimit) }) + store.dispatch('setInstanceOption', { name: 'avatarlimit', value: parseInt(uploadlimit.avatarlimit) }) + store.dispatch('setInstanceOption', { name: 'backgroundlimit', value: parseInt(uploadlimit.backgroundlimit) }) + store.dispatch('setInstanceOption', { name: 'bannerlimit', value: parseInt(uploadlimit.bannerlimit) }) + } - if (vapidPublicKey) { - store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey }) - } + if (vapidPublicKey) { + store.dispatch('setInstanceOption', { name: 'vapidPublicKey', value: vapidPublicKey }) + } - return data.site.pleromafe + return data.site.pleromafe + } else { + throw (res) + } } catch (error) { console.error('Could not load statusnet config, potentially fatal') console.error(error) @@ -38,7 +42,11 @@ const getStatusnetConfig = async ({ store }) => { const getStaticConfig = async () => { try { const res = await window.fetch('/static/config.json') - return res.json() + if (res.ok) { + return res.json() + } else { + throw (res) + } } catch (error) { console.warn('Failed to load static/config.json, continuing without it.') console.warn(error) -- cgit v1.2.3-70-g09d2 From 5318227c378a9cd44baa4cc12dbb1935826c843b Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 13 Mar 2019 13:29:34 +0100 Subject: afterStoreSetup: Move log in and theme load to afterStoreSetup. --- src/boot/after_store.js | 10 ++++++++++ src/lib/persisted_state.js | 12 ------------ 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'src/boot/after_store.js') diff --git a/src/boot/after_store.js b/src/boot/after_store.js index a51f895e..3d400ffa 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -212,6 +212,16 @@ const getNodeInfo = async ({ store }) => { } const afterStoreSetup = async ({ store, i18n }) => { + if (store.state.config.customTheme) { + // This is a hack to deal with async loading of config.json and themes + // See: style_setter.js, setPreset() + window.themeLoaded = true + store.dispatch('setOption', { + name: 'customTheme', + value: store.state.config.customTheme + }) + } + const apiConfig = await getStatusnetConfig({ store }) const staticConfig = await getStaticConfig() await setSettings({ store, apiConfig, staticConfig }) diff --git a/src/lib/persisted_state.js b/src/lib/persisted_state.js index e828a74b..7ab89c12 100644 --- a/src/lib/persisted_state.js +++ b/src/lib/persisted_state.js @@ -60,18 +60,6 @@ export default function createPersistedState ({ merge({}, store.state, savedState) ) } - if (store.state.config.customTheme) { - // This is a hack to deal with async loading of config.json and themes - // See: style_setter.js, setPreset() - window.themeLoaded = true - store.dispatch('setOption', { - name: 'customTheme', - value: store.state.config.customTheme - }) - } - if (store.state.oauth.token) { - store.dispatch('loginUser', store.state.oauth.token) - } loaded = true } catch (e) { console.log("Couldn't load state") -- cgit v1.2.3-70-g09d2 From f93d4a37546f12f4850fbe4a296dfa0a92813ddd Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Mar 2019 21:35:45 +0000 Subject: after store: fix setting postFormats field --- src/boot/after_store.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/boot/after_store.js') diff --git a/src/boot/after_store.js b/src/boot/after_store.js index a51f895e..6e5e1d8b 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -198,6 +198,7 @@ const getNodeInfo = async ({ store }) => { store.dispatch('setInstanceOption', { name: 'gopherAvailable', value: features.includes('gopher') }) store.dispatch('setInstanceOption', { name: 'restrictedNicknames', value: metadata.restrictedNicknames }) + store.dispatch('setInstanceOption', { name: 'postFormats', value: metadata.postFormats }) const suggestions = metadata.suggestions store.dispatch('setInstanceOption', { name: 'suggestionsEnabled', value: suggestions.enabled }) -- cgit v1.2.3-70-g09d2