diff --git a/src/features/followingV2/home/FeedPage.tsx b/src/features/followingV2/home/FeedPage.tsx index 962669318..39af616c4 100644 --- a/src/features/followingV2/home/FeedPage.tsx +++ b/src/features/followingV2/home/FeedPage.tsx @@ -69,7 +69,7 @@ export function FeedPage({ const {_} = useLingui() const navigation = useNavigation>() const isScreenFocused = useIsFocused() - const {openComposer} = useOpenComposer() + const {openComposer} = useOpenComposer(isPageFocused ? feed : undefined) const [isScrolledDown, setIsScrolledDown] = useState(false) const headerOffset = useHeaderOffset() const feedFeedback = useFeedFeedback(feedInfo, hasSession) diff --git a/src/screens/Notifications/components/NotificationItem/Item/post.tsx b/src/screens/Notifications/components/NotificationItem/Item/post.tsx index 7d7644c81..e3500b303 100644 --- a/src/screens/Notifications/components/NotificationItem/Item/post.tsx +++ b/src/screens/Notifications/components/NotificationItem/Item/post.tsx @@ -4,6 +4,7 @@ import {moderatePost, type ModerationDecision} from '@bsky/sdk/moderation' import {RichText as RichTextAPI} from '@bsky/sdk/richtext' import {Trans, useLingui} from '@lingui/react/macro' +import {getCommunitySpaceUri} from '#/lib/api/community-post' import {MAX_POST_LINES} from '#/lib/constants' import {useOpenComposer} from '#/lib/hooks/useOpenComposer' import {makeProfileLink} from '#/lib/routes/links' @@ -509,6 +510,7 @@ function PostActionsInner({ ? moderatePost(post, moderationOpts) : undefined, langs: record.langs, + communitySpace: getCommunitySpaceUri(post), }, logContext: 'PostReply', }) diff --git a/src/screens/Notifications/components/NotificationItem/links.test.ts b/src/screens/Notifications/components/NotificationItem/links.test.ts new file mode 100644 index 000000000..fc39ec13d --- /dev/null +++ b/src/screens/Notifications/components/NotificationItem/links.test.ts @@ -0,0 +1,46 @@ +import {makePostLink} from './links' + +const author = {did: 'did:plc:alice', handle: 'alice.test'} +const SPACE = 'at://did:plc:tenant/space/community.blacksky.feed/private' + +describe('makePostLink', () => { + it('links a public post by its record key', () => { + expect( + makePostLink({ + uri: 'at://did:plc:alice/app.bsky.feed.post/3kpub', + author, + }), + ).toBe('/profile/did:plc:alice/post/3kpub') + }) + + it('keeps sub-routes ahead of the query', () => { + expect( + makePostLink( + {uri: 'at://did:plc:alice/app.bsky.feed.post/3kpub', author}, + 'liked-by', + ), + ).toBe('/profile/did:plc:alice/post/3kpub/liked-by') + }) + + it('names the space of a post in a permissioned space', () => { + expect( + makePostLink({ + uri: `${SPACE}/did:plc:alice/app.bsky.feed.post/3kprivate`, + author, + }), + ).toBe( + `/profile/did:plc:alice/post/3kprivate?space=${encodeURIComponent(SPACE)}`, + ) + }) + + it('names the collection of a community post', () => { + expect( + makePostLink( + {uri: 'at://did:plc:alice/community.blacksky.feed.post/3kcomm', author}, + 'liked-by', + ), + ).toBe( + '/profile/did:plc:alice/post/3kcomm/liked-by?collection=community.blacksky.feed.post', + ) + }) +}) diff --git a/src/screens/Notifications/components/NotificationItem/links.ts b/src/screens/Notifications/components/NotificationItem/links.ts index c368cd1fa..647d6d53e 100644 --- a/src/screens/Notifications/components/NotificationItem/links.ts +++ b/src/screens/Notifications/components/NotificationItem/links.ts @@ -1,6 +1,7 @@ import {AtUri} from '@atproto/syntax' import {makeProfileLink} from '#/lib/routes/links' +import {postUriToRelativePath} from '#/lib/strings/url-helpers' /** * `getPosts`, which backs the activity list screen, takes at most 25 URIs. @@ -15,12 +16,21 @@ export function makePostLink( post: {uri: string; author: {did: string; handle: string}}, ...segments: string[] ) { - return makeProfileLink( - post.author, - 'post', - new AtUri(post.uri).rkey, - ...segments, - ) + /* + * A post in a permissioned space or a community collection needs the query + * that names it, and a space record URI does not parse as an at-uri at all. + */ + const path = postUriToRelativePath(post.uri) + if (path === undefined) { + return makeProfileLink( + post.author, + 'post', + new AtUri(post.uri).rkey, + ...segments, + ) + } + const [pathname, query] = path.split('?') + return [pathname, ...segments].join('/') + (query ? `?${query}` : '') } /** diff --git a/src/state/queries/notifications/grouped/__tests__/moderate.test.ts b/src/state/queries/notifications/grouped/__tests__/moderate.test.ts index 9f8d44dda..d591d92c7 100644 --- a/src/state/queries/notifications/grouped/__tests__/moderate.test.ts +++ b/src/state/queries/notifications/grouped/__tests__/moderate.test.ts @@ -271,4 +271,24 @@ describe('moderateNotification', () => { expect(result).toEqual({...subscribed, items: [hidden[1], hidden[2]]}) }) }) + + describe('hide follow notifications', () => { + const args = {...ARGS, hideFollowNotifications: true} + + it('drops a follow notification when the setting is on', () => { + expect( + moderateNotification(get('follow-many', 'follow'), args), + ).toBeUndefined() + }) + + it('keeps follow-backs and everything else', () => { + const followBack = get('follow-back', 'followBack') + expect(moderateNotification(followBack, args)).toBe(followBack) + }) + + it('keeps follows when the setting is off', () => { + const follow = get('follow-many', 'follow') + expect(moderateNotification(follow, ARGS)).toBe(follow) + }) + }) }) diff --git a/src/state/queries/notifications/grouped/index.ts b/src/state/queries/notifications/grouped/index.ts index e16b2d46e..6b3b06df7 100644 --- a/src/state/queries/notifications/grouped/index.ts +++ b/src/state/queries/notifications/grouped/index.ts @@ -7,6 +7,7 @@ import { } from '@tanstack/react-query' import {getGroupedNotifications} from '#/lib/api/community-notifications' +import {useHideFollowNotifications} from '#/state/preferences/hide-follow-notifications' import {useModerationOpts} from '#/state/preferences/moderation-opts' import {STALE} from '#/state/queries' import {getNextCursor} from '#/state/queries/notifications/grouped/cursor' @@ -157,6 +158,7 @@ export function useGroupedNotificationsQuery({ const {currentAccount} = useSession() const moderationOpts = useModerationOpts() const {uris: hiddenReplyUris} = useThreadgateHiddenReplyUris() + const hideFollowNotifications = useHideFollowNotifications() const viewerDid = currentAccount?.did /* * Compare by time rather than identity, so a caller passing a fresh `Date` @@ -184,6 +186,7 @@ export function useGroupedNotificationsQuery({ return selectNotifications(data, { moderationOpts, hiddenReplyUris, + hideFollowNotifications, seenAtMs, }) }, @@ -226,6 +229,7 @@ function selectNotifications( !cached || cached.args.moderationOpts !== args.moderationOpts || cached.args.hiddenReplyUris !== args.hiddenReplyUris || + cached.args.hideFollowNotifications !== args.hideFollowNotifications || cached.args.seenAtMs !== args.seenAtMs ) { cached = { diff --git a/src/state/queries/notifications/grouped/moderate.ts b/src/state/queries/notifications/grouped/moderate.ts index 65cd677ae..53cdbb234 100644 --- a/src/state/queries/notifications/grouped/moderate.ts +++ b/src/state/queries/notifications/grouped/moderate.ts @@ -34,6 +34,10 @@ export type NotificationModerationArgs = { * Replies the viewer has hidden with a threadgate. */ hiddenReplyUris: ReadonlySet + /** + * The viewer's "hide follow notifications" setting. + */ + hideFollowNotifications?: boolean } /** @@ -48,8 +52,15 @@ export type NotificationModerationArgs = { */ export function moderateNotification( notification: NotificationView, - {moderationOpts, hiddenReplyUris}: NotificationModerationArgs, + { + moderationOpts, + hiddenReplyUris, + hideFollowNotifications, + }: NotificationModerationArgs, ): NotificationView | undefined { + if (hideFollowNotifications && notification.type === 'follow') { + return undefined + } switch (notification.type) { case 'like': case 'repost':