Merge branch 'carousel-seen-feature' into 'develop'

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

See merge request soapbox-pub/soapbox!2001
This commit is contained in:
Alex Gleason 2022-12-14 19:46:30 +00:00
commit e2c7933513
5 changed files with 29 additions and 12 deletions

View file

@ -21,7 +21,7 @@ jest.mock('../../../hooks/useDimensions', () => ({
describe('<FeedCarousel />', () => { describe('<FeedCarousel />', () => {
let store: any; let store: any;
describe('with "feedUserFiltering" disabled', () => { describe('with "carousel" disabled', () => {
beforeEach(() => { beforeEach(() => {
store = { store = {
instance: { instance: {
@ -42,7 +42,7 @@ describe('<FeedCarousel />', () => {
}); });
}); });
describe('with "feedUserFiltering" enabled', () => { describe('with "carousel" enabled', () => {
beforeEach(() => { beforeEach(() => {
store = { store = {
instance: { instance: {
@ -70,6 +70,8 @@ describe('<FeedCarousel />', () => {
mock.onGet('/api/v1/accounts/1/statuses').reply(200, [], { mock.onGet('/api/v1/accounts/1/statuses').reply(200, [], {
link: '<https://example.com/api/v1/accounts/1/statuses?since_id=1>; rel=\'prev\'', link: '<https://example.com/api/v1/accounts/1/statuses?since_id=1>; rel=\'prev\'',
}); });
mock.onPost('/api/v1/truth/carousels/avatars/seen').reply(200);
}); });
}); });

View file

@ -96,7 +96,7 @@ const FeedCarousel = () => {
if (avatars.length > 0) { if (avatars.length > 0) {
setSeenAccountIds( setSeenAccountIds(
avatars avatars
.filter((avatar) => avatar.seen) .filter((avatar) => avatar.seen !== false)
.map((avatar) => avatar.account_id), .map((avatar) => avatar.account_id),
); );
} }

View file

@ -59,7 +59,7 @@ const HomePage: React.FC = ({ children }) => {
</Card> </Card>
)} )}
{features.feedUserFiltering && <FeedCarousel />} {features.carousel && <FeedCarousel />}
{children} {children}

View file

@ -1,12 +1,12 @@
import { useMutation, useQuery } from '@tanstack/react-query'; import { useMutation, useQuery } from '@tanstack/react-query';
import { useApi } from 'soapbox/hooks'; import { useApi, useFeatures } from 'soapbox/hooks';
export type Avatar = { export type Avatar = {
account_id: string account_id: string
account_avatar: string account_avatar: string
acct: string acct: string
seen: boolean seen?: boolean
} }
const CarouselKeys = { const CarouselKeys = {
@ -36,10 +36,15 @@ function useCarouselAvatars() {
function useMarkAsSeen() { function useMarkAsSeen() {
const api = useApi(); const api = useApi();
const features = useFeatures();
return useMutation((account_id: string) => api.post('/api/v1/truth/carousels/avatars/seen', { return useMutation(async (accountId: string) => {
account_id, if (features.carouselSeen) {
})); await void api.post('/api/v1/truth/carousels/avatars/seen', {
account_id: accountId,
});
}
});
} }
export { useCarouselAvatars, useMarkAsSeen }; export { useCarouselAvatars, useMarkAsSeen };

View file

@ -205,6 +205,19 @@ const getInstanceFeatures = (instance: Instance) => {
v.software === PLEROMA, v.software === PLEROMA,
]), ]),
/**
* Whether to show the Feed Carousel for suggested Statuses.
* @see GET /api/v1/truth/carousels/avatars
* @see GET /api/v1/truth/carousels/suggestions
*/
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. * Ability to accept a chat.
* POST /api/v1/pleroma/chats/:id/accept * POST /api/v1/pleroma/chats/:id/accept
@ -371,9 +384,6 @@ const getInstanceFeatures = (instance: Instance) => {
/** Whether the instance federates. */ /** Whether the instance federates. */
federating: federation.get('enabled', true) === true, // Assume true unless explicitly false federating: federation.get('enabled', true) === true, // Assume true unless explicitly false
/** Whether or not to show the Feed Carousel for suggested Statuses */
feedUserFiltering: v.software === TRUTHSOCIAL,
/** /**
* Can edit and manage timeline filters (aka "muted words"). * Can edit and manage timeline filters (aka "muted words").
* @see {@link https://docs.joinmastodon.org/methods/accounts/filters/} * @see {@link https://docs.joinmastodon.org/methods/accounts/filters/}