Use feature detection for frontendConfigurations
This commit is contained in:
parent
29b28edee5
commit
b72f398bad
|
@ -47,21 +47,34 @@ export function rememberSoapboxConfig(host) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchSoapboxConfig(host) {
|
export function fetchFrontendConfigurations() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
api(getState).get('/api/pleroma/frontend_configurations').then(response => {
|
return api(getState)
|
||||||
if (response.data.soapbox_fe) {
|
.get('/api/pleroma/frontend_configurations')
|
||||||
dispatch(importSoapboxConfig(response.data.soapbox_fe, host));
|
.then(({ data }) => data);
|
||||||
} else {
|
|
||||||
dispatch(fetchSoapboxJson(host));
|
|
||||||
}
|
|
||||||
}).catch(error => {
|
|
||||||
dispatch(fetchSoapboxJson(host));
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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() {
|
export function loadSoapboxConfig() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const host = getHost(getState());
|
const host = getHost(getState());
|
||||||
|
|
|
@ -48,18 +48,21 @@ const loadInitial = () => {
|
||||||
return async(dispatch, getState) => {
|
return async(dispatch, getState) => {
|
||||||
// Await for authenticated fetch
|
// Await for authenticated fetch
|
||||||
await dispatch(fetchMe());
|
await dispatch(fetchMe());
|
||||||
|
// Await for feature detection
|
||||||
|
await dispatch(loadInstance());
|
||||||
|
|
||||||
await Promise.all([
|
const promises = [];
|
||||||
dispatch(loadInstance()),
|
|
||||||
dispatch(loadSoapboxConfig()),
|
promises.push(dispatch(loadSoapboxConfig()));
|
||||||
]);
|
|
||||||
|
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const features = getFeatures(state.instance);
|
const features = getFeatures(state.instance);
|
||||||
|
|
||||||
if (features.pepe && !state.me) {
|
if (features.pepe && !state.me) {
|
||||||
await dispatch(fetchVerificationConfig());
|
promises.push(dispatch(fetchVerificationConfig()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,7 @@ const getInstanceFeatures = (instance: Instance) => {
|
||||||
pepe: v.software === TRUTHSOCIAL,
|
pepe: v.software === TRUTHSOCIAL,
|
||||||
accountLocation: v.software === TRUTHSOCIAL,
|
accountLocation: v.software === TRUTHSOCIAL,
|
||||||
accountWebsite: v.software === TRUTHSOCIAL,
|
accountWebsite: v.software === TRUTHSOCIAL,
|
||||||
|
frontendConfigurations: v.software === PLEROMA,
|
||||||
|
|
||||||
// FIXME: long-term this shouldn't be a feature,
|
// FIXME: long-term this shouldn't be a feature,
|
||||||
// but for now we want it to be overrideable in the build
|
// but for now we want it to be overrideable in the build
|
||||||
|
|
Loading…
Reference in New Issue