From 6694a33603544511441474819216d51482d19827 Mon Sep 17 00:00:00 2001 From: Hailey Date: Tue, 2 Jul 2024 19:50:04 -0700 Subject: [PATCH] Don't follow self, blocks or mute when following all; don't show blocks in list (#4715) * don't follow self when following all * also filter blocks * add more filtering to follow all * extract logic to functions --- .../StarterPack/Main/ProfilesList.tsx | 3 ++- src/lib/moderation/blocked-and-muted.ts | 17 +++++++++++++++++ src/screens/StarterPack/StarterPackScreen.tsx | 9 ++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/lib/moderation/blocked-and-muted.ts diff --git a/src/components/StarterPack/Main/ProfilesList.tsx b/src/components/StarterPack/Main/ProfilesList.tsx index 7691e72229..0cc911d66a 100644 --- a/src/components/StarterPack/Main/ProfilesList.tsx +++ b/src/components/StarterPack/Main/ProfilesList.tsx @@ -9,6 +9,7 @@ import { import {InfiniteData, UseInfiniteQueryResult} from '@tanstack/react-query' import {useBottomBarOffset} from 'lib/hooks/useBottomBarOffset' +import {isBlockedOrBlocking} from 'lib/moderation/blocked-and-muted' import {isNative, isWeb} from 'platform/detection' import {useSession} from 'state/session' import {List, ListRef} from 'view/com/util/List' @@ -47,7 +48,7 @@ export const ProfilesList = React.forwardRef( // The server returns these sorted by descending creation date, so we want to invert const profiles = data?.pages .flatMap(p => p.items.map(i => i.subject)) - .filter(p => !p.associated?.labeler) + .filter(p => !isBlockedOrBlocking(p) && !p.associated?.labeler) .reverse() const isOwn = new AtUri(listUri).host === currentAccount?.did diff --git a/src/lib/moderation/blocked-and-muted.ts b/src/lib/moderation/blocked-and-muted.ts new file mode 100644 index 0000000000..18e6ef3e34 --- /dev/null +++ b/src/lib/moderation/blocked-and-muted.ts @@ -0,0 +1,17 @@ +import {AppBskyActorDefs} from '@atproto/api' + +export function isBlockedOrBlocking( + profile: + | AppBskyActorDefs.ProfileViewBasic + | AppBskyActorDefs.ProfileViewDetailed, +) { + return profile.viewer?.blockedBy || profile.viewer?.blocking +} + +export function isMuted( + profile: + | AppBskyActorDefs.ProfileViewBasic + | AppBskyActorDefs.ProfileViewDetailed, +) { + return profile.viewer?.muted || profile.viewer?.mutedByList +} diff --git a/src/screens/StarterPack/StarterPackScreen.tsx b/src/screens/StarterPack/StarterPackScreen.tsx index b80687aff3..2b6f673b1f 100644 --- a/src/screens/StarterPack/StarterPackScreen.tsx +++ b/src/screens/StarterPack/StarterPackScreen.tsx @@ -25,6 +25,7 @@ import {logger} from '#/logger' import {useDeleteStarterPackMutation} from '#/state/queries/starter-packs' import {batchedUpdates} from 'lib/batchedUpdates' import {HITSLOP_20} from 'lib/constants' +import {isBlockedOrBlocking, isMuted} from 'lib/moderation/blocked-and-muted' import {makeProfileLink, makeStarterPackLink} from 'lib/routes/links' import {CommonNavigatorParams, NavigationProp} from 'lib/routes/types' import {logEvent} from 'lib/statsig/statsig' @@ -344,7 +345,13 @@ function Header({ list: starterPack.list.uri, }) const dids = list.data.items - .filter(li => !li.subject.viewer?.following) + .filter( + li => + li.subject.did !== currentAccount?.did && + !isBlockedOrBlocking(li.subject) && + !isMuted(li.subject) && + !li.subject.viewer?.following, + ) .map(li => li.subject.did) const followUris = await bulkWriteFollows(agent, dids)