diff --git a/app/soapbox/actions/soapbox.js b/app/soapbox/actions/soapbox.js index 0b18c9bc1..318050219 100644 --- a/app/soapbox/actions/soapbox.js +++ b/app/soapbox/actions/soapbox.js @@ -47,21 +47,34 @@ export function rememberSoapboxConfig(host) { }; } -export function fetchSoapboxConfig(host) { +export function fetchFrontendConfigurations() { return (dispatch, getState) => { - api(getState).get('/api/pleroma/frontend_configurations').then(response => { - if (response.data.soapbox_fe) { - dispatch(importSoapboxConfig(response.data.soapbox_fe, host)); - } else { - dispatch(fetchSoapboxJson(host)); - } - }).catch(error => { - dispatch(fetchSoapboxJson(host)); - }); + return api(getState) + .get('/api/pleroma/frontend_configurations') + .then(({ data }) => data); }; } -// Tries to remember the config from browser storage before fetching it +/** Conditionally fetches Soapbox config depending on backend features */ +export function fetchSoapboxConfig(host) { + return (dispatch, getState) => { + const features = getFeatures(getState().instance); + + if (features.frontendConfigurations) { + return dispatch(fetchFrontendConfigurations()).then(data => { + if (data.soapbox_fe) { + dispatch(importSoapboxConfig(data.soapbox_fe, host)); + } else { + dispatch(fetchSoapboxJson(host)); + } + }); + } else { + return dispatch(fetchSoapboxJson(host)); + } + }; +} + +/** Tries to remember the config from browser storage before fetching it */ export function loadSoapboxConfig() { return (dispatch, getState) => { const host = getHost(getState()); diff --git a/app/soapbox/containers/soapbox.js b/app/soapbox/containers/soapbox.js index ba59cef92..b3f318c01 100644 --- a/app/soapbox/containers/soapbox.js +++ b/app/soapbox/containers/soapbox.js @@ -48,18 +48,21 @@ const loadInitial = () => { return async(dispatch, getState) => { // Await for authenticated fetch await dispatch(fetchMe()); + // Await for feature detection + await dispatch(loadInstance()); - await Promise.all([ - dispatch(loadInstance()), - dispatch(loadSoapboxConfig()), - ]); + const promises = []; + + promises.push(dispatch(loadSoapboxConfig())); const state = getState(); const features = getFeatures(state.instance); if (features.pepe && !state.me) { - await dispatch(fetchVerificationConfig()); + promises.push(dispatch(fetchVerificationConfig())); } + + await Promise.all(promises); }; }; diff --git a/app/soapbox/utils/features.ts b/app/soapbox/utils/features.ts index 2fdc310f9..27982f15d 100644 --- a/app/soapbox/utils/features.ts +++ b/app/soapbox/utils/features.ts @@ -144,6 +144,7 @@ const getInstanceFeatures = (instance: Instance) => { pepe: v.software === TRUTHSOCIAL, accountLocation: v.software === TRUTHSOCIAL, accountWebsite: v.software === TRUTHSOCIAL, + frontendConfigurations: v.software === PLEROMA, // FIXME: long-term this shouldn't be a feature, // but for now we want it to be overrideable in the build