From 8f3c0a1071d2ab13b2a40b496365278cf9990140 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 14 Dec 2022 13:06:41 -0600 Subject: [PATCH] Carousel: make `seen` optional, only hit the API if features.carouselSeen is supported --- app/soapbox/queries/carousels.ts | 15 ++++++++++----- app/soapbox/utils/features.ts | 6 ++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/soapbox/queries/carousels.ts b/app/soapbox/queries/carousels.ts index c908b352a..d6e05798a 100644 --- a/app/soapbox/queries/carousels.ts +++ b/app/soapbox/queries/carousels.ts @@ -1,12 +1,12 @@ import { useMutation, useQuery } from '@tanstack/react-query'; -import { useApi } from 'soapbox/hooks'; +import { useApi, useFeatures } from 'soapbox/hooks'; export type Avatar = { account_id: string account_avatar: string acct: string - seen: boolean + seen?: boolean } const CarouselKeys = { @@ -36,10 +36,15 @@ function useCarouselAvatars() { function useMarkAsSeen() { const api = useApi(); + const features = useFeatures(); - return useMutation((account_id: string) => api.post('/api/v1/truth/carousels/avatars/seen', { - account_id, - })); + return useMutation(async (accountId: string) => { + if (features.carouselSeen) { + await void api.post('/api/v1/truth/carousels/avatars/seen', { + account_id: accountId, + }); + } + }); } export { useCarouselAvatars, useMarkAsSeen }; \ No newline at end of file diff --git a/app/soapbox/utils/features.ts b/app/soapbox/utils/features.ts index 9fc226b4e..1927bde2e 100644 --- a/app/soapbox/utils/features.ts +++ b/app/soapbox/utils/features.ts @@ -212,6 +212,12 @@ const getInstanceFeatures = (instance: Instance) => { */ carousel: v.software === TRUTHSOCIAL, + /** + * Ability to mark a carousel avatar as "seen." + * @see POST /api/v1/truth/carousels/avatars/seen + */ + carouselSeen: v.software === TRUTHSOCIAL, + /** * Ability to accept a chat. * POST /api/v1/pleroma/chats/:id/accept