From 7626cc3cb7915f5f757fbb251757ae973fdd86a1 Mon Sep 17 00:00:00 2001 From: Rudy Fraser Date: Tue, 10 Nov 2026 21:20:36 -0500 Subject: [PATCH] fix(merge): tighten the fork handling added to the new screens A multi-post notification list fails on a server or network error instead of showing fewer posts; only a post the viewer cannot read is left out. Marking a moderation report or notice seen goes to the service it was read from. The moderation inbox post preview keeps the post's collection in its link. --- src/lib/api/community-post.ts | 23 +++++++++++++++++-- src/lib/api/feed/posts.test.ts | 20 ++++++++++++++-- src/lib/api/feed/posts.ts | 11 +++++++-- src/screens/ModerationInbox/Notice.tsx | 7 +++--- src/screens/ModerationInbox/Report.tsx | 7 +++--- .../PostSubjectPreview.tsx | 8 ++++++- src/state/queries/moderation-inbox.ts | 10 +++++++- 7 files changed, 72 insertions(+), 14 deletions(-) diff --git a/src/lib/api/community-post.ts b/src/lib/api/community-post.ts index 1be0a0b3a..98e7ffeab 100644 --- a/src/lib/api/community-post.ts +++ b/src/lib/api/community-post.ts @@ -72,6 +72,22 @@ export function getCommunitySpaceUri( : undefined } +/** A community post read the server answered with an error status. */ +export class CommunityPostError extends Error { + constructor( + message: string, + readonly status: number, + ) { + super(message) + this.name = 'CommunityPostError' + } + + /** The post is gone or the viewer may not read it; retrying will not help. */ + get isUnavailable() { + return this.status >= 400 && this.status < 500 + } +} + /** * Read one community post by URI. * @@ -89,10 +105,13 @@ export async function fetchCommunityPostView( message?: string error?: string } - throw new Error(body.message || body.error || `HTTP ${res.status}`) + throw new CommunityPostError( + body.message || body.error || `HTTP ${res.status}`, + res.status, + ) } const data = jsonToLex(await res.json()) as {post?: unknown} const post = toPostView(data.post) - if (!post) throw new Error('Community post not found') + if (!post) throw new CommunityPostError('Community post not found', 404) return post } diff --git a/src/lib/api/feed/posts.test.ts b/src/lib/api/feed/posts.test.ts index 5712e3c3e..3aee8718c 100644 --- a/src/lib/api/feed/posts.test.ts +++ b/src/lib/api/feed/posts.test.ts @@ -1,6 +1,9 @@ import {type Client} from '@atproto/lex' -import {fetchCommunityPostView} from '#/lib/api/community-post' +import { + CommunityPostError, + fetchCommunityPostView, +} from '#/lib/api/community-post' import {app} from '#/lexicons' import {PostListFeedAPI} from './posts' @@ -54,7 +57,7 @@ describe('PostListFeedAPI', () => { it('leaves out a community post the viewer can no longer read', async () => { jest .mocked(fetchCommunityPostView) - .mockRejectedValue(new Error('NotAMember')) + .mockRejectedValue(new CommunityPostError('NotAMember', 403)) const {api} = setup([PRIVATE, PUBLIC]) const page = await api.fetch({}) @@ -62,6 +65,19 @@ describe('PostListFeedAPI', () => { expect(page.feed.map(item => item.post.uri)).toEqual([PUBLIC]) }) + it.each([ + ['a server error', new CommunityPostError('down', 503)], + ['a network failure', new TypeError('Network request failed')], + ])( + 'fails the page on %s rather than showing fewer posts', + async (_name, e) => { + jest.mocked(fetchCommunityPostView).mockRejectedValue(e) + const {api} = setup([PRIVATE, PUBLIC]) + + await expect(api.fetch({})).rejects.toBe(e) + }, + ) + it('skips the standard route when every post is community content', async () => { const {api, call} = setup([PRIVATE]) diff --git a/src/lib/api/feed/posts.ts b/src/lib/api/feed/posts.ts index abe4a8b43..fb52b430c 100644 --- a/src/lib/api/feed/posts.ts +++ b/src/lib/api/feed/posts.ts @@ -1,6 +1,7 @@ import {type Client, type XrpcRequestParams} from '@atproto/lex' import { + CommunityPostError, fetchCommunityPostView, isCommunityPostUri, } from '#/lib/api/community-post' @@ -48,7 +49,8 @@ export class PostListFeedAPI implements FeedAPI { /* * `getPosts` only takes at-uris and only serves public posts, so community * and permissioned-space posts are read one by one through the - * membership-gated route. One the viewer can no longer read is left out. + * membership-gated route. One the viewer can no longer read is left out; + * any other failure fails the page, so the feed shows its error and retries. */ const community = this.params.uris.filter(uri => isCommunityPostUri(uri)) const standard = this.params.uris.filter(uri => !isCommunityPostUri(uri)) @@ -58,7 +60,12 @@ export class PostListFeedAPI implements FeedAPI { : {posts: []}, Promise.all( community.map(uri => - fetchCommunityPostView(this.client, uri).catch(() => undefined), + fetchCommunityPostView(this.client, uri).catch((e: unknown) => { + if (e instanceof CommunityPostError && e.isUnavailable) { + return undefined + } + throw e + }), ), ), ]) diff --git a/src/screens/ModerationInbox/Notice.tsx b/src/screens/ModerationInbox/Notice.tsx index e4407f253..e8351dfb8 100644 --- a/src/screens/ModerationInbox/Notice.tsx +++ b/src/screens/ModerationInbox/Notice.tsx @@ -60,14 +60,15 @@ export function ModerationInboxNoticeDetailsScreen({ const {t: l} = useLingui() const ax = useAnalytics() const {currentAccount, hasSession} = useSession() - const {mutate: markSeen} = useUpdateModerationInboxSeenMutation({ - silent: true, - }) const moderationOpts = useModerationOpts() const isEnabled = ax.features.enabled(ax.features.ModerationInboxEnable) const moderationService = isValidDid(route.params?.moderationService) ? route.params.moderationService : undefined + const {mutate: markSeen} = useUpdateModerationInboxSeenMutation({ + silent: true, + moderationService, + }) const rawSubject = route.params?.subject const subject = isValidDid(rawSubject) ? rawSubject diff --git a/src/screens/ModerationInbox/Report.tsx b/src/screens/ModerationInbox/Report.tsx index d8caeec3e..c5ad2ddcc 100644 --- a/src/screens/ModerationInbox/Report.tsx +++ b/src/screens/ModerationInbox/Report.tsx @@ -44,14 +44,15 @@ export function ModerationInboxReportDetailsScreen({ const {t: l} = useLingui() const ax = useAnalytics() const {hasSession} = useSession() - const {mutate: markSeen} = useUpdateModerationInboxSeenMutation({ - silent: true, - }) const moderationOpts = useModerationOpts() const isEnabled = ax.features.enabled(ax.features.ModerationInboxEnable) const moderationService = isValidDid(route.params.moderationService) ? route.params.moderationService : undefined + const {mutate: markSeen} = useUpdateModerationInboxSeenMutation({ + silent: true, + moderationService, + }) const parsedId = Number(route.params.id) const id = Number.isSafeInteger(parsedId) && parsedId > 0 ? parsedId : undefined diff --git a/src/screens/ModerationInbox/components/ReportSubjectPreview/PostSubjectPreview.tsx b/src/screens/ModerationInbox/components/ReportSubjectPreview/PostSubjectPreview.tsx index 3849bf811..9e16f5ebb 100644 --- a/src/screens/ModerationInbox/components/ReportSubjectPreview/PostSubjectPreview.tsx +++ b/src/screens/ModerationInbox/components/ReportSubjectPreview/PostSubjectPreview.tsx @@ -134,7 +134,13 @@ export function PostSubjectPreview({ testID="moderationInboxOpenPost" to={{ screen: 'PostThread', - params: {name: uri.host, rkey: uri.rkey}, + params: { + name: uri.host, + rkey: uri.rkey, + ...(uri.collection === 'app.bsky.feed.post' + ? {} + : {collection: uri.collection}), + }, }} label={l`Open post`} size="tiny" diff --git a/src/state/queries/moderation-inbox.ts b/src/state/queries/moderation-inbox.ts index e5517af56..f979142fb 100644 --- a/src/state/queries/moderation-inbox.ts +++ b/src/state/queries/moderation-inbox.ts @@ -324,8 +324,14 @@ export function useUpdateModerationInboxNotificationPreferencesMutation() { export function useUpdateModerationInboxSeenMutation({ silent = false, + moderationService, }: { silent?: boolean + /** + * The service whose item is being read. A report or notice opened from + * another service must be marked seen there, not on the default one. + */ + moderationService?: DidString } = {}) { const {t: l} = useLingui() const client = useAppviewClient() @@ -336,7 +342,9 @@ export function useUpdateModerationInboxSeenMutation({ return useMutation({ mutationFn: async (input: tools.ozone.inbox.updateSeen.$InputBody) => await client.call(tools.ozone.inbox.updateSeen, input, { - service: MOD_PROXY_SERVICE, + service: moderationService + ? `${moderationService}#atproto_labeler` + : MOD_PROXY_SERVICE, }), onSuccess: async () => { await queryClient.invalidateQueries({queryKey}) -- knotmirror 0.0.1