kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Conditionally fetch /nodeinfo/2.1.json for Pleroma < 2.1, #137
rodzic
61fcfdbc6e
commit
a2c9aeb8dd
|
@ -1,18 +1,36 @@
|
||||||
import api from '../api';
|
import api from '../api';
|
||||||
|
import { get } from 'lodash';
|
||||||
|
import { parseVersion } from 'soapbox/utils/features';
|
||||||
|
|
||||||
export const INSTANCE_IMPORT = 'INSTANCE_IMPORT';
|
export const INSTANCE_IMPORT = 'INSTANCE_IMPORT';
|
||||||
export const INSTANCE_FAIL = 'INSTANCE_FAIL';
|
export const INSTANCE_FAIL = 'INSTANCE_FAIL';
|
||||||
|
export const NODEINFO_IMPORT = 'NODEINFO_IMPORT';
|
||||||
|
export const NODEINFO_FAIL = 'NODEINFO_FAIL';
|
||||||
|
|
||||||
export function fetchInstance() {
|
export function fetchInstance() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
api(getState).get('/api/v1/instance').then(response => {
|
api(getState).get('/api/v1/instance').then(response => {
|
||||||
dispatch(importInstance(response.data));
|
dispatch(importInstance(response.data));
|
||||||
|
const v = parseVersion(get(response.data, 'version'));
|
||||||
|
if (v.software === 'Pleroma' && !get(response.data, ['pleroma', 'metadata'])) {
|
||||||
|
dispatch(fetchNodeinfo()); // Pleroma < 2.1 backwards compatibility
|
||||||
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(instanceFail(error));
|
dispatch(instanceFail(error));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fetchNodeinfo() {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
api(getState).get('/nodeinfo/2.1.json').then(response => {
|
||||||
|
dispatch(importNodeinfo(response.data));
|
||||||
|
}).catch(error => {
|
||||||
|
dispatch(nodeinfoFail(error));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function importInstance(instance) {
|
export function importInstance(instance) {
|
||||||
return {
|
return {
|
||||||
type: INSTANCE_IMPORT,
|
type: INSTANCE_IMPORT,
|
||||||
|
@ -27,3 +45,18 @@ export function instanceFail(error) {
|
||||||
skipAlert: true,
|
skipAlert: true,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function importNodeinfo(nodeinfo) {
|
||||||
|
return {
|
||||||
|
type: NODEINFO_IMPORT,
|
||||||
|
nodeinfo,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function nodeinfoFail(error) {
|
||||||
|
return {
|
||||||
|
type: NODEINFO_FAIL,
|
||||||
|
error,
|
||||||
|
skipAlert: true,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
import { INSTANCE_IMPORT } from '../actions/instance';
|
import {
|
||||||
|
INSTANCE_IMPORT,
|
||||||
|
NODEINFO_IMPORT,
|
||||||
|
} from '../actions/instance';
|
||||||
import { Map as ImmutableMap, fromJS } from 'immutable';
|
import { Map as ImmutableMap, fromJS } from 'immutable';
|
||||||
|
|
||||||
|
const nodeinfoToInstance = nodeinfo => {
|
||||||
|
// Match Pleroma's develop branch
|
||||||
|
return ImmutableMap({
|
||||||
|
pleroma: ImmutableMap({
|
||||||
|
metadata: ImmutableMap({
|
||||||
|
account_activation_required: nodeinfo.getIn(['metadata', 'accountActivationRequired']),
|
||||||
|
features: nodeinfo.getIn(['metadata', 'features']),
|
||||||
|
federation: nodeinfo.getIn(['metadata', 'federation']),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Set Mastodon defaults, overridden by Pleroma servers
|
// Set Mastodon defaults, overridden by Pleroma servers
|
||||||
const initialState = ImmutableMap({
|
const initialState = ImmutableMap({
|
||||||
max_toot_chars: 500,
|
max_toot_chars: 500,
|
||||||
|
@ -16,6 +32,8 @@ export default function instance(state = initialState, action) {
|
||||||
switch(action.type) {
|
switch(action.type) {
|
||||||
case INSTANCE_IMPORT:
|
case INSTANCE_IMPORT:
|
||||||
return initialState.merge(fromJS(action.instance));
|
return initialState.merge(fromJS(action.instance));
|
||||||
|
case NODEINFO_IMPORT:
|
||||||
|
return nodeinfoToInstance(fromJS(action.nodeinfo)).merge(state);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue