Only support Pleroma for now
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
3448022965
commit
1ea4ae3a57
5 changed files with 6 additions and 41 deletions
|
@ -1,6 +1,5 @@
|
|||
import { createAsyncThunk } from '@reduxjs/toolkit';
|
||||
import get from 'lodash/get';
|
||||
import { gte } from 'semver';
|
||||
|
||||
import KVStore from 'soapbox/storage/kv_store';
|
||||
import { RootState } from 'soapbox/store';
|
||||
|
@ -38,12 +37,6 @@ const needsNodeinfo = (instance: Record<string, any>): boolean => {
|
|||
return v.software === 'Pleroma' && !get(instance, ['pleroma', 'metadata']);
|
||||
};
|
||||
|
||||
/** Mastodon exposes features availabiliy under /api/v2/instance since 4.0.0 */
|
||||
const supportsInstanceV2 = (instance: Record<string, any>): boolean => {
|
||||
const v = parseVersion(get(instance, 'version'));
|
||||
return v.software === 'Mastodon' && gte(v.compatVersion, '4.0.0');
|
||||
};
|
||||
|
||||
export const fetchInstance = createAsyncThunk<void, void, { state: RootState }>(
|
||||
'instance/fetch',
|
||||
async(_arg, { dispatch, getState, rejectWithValue }) => {
|
||||
|
@ -52,9 +45,6 @@ export const fetchInstance = createAsyncThunk<void, void, { state: RootState }>(
|
|||
if (needsNodeinfo(instance)) {
|
||||
dispatch(fetchNodeinfo());
|
||||
}
|
||||
if (supportsInstanceV2(instance)) {
|
||||
dispatch(fetchInstanceV2());
|
||||
}
|
||||
return instance;
|
||||
} catch (e) {
|
||||
return rejectWithValue(e);
|
||||
|
@ -74,14 +64,6 @@ export const loadInstance = createAsyncThunk<void, void, { state: RootState }>(
|
|||
},
|
||||
);
|
||||
|
||||
export const fetchInstanceV2 = createAsyncThunk<void, void, { state: RootState }>(
|
||||
'nodeinfo/fetch',
|
||||
async(_arg, { getState }) => {
|
||||
const { data: instance } = await api(getState).get('/api/v2/instance');
|
||||
return instance;
|
||||
},
|
||||
);
|
||||
|
||||
export const fetchNodeinfo = createAsyncThunk<void, void, { state: RootState }>(
|
||||
'nodeinfo/fetch',
|
||||
async(_arg, { getState }) => await api(getState).get('/nodeinfo/2.1.json'),
|
||||
|
|
|
@ -310,10 +310,12 @@ const toggleStatusHidden = (status: Status) => {
|
|||
}
|
||||
};
|
||||
|
||||
const translateStatus = (id: string) => (dispatch: AppDispatch, getState: () => RootState) => {
|
||||
const translateStatus = (id: string, targetLanguage?: string) => (dispatch: AppDispatch, getState: () => RootState) => {
|
||||
dispatch({ type: STATUS_TRANSLATE_REQUEST, id });
|
||||
|
||||
api(getState).post(`/api/v1/statuses/${id}/translate`).then(response => {
|
||||
api(getState).post(`/api/v1/statuses/${id}/translate`, {
|
||||
target_language: targetLanguage,
|
||||
}).then(response => {
|
||||
dispatch({
|
||||
type: STATUS_TRANSLATE_SUCCESS,
|
||||
id,
|
||||
|
|
|
@ -27,7 +27,7 @@ const TranslateButton: React.FC<ITranslateButton> = ({ status }) => {
|
|||
if (status.translation) {
|
||||
dispatch(undoStatusTranslation(status.id));
|
||||
} else {
|
||||
dispatch(translateStatus(status.id));
|
||||
dispatch(translateStatus(status.id, intl.locale));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import {
|
|||
rememberInstance,
|
||||
fetchInstance,
|
||||
fetchNodeinfo,
|
||||
fetchInstanceV2,
|
||||
} from '../actions/instance';
|
||||
|
||||
import type { AnyAction } from 'redux';
|
||||
|
@ -33,20 +32,10 @@ const nodeinfoToInstance = (nodeinfo: ImmutableMap<string, any>) => {
|
|||
}));
|
||||
};
|
||||
|
||||
const instanceV2ToInstance = (instanceV2: ImmutableMap<string, any>) =>
|
||||
normalizeInstance(ImmutableMap({
|
||||
configuration: instanceV2.get('configuration'),
|
||||
}));
|
||||
|
||||
const importInstance = (_state: typeof initialState, instance: ImmutableMap<string, any>) => {
|
||||
return normalizeInstance(instance);
|
||||
};
|
||||
|
||||
const importInstanceV2 = (state: typeof initialState, instanceV2: ImmutableMap<string, any>) => {
|
||||
console.log(instanceV2.toJS());
|
||||
return state.mergeDeep(instanceV2ToInstance(instanceV2));
|
||||
};
|
||||
|
||||
const importNodeinfo = (state: typeof initialState, nodeinfo: ImmutableMap<string, any>) => {
|
||||
return nodeinfoToInstance(nodeinfo).mergeDeep(state);
|
||||
};
|
||||
|
@ -131,8 +120,6 @@ export default function instance(state = initialState, action: AnyAction) {
|
|||
case fetchInstance.fulfilled.type:
|
||||
persistInstance(action.payload);
|
||||
return importInstance(state, ImmutableMap(fromJS(action.payload)));
|
||||
case fetchInstanceV2.fulfilled.type:
|
||||
return importInstanceV2(state, ImmutableMap(fromJS(action.payload)));
|
||||
case fetchInstance.rejected.type:
|
||||
return handleInstanceFetchFail(state, action.error);
|
||||
case fetchNodeinfo.fulfilled.type:
|
||||
|
|
|
@ -353,12 +353,6 @@ const getInstanceFeatures = (instance: Instance) => {
|
|||
*/
|
||||
importData: v.software === PLEROMA && gte(v.version, '2.2.0'),
|
||||
|
||||
/**
|
||||
* Supports V2 instance endpoint.
|
||||
* @see GET /api/v2/instance
|
||||
*/
|
||||
instanceV2: v.software === MASTODON && gte(v.compatVersion, '4.0.0'),
|
||||
|
||||
/**
|
||||
* Can create, view, and manage lists.
|
||||
* @see {@link https://docs.joinmastodon.org/methods/timelines/lists/}
|
||||
|
@ -618,7 +612,7 @@ const getInstanceFeatures = (instance: Instance) => {
|
|||
* Can translate statuses.
|
||||
* @see POST /api/v1/statuses/:id/translate
|
||||
*/
|
||||
translations: v.software === MASTODON && instance.configuration.getIn(['translation', 'enabled'], false),
|
||||
translations: features.includes('translation'),
|
||||
|
||||
/**
|
||||
* Trending statuses.
|
||||
|
|
Loading…
Reference in a new issue