Support trending statuses from Mastodon 3.5

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-03-29 21:15:06 +02:00
parent 6d4d96528c
commit 36c0fb5882
2 changed files with 10 additions and 1 deletions

View file

@ -1,3 +1,5 @@
import { getFeatures } from 'soapbox/utils/features';
import api from '../api'; import api from '../api';
import { importFetchedStatuses } from './importer'; import { importFetchedStatuses } from './importer';
@ -8,8 +10,13 @@ export const TRENDING_STATUSES_FETCH_FAIL = 'TRENDING_STATUSES_FETCH_FAIL';
export function fetchTrendingStatuses() { export function fetchTrendingStatuses() {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState();
const instance = state.get('instance');
const features = getFeatures(instance);
dispatch({ type: TRENDING_STATUSES_FETCH_REQUEST }); dispatch({ type: TRENDING_STATUSES_FETCH_REQUEST });
return api(getState).get('/api/v1/truth/trending/truths').then(({ data: statuses }) => { return api(getState).get(features.trendingTruths ? '/api/v1/truth/trending/truths' : '/api/v1/trends/statuses').then(({ data: statuses }) => {
dispatch(importFetchedStatuses(statuses)); dispatch(importFetchedStatuses(statuses));
dispatch({ type: TRENDING_STATUSES_FETCH_SUCCESS, statuses }); dispatch({ type: TRENDING_STATUSES_FETCH_SUCCESS, statuses });
return statuses; return statuses;

View file

@ -123,6 +123,8 @@ const getInstanceFeatures = (instance: Instance) => {
v.software === MASTODON && gte(v.compatVersion, '3.2.0'), v.software === MASTODON && gte(v.compatVersion, '3.2.0'),
v.software === PLEROMA && gte(v.version, '2.4.50'), v.software === PLEROMA && gte(v.version, '2.4.50'),
]), ]),
trendingTruths: v.software === TRUTHSOCIAL,
trendingStatuses: v.software === MASTODON && gte(v.compatVersion, '3.5.0'),
}; };
}; };