Use feature detection for frontendConfigurations

merge-requests/1243/head
Alex Gleason 2022-04-19 18:33:13 -05:00
rodzic 29b28edee5
commit b72f398bad
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
3 zmienionych plików z 33 dodań i 16 usunięć

Wyświetl plik

@ -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());

Wyświetl plik

@ -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);
};
};

Wyświetl plik

@ -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