De-closure my-follows
This commit is contained in:
@@ -31,9 +31,9 @@ const SANITY_PAGE_LIMIT = 1000
|
||||
const PAGE_SIZE = 100
|
||||
// ...which comes 100,000k list members
|
||||
|
||||
export const RQKEY = (userDid: string | undefined) => [
|
||||
export const RQKEY = (sessionDid: string | undefined) => [
|
||||
'list-memberships',
|
||||
userDid,
|
||||
sessionDid,
|
||||
]
|
||||
|
||||
export interface ListMembersip {
|
||||
@@ -57,15 +57,15 @@ export function useDangerousListMembershipsQuery() {
|
||||
async function dangerousListMembershipsQueryFn({
|
||||
queryKey,
|
||||
}: QueryFunctionContext) {
|
||||
const [_, userDid] = queryKey as ReturnType<typeof RQKEY>
|
||||
if (!userDid) {
|
||||
const [_, sessionDid] = queryKey as ReturnType<typeof RQKEY>
|
||||
if (!sessionDid) {
|
||||
return []
|
||||
}
|
||||
let cursor
|
||||
let arr: ListMembersip[] = []
|
||||
for (let i = 0; i < SANITY_PAGE_LIMIT; i++) {
|
||||
const res = await getAgent().app.bsky.graph.listitem.list({
|
||||
repo: userDid,
|
||||
repo: sessionDid,
|
||||
limit: PAGE_SIZE,
|
||||
cursor,
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {AppBskyActorDefs} from '@atproto/api'
|
||||
import {useQuery} from '@tanstack/react-query'
|
||||
import {QueryFunctionContext, useQuery} from '@tanstack/react-query'
|
||||
import {useSession, getAgent} from '../session'
|
||||
import {STALE} from '#/state/queries'
|
||||
|
||||
@@ -8,38 +8,44 @@ const SANITY_PAGE_LIMIT = 1000
|
||||
const PAGE_SIZE = 100
|
||||
// ...which comes 10,000k follows
|
||||
|
||||
export const RQKEY = () => ['my-follows']
|
||||
export const RQKEY = (sessionDid: string | undefined) => [
|
||||
'my-follows',
|
||||
sessionDid,
|
||||
]
|
||||
|
||||
export function useMyFollowsQuery() {
|
||||
const {currentAccount} = useSession()
|
||||
return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(),
|
||||
async queryFn() {
|
||||
if (!currentAccount) {
|
||||
return []
|
||||
}
|
||||
let cursor
|
||||
let arr: AppBskyActorDefs.ProfileViewBasic[] = []
|
||||
for (let i = 0; i < SANITY_PAGE_LIMIT; i++) {
|
||||
const res = await getAgent().getFollows({
|
||||
actor: currentAccount.did,
|
||||
cursor,
|
||||
limit: PAGE_SIZE,
|
||||
})
|
||||
// TODO
|
||||
// res.data.follows = res.data.follows.filter(
|
||||
// profile =>
|
||||
// !moderateProfile(profile, this.rootStore.preferences.moderationOpts)
|
||||
// .account.filter,
|
||||
// )
|
||||
arr = arr.concat(res.data.follows)
|
||||
if (!res.data.cursor) {
|
||||
break
|
||||
}
|
||||
cursor = res.data.cursor
|
||||
}
|
||||
return arr
|
||||
},
|
||||
queryKey: RQKEY(currentAccount?.did),
|
||||
queryFn: myFollowsQueryFn,
|
||||
})
|
||||
}
|
||||
|
||||
async function myFollowsQueryFn({queryKey}: QueryFunctionContext) {
|
||||
const [_, sessionDid] = queryKey as ReturnType<typeof RQKEY>
|
||||
if (!sessionDid) {
|
||||
return []
|
||||
}
|
||||
let cursor
|
||||
let arr: AppBskyActorDefs.ProfileViewBasic[] = []
|
||||
for (let i = 0; i < SANITY_PAGE_LIMIT; i++) {
|
||||
const res = await getAgent().getFollows({
|
||||
actor: sessionDid,
|
||||
cursor,
|
||||
limit: PAGE_SIZE,
|
||||
})
|
||||
// TODO
|
||||
// res.data.follows = res.data.follows.filter(
|
||||
// profile =>
|
||||
// !moderateProfile(profile, this.rootStore.preferences.moderationOpts)
|
||||
// .account.filter,
|
||||
// )
|
||||
arr = arr.concat(res.data.follows)
|
||||
if (!res.data.cursor) {
|
||||
break
|
||||
}
|
||||
cursor = res.data.cursor
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user