Carousel: make seen optional, only hit the API if features.carouselSeen is supported

This commit is contained in:
Alex Gleason 2022-12-14 13:06:41 -06:00
parent 30abdab924
commit 8f3c0a1071
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 16 additions and 5 deletions

View file

@ -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 };

View file

@ -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