diff --git a/package.json b/package.json index 74f75a73d..7c4249da4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blacksky.community", - "version": "1.134.0", + "version": "1.134.1", "private": true, "sideEffects": [ "*.css", diff --git a/src/state/queries/__tests__/moderation-inbox-service.test.tsx b/src/state/queries/__tests__/moderation-inbox-service.test.tsx new file mode 100644 index 000000000..a1dab8cc8 --- /dev/null +++ b/src/state/queries/__tests__/moderation-inbox-service.test.tsx @@ -0,0 +1,97 @@ +import {type PropsWithChildren} from 'react' +import {i18n} from '@lingui/core' +import {I18nProvider} from '@lingui/react' +import {QueryClient, QueryClientProvider} from '@tanstack/react-query' +import {act, renderHook, waitFor} from '@testing-library/react-native' + +import {useAppviewClient, useSession} from '#/state/session' +import {BLACKSKY_LABELER} from '#/state/session/additional-moderation-authorities' +import {tools} from '#/lexicons' +import { + useModerationInboxAccountStatusQuery, + useUpdateModerationInboxSeenMutation, +} from '../moderation-inbox' + +jest.mock('#/state/session', () => ({ + useAppviewClient: jest.fn(), + useSession: jest.fn(), +})) +jest.mock('#/state/session/additional-moderation-authorities', () => ({ + BLACKSKY_LABELER: 'did:plc:d2mkddsbmnrgr3domzg5qexf', +})) +jest.mock('#/components/Toast', () => ({show: jest.fn()})) +jest.mock('#/logger', () => ({logger: {error: jest.fn(), debug: jest.fn()}})) + +i18n.activate('en') + +const OWN_SERVICE = `${BLACKSKY_LABELER}#atproto_labeler` + +function setup() { + const call = jest.fn().mockResolvedValue({}) + jest.mocked(useAppviewClient).mockReturnValue({call} as never) + jest.mocked(useSession).mockReturnValue({ + currentAccount: {did: 'did:plc:viewer'}, + hasSession: true, + } as never) + const queryClient = new QueryClient({ + defaultOptions: { + queries: {retry: false, gcTime: Infinity}, + mutations: {retry: false, gcTime: Infinity}, + }, + }) + const wrapper = ({children}: PropsWithChildren) => ( + + {children} + + ) + return {call, wrapper} +} + +describe('moderation inbox service', () => { + it('reads the inbox from the app’s own moderation service', async () => { + const {call, wrapper} = setup() + + renderHook(() => useModerationInboxAccountStatusQuery(), {wrapper}) + + await waitFor(() => expect(call).toHaveBeenCalled()) + expect(call).toHaveBeenCalledWith( + tools.ozone.inbox.getAccountStatus, + {}, + {service: OWN_SERVICE}, + ) + }) + + it('marks the inbox seen on the same service', async () => { + const {call, wrapper} = setup() + const {result} = renderHook(() => useUpdateModerationInboxSeenMutation(), { + wrapper, + }) + + await act(() => result.current.mutateAsync({sections: ['reports']})) + + expect(call).toHaveBeenCalledWith( + tools.ozone.inbox.updateSeen, + {sections: ['reports']}, + {service: OWN_SERVICE}, + ) + }) + + it('marks an item seen on the service it came from', async () => { + const {call, wrapper} = setup() + const {result} = renderHook( + () => + useUpdateModerationInboxSeenMutation({ + moderationService: 'did:plc:other', + }), + {wrapper}, + ) + + await act(() => result.current.mutateAsync({sections: ['reports']})) + + expect(call).toHaveBeenCalledWith( + tools.ozone.inbox.updateSeen, + {sections: ['reports']}, + {service: 'did:plc:other#atproto_labeler'}, + ) + }) +}) diff --git a/src/state/queries/moderation-inbox.ts b/src/state/queries/moderation-inbox.ts index f979142fb..162083691 100644 --- a/src/state/queries/moderation-inbox.ts +++ b/src/state/queries/moderation-inbox.ts @@ -1,3 +1,4 @@ +import {type Service} from '@atproto/lex' import {type DidString} from '@atproto/syntax' import {useLingui} from '@lingui/react/macro' import { @@ -8,18 +9,26 @@ import { useQueryClient, } from '@tanstack/react-query' -import {MOD_PROXY_SERVICE} from '#/lib/constants' import {isNetworkError} from '#/lib/strings/errors' import {matchXrpcError} from '#/lib/xrpc-error' import {logger} from '#/logger' import {STALE} from '#/state/queries' import {createQueryKey} from '#/state/queries/util' import {useAppviewClient, useSession} from '#/state/session' +import {BLACKSKY_LABELER} from '#/state/session/additional-moderation-authorities' import * as Toast from '#/components/Toast' +import {MOD_PROXY_DID} from '#/env' import {tools} from '#/lexicons' const QUERY_KEY_ROOT = 'moderation-inbox' +/* + * The inbox belongs to this app's own moderation service. The shared + * `MOD_PROXY_SERVICE` defaults to Bluesky's, which is right for the appeals + * that use it (chat and live access) and wrong here. + */ +const INBOX_SERVICE: Service = `${MOD_PROXY_DID || BLACKSKY_LABELER}#atproto_labeler` + type ReportsFilter = NonNullable< tools.ozone.inbox.listReports.$Params['filter'] > @@ -42,7 +51,7 @@ export function useModerationInboxReportsQuery(filter: ReportsFilter) { await client.call( tools.ozone.inbox.listReports, {filter, limit: 100, cursor: pageParam}, - {service: MOD_PROXY_SERVICE}, + {service: INBOX_SERVICE}, ), initialPageParam: undefined as string | undefined, getNextPageParam: lastPage => lastPage.cursor, @@ -104,7 +113,7 @@ export function useModerationInboxActionedSubjectsQuery( await client.call( tools.ozone.inbox.listActionedSubjects, {filter, limit: 30, cursor: pageParam}, - {service: MOD_PROXY_SERVICE}, + {service: INBOX_SERVICE}, ), initialPageParam: undefined as string | undefined, getNextPageParam: lastPage => lastPage.cursor, @@ -124,7 +133,7 @@ export function useModerationInboxAccountStatusQuery() { await client.call( tools.ozone.inbox.getAccountStatus, {}, - {service: MOD_PROXY_SERVICE}, + {service: INBOX_SERVICE}, ), staleTime: STALE.MINUTES.ONE, enabled: hasSession && !!did, @@ -253,7 +262,7 @@ export function useModerationInboxUnreadCountQuery(isEnabled = true) { await client.call( tools.ozone.inbox.getUnreadCount, {}, - {service: MOD_PROXY_SERVICE}, + {service: INBOX_SERVICE}, ), staleTime: STALE.SECONDS.THIRTY, enabled: isEnabled && hasSession && !!did, @@ -276,7 +285,7 @@ export function useModerationInboxNotificationPreferencesQuery( await client.call( tools.ozone.inbox.getNotificationPreferences, {}, - {service: MOD_PROXY_SERVICE}, + {service: INBOX_SERVICE}, ), staleTime: STALE.MINUTES.ONE, enabled: isEnabled && hasSession && !!did, @@ -300,7 +309,7 @@ export function useUpdateModerationInboxNotificationPreferencesMutation() { await client.call( tools.ozone.inbox.putNotificationPreferences, preferences, - {service: MOD_PROXY_SERVICE}, + {service: INBOX_SERVICE}, ), onMutate: async () => { await queryClient.cancelQueries({queryKey}) @@ -344,7 +353,7 @@ export function useUpdateModerationInboxSeenMutation({ await client.call(tools.ozone.inbox.updateSeen, input, { service: moderationService ? `${moderationService}#atproto_labeler` - : MOD_PROXY_SERVICE, + : INBOX_SERVICE, }), onSuccess: async () => { await queryClient.invalidateQueries({queryKey})