Merge branch 'master' into themes
This commit is contained in:
commit
86d585ffbd
2 changed files with 54 additions and 3 deletions
|
@ -1,18 +1,36 @@
|
|||
import api from '../api';
|
||||
import { get } from 'lodash';
|
||||
import { parseVersion } from 'soapbox/utils/features';
|
||||
|
||||
export const INSTANCE_IMPORT = 'INSTANCE_IMPORT';
|
||||
export const INSTANCE_FAIL = 'INSTANCE_FAIL';
|
||||
export const INSTANCE_IMPORT = 'INSTANCE_IMPORT';
|
||||
export const INSTANCE_FAIL = 'INSTANCE_FAIL';
|
||||
export const NODEINFO_IMPORT = 'NODEINFO_IMPORT';
|
||||
export const NODEINFO_FAIL = 'NODEINFO_FAIL';
|
||||
|
||||
export function fetchInstance() {
|
||||
return (dispatch, getState) => {
|
||||
api(getState).get('/api/v1/instance').then(response => {
|
||||
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 => {
|
||||
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) {
|
||||
return {
|
||||
type: INSTANCE_IMPORT,
|
||||
|
@ -27,3 +45,18 @@ export function instanceFail(error) {
|
|||
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';
|
||||
|
||||
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
|
||||
const initialState = ImmutableMap({
|
||||
max_toot_chars: 500,
|
||||
|
@ -16,6 +32,8 @@ export default function instance(state = initialState, action) {
|
|||
switch(action.type) {
|
||||
case INSTANCE_IMPORT:
|
||||
return initialState.merge(fromJS(action.instance));
|
||||
case NODEINFO_IMPORT:
|
||||
return nodeinfoToInstance(fromJS(action.nodeinfo)).merge(state);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue