diff --git a/app/soapbox/actions/instance.ts b/app/soapbox/actions/instance.ts index 3a45abf49..151ad3672 100644 --- a/app/soapbox/actions/instance.ts +++ b/app/soapbox/actions/instance.ts @@ -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): 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): boolean => { - const v = parseVersion(get(instance, 'version')); - return v.software === 'Mastodon' && gte(v.compatVersion, '4.0.0'); -}; - export const fetchInstance = createAsyncThunk( 'instance/fetch', async(_arg, { dispatch, getState, rejectWithValue }) => { @@ -52,9 +45,6 @@ export const fetchInstance = createAsyncThunk( 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( }, ); -export const fetchInstanceV2 = createAsyncThunk( - 'nodeinfo/fetch', - async(_arg, { getState }) => { - const { data: instance } = await api(getState).get('/api/v2/instance'); - return instance; - }, -); - export const fetchNodeinfo = createAsyncThunk( 'nodeinfo/fetch', async(_arg, { getState }) => await api(getState).get('/nodeinfo/2.1.json'), diff --git a/app/soapbox/actions/statuses.ts b/app/soapbox/actions/statuses.ts index 5ebf1c95c..f9bfca3b0 100644 --- a/app/soapbox/actions/statuses.ts +++ b/app/soapbox/actions/statuses.ts @@ -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, diff --git a/app/soapbox/components/translate-button.tsx b/app/soapbox/components/translate-button.tsx index 5c6334fd3..d39cba1a6 100644 --- a/app/soapbox/components/translate-button.tsx +++ b/app/soapbox/components/translate-button.tsx @@ -27,7 +27,7 @@ const TranslateButton: React.FC = ({ status }) => { if (status.translation) { dispatch(undoStatusTranslation(status.id)); } else { - dispatch(translateStatus(status.id)); + dispatch(translateStatus(status.id, intl.locale)); } }; diff --git a/app/soapbox/reducers/instance.ts b/app/soapbox/reducers/instance.ts index ad6b5ae2f..4c1456dc4 100644 --- a/app/soapbox/reducers/instance.ts +++ b/app/soapbox/reducers/instance.ts @@ -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) => { })); }; -const instanceV2ToInstance = (instanceV2: ImmutableMap) => - normalizeInstance(ImmutableMap({ - configuration: instanceV2.get('configuration'), - })); - const importInstance = (_state: typeof initialState, instance: ImmutableMap) => { return normalizeInstance(instance); }; -const importInstanceV2 = (state: typeof initialState, instanceV2: ImmutableMap) => { - console.log(instanceV2.toJS()); - return state.mergeDeep(instanceV2ToInstance(instanceV2)); -}; - const importNodeinfo = (state: typeof initialState, nodeinfo: ImmutableMap) => { 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: diff --git a/app/soapbox/utils/features.ts b/app/soapbox/utils/features.ts index 716809612..f70402873 100644 --- a/app/soapbox/utils/features.ts +++ b/app/soapbox/utils/features.ts @@ -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.