From 86579abd4581abde251536b1be48f8588214a18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sat, 16 Jul 2022 19:59:00 +0200 Subject: [PATCH] Workaround for filtering on latest Mastodon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/actions/filters.ts | 7 +++++++ app/soapbox/normalizers/status.ts | 6 ++++++ app/soapbox/utils/features.ts | 5 ++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/soapbox/actions/filters.ts b/app/soapbox/actions/filters.ts index 61b4e9b631..c0f79c6b89 100644 --- a/app/soapbox/actions/filters.ts +++ b/app/soapbox/actions/filters.ts @@ -2,6 +2,7 @@ import { defineMessages } from 'react-intl'; import snackbar from 'soapbox/actions/snackbar'; import { isLoggedIn } from 'soapbox/utils/auth'; +import { getFeatures } from 'soapbox/utils/features'; import api from '../api'; @@ -28,6 +29,12 @@ const fetchFilters = () => (dispatch: AppDispatch, getState: () => RootState) => { if (!isLoggedIn(getState)) return; + const state = getState(); + const instance = state.instance; + const features = getFeatures(instance); + + if (!features.filters) return; + dispatch({ type: FILTERS_FETCH_REQUEST, skipLoading: true, diff --git a/app/soapbox/normalizers/status.ts b/app/soapbox/normalizers/status.ts index 5474fa3952..554b40f5f2 100644 --- a/app/soapbox/normalizers/status.ts +++ b/app/soapbox/normalizers/status.ts @@ -144,6 +144,11 @@ const fixQuote = (status: ImmutableMap) => { }); }; +// Workaround for not yet implemented filtering from Mastodon 3.6 +const fixFiltered = (status: ImmutableMap) => { + status.delete('filtered'); +}; + export const normalizeStatus = (status: Record) => { return StatusRecord( ImmutableMap(fromJS(status)).withMutations(status => { @@ -155,6 +160,7 @@ export const normalizeStatus = (status: Record) => { fixMentionsOrder(status); addSelfMention(status); fixQuote(status); + fixFiltered(status); }), ); }; diff --git a/app/soapbox/utils/features.ts b/app/soapbox/utils/features.ts index 0afe0c254e..2c3ff62ee7 100644 --- a/app/soapbox/utils/features.ts +++ b/app/soapbox/utils/features.ts @@ -276,7 +276,10 @@ const getInstanceFeatures = (instance: Instance) => { * Can edit and manage timeline filters (aka "muted words"). * @see {@link https://docs.joinmastodon.org/methods/accounts/filters/} */ - filters: v.software !== TRUTHSOCIAL, + filters: any([ + v.software === MASTODON && lt(v.compatVersion, '3.6.0'), + v.software === PLEROMA, + ]), /** * Allows setting the focal point of a media attachment.