diff options
Diffstat (limited to 'src/state')
-rw-r--r-- | src/state/modals/index.tsx | 2 | ||||
-rw-r--r-- | src/state/queries/feed.ts | 4 | ||||
-rw-r--r-- | src/state/queries/notifications/util.ts | 47 | ||||
-rw-r--r-- | src/state/queries/post-feed.ts | 13 | ||||
-rw-r--r-- | src/state/queries/profile.ts | 20 |
5 files changed, 72 insertions, 14 deletions
diff --git a/src/state/modals/index.tsx b/src/state/modals/index.tsx index 45856e108..ab710a3d0 100644 --- a/src/state/modals/index.tsx +++ b/src/state/modals/index.tsx @@ -6,7 +6,7 @@ import {Image as RNImage} from 'react-native-image-crop-picker' import {ImageModel} from '#/state/models/media/image' import {GalleryModel} from '#/state/models/media/gallery' import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' -import {EmbedPlayerSource} from '#/lib/strings/embed-player.ts' +import {EmbedPlayerSource} from '#/lib/strings/embed-player' import {ThreadgateSetting} from '../queries/threadgate' export interface ConfirmModal { diff --git a/src/state/queries/feed.ts b/src/state/queries/feed.ts index 4acc7179a..67294ece2 100644 --- a/src/state/queries/feed.ts +++ b/src/state/queries/feed.ts @@ -136,6 +136,10 @@ export function getFeedTypeFromUri(uri: string) { return pathname.includes(feedSourceNSIDs.feed) ? 'feed' : 'list' } +export function getAvatarTypeFromUri(uri: string) { + return getFeedTypeFromUri(uri) === 'feed' ? 'algo' : 'list' +} + export function useFeedSourceInfoQuery({uri}: {uri: string}) { const type = getFeedTypeFromUri(uri) diff --git a/src/state/queries/notifications/util.ts b/src/state/queries/notifications/util.ts index 411a0f791..e53a07258 100644 --- a/src/state/queries/notifications/util.ts +++ b/src/state/queries/notifications/util.ts @@ -6,6 +6,7 @@ import { AppBskyFeedPost, AppBskyFeedRepost, AppBskyFeedLike, + AppBskyEmbedRecord, } from '@atproto/api' import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped' import chunk from 'lodash.chunk' @@ -110,8 +111,6 @@ function shouldFilterNotif( return true } } - // TODO: thread muting is not being applied - // (this requires fetching the post) return false } @@ -221,10 +220,44 @@ function getSubjectUri( } } -function isThreadMuted(notif: FeedNotification, mutes: string[]): boolean { - if (!notif.subject) { - return false +export function isThreadMuted(notif: FeedNotification, threadMutes: string[]) { + // If there's a subject we want to use that. This will always work on the notifications tab + if (notif.subject) { + const record = notif.subject.record as AppBskyFeedPost.Record + // Check for a quote record + if ( + (record.reply && threadMutes.includes(record.reply.root.uri)) || + (notif.subject.uri && threadMutes.includes(notif.subject.uri)) + ) { + return true + } else if ( + AppBskyEmbedRecord.isMain(record.embed) && + threadMutes.includes(record.embed.record.uri) + ) { + return true + } + } else { + // Otherwise we just do the best that we can + const record = notif.notification.record + if (AppBskyFeedPost.isRecord(record)) { + if (record.reply && threadMutes.includes(record.reply.root.uri)) { + // We can always filter replies + return true + } else if ( + AppBskyEmbedRecord.isMain(record.embed) && + threadMutes.includes(record.embed.record.uri) + ) { + // We can also filter quotes if the quoted post is the root + return true + } + } else if ( + AppBskyFeedRepost.isRecord(record) && + threadMutes.includes(record.subject.uri) + ) { + // Finally we can filter reposts, again if the post is the root + return true + } } - const record = notif.subject.record as AppBskyFeedPost.Record // assured in fetchSubjects() - return mutes.includes(record.reply?.root.uri || notif.subject.uri) + + return false } diff --git a/src/state/queries/post-feed.ts b/src/state/queries/post-feed.ts index 82acf3974..b422fa8fe 100644 --- a/src/state/queries/post-feed.ts +++ b/src/state/queries/post-feed.ts @@ -28,6 +28,7 @@ import {getModerationOpts} from '#/state/queries/preferences/moderation' import {KnownError} from '#/view/com/posts/FeedErrorMessage' import {embedViewRecordToPostView, getEmbeddedPost} from './util' import {useModerationOpts} from './preferences' +import {queryClient} from 'lib/react-query' type ActorDid = string type AuthorFilter = @@ -444,3 +445,15 @@ function assertSomePostsPassModeration(feed: AppBskyFeedDefs.FeedViewPost[]) { throw new Error(KnownError.FeedNSFPublic) } } + +export function resetProfilePostsQueries(did: string, timeout = 0) { + setTimeout(() => { + queryClient.resetQueries({ + predicate: query => + !!( + query.queryKey[0] === 'post-feed' && + (query.queryKey[1] as string)?.includes(did) + ), + }) + }, timeout) +} diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts index 74be99330..affb8295c 100644 --- a/src/state/queries/profile.ts +++ b/src/state/queries/profile.ts @@ -17,6 +17,7 @@ import {updateProfileShadow} from '../cache/profile-shadow' import {uploadBlob} from '#/lib/api' import {until} from '#/lib/async/until' import {Shadow} from '#/state/cache/types' +import {resetProfilePostsQueries} from '#/state/queries/post-feed' import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue' import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts' import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts' @@ -26,16 +27,19 @@ import {track} from '#/lib/analytics/analytics' export const RQKEY = (did: string) => ['profile', did] export const profilesQueryKey = (handles: string[]) => ['profiles', handles] -export function useProfileQuery({did}: {did: string | undefined}) { - const {currentAccount} = useSession() - const isCurrentAccount = did === currentAccount?.did - +export function useProfileQuery({ + did, + staleTime = STALE.SECONDS.FIFTEEN, +}: { + did: string | undefined + staleTime?: number +}) { return useQuery({ // WARNING // this staleTime is load-bearing // if you remove it, the UI infinite-loops // -prf - staleTime: isCurrentAccount ? STALE.SECONDS.THIRTY : STALE.MINUTES.FIVE, + staleTime, refetchOnWindowFocus: true, queryKey: RQKEY(did || ''), queryFn: async () => { @@ -375,8 +379,9 @@ function useProfileBlockMutation() { {subject: did, createdAt: new Date().toISOString()}, ) }, - onSuccess() { + onSuccess(_, {did}) { queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()}) + resetProfilePostsQueries(did, 1000) }, }) } @@ -394,6 +399,9 @@ function useProfileUnblockMutation() { rkey, }) }, + onSuccess(_, {did}) { + resetProfilePostsQueries(did, 1000) + }, }) } |