Factor out store from post-feed query (#1888)
parent
06eb8b9a4c
commit
b04748e703
|
@ -11,7 +11,8 @@ import {LikesFeedAPI} from 'lib/api/feed/likes'
|
||||||
import {CustomFeedAPI} from 'lib/api/feed/custom'
|
import {CustomFeedAPI} from 'lib/api/feed/custom'
|
||||||
import {ListFeedAPI} from 'lib/api/feed/list'
|
import {ListFeedAPI} from 'lib/api/feed/list'
|
||||||
import {MergeFeedAPI} from 'lib/api/feed/merge'
|
import {MergeFeedAPI} from 'lib/api/feed/merge'
|
||||||
import {useStores} from '../models/root-store'
|
import {useModerationOpts} from '#/state/queries/preferences'
|
||||||
|
import {logger} from '#/logger'
|
||||||
|
|
||||||
type ActorDid = string
|
type ActorDid = string
|
||||||
type AuthorFilter =
|
type AuthorFilter =
|
||||||
|
@ -66,8 +67,8 @@ export function usePostFeedQuery(
|
||||||
) {
|
) {
|
||||||
const {agent} = useSession()
|
const {agent} = useSession()
|
||||||
const feedTuners = useFeedTuners(feedDesc)
|
const feedTuners = useFeedTuners(feedDesc)
|
||||||
const store = useStores()
|
|
||||||
const enabled = opts?.enabled !== false
|
const enabled = opts?.enabled !== false
|
||||||
|
const moderationOpts = useModerationOpts()
|
||||||
|
|
||||||
const api: FeedAPI = useMemo(() => {
|
const api: FeedAPI = useMemo(() => {
|
||||||
if (feedDesc === 'home') {
|
if (feedDesc === 'home') {
|
||||||
|
@ -100,26 +101,27 @@ export function usePostFeedQuery(
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
console.log('poll')
|
|
||||||
|
logger.debug('usePostFeedQuery: pollLatest')
|
||||||
|
|
||||||
const post = await api.peekLatest()
|
const post = await api.peekLatest()
|
||||||
if (post) {
|
|
||||||
|
if (post && moderationOpts) {
|
||||||
const slices = tuner.tune([post], feedTuners, {
|
const slices = tuner.tune([post], feedTuners, {
|
||||||
dryRun: true,
|
dryRun: true,
|
||||||
maintainOrder: true,
|
maintainOrder: true,
|
||||||
})
|
})
|
||||||
if (slices[0]) {
|
if (slices[0]) {
|
||||||
if (
|
if (
|
||||||
!moderatePost(
|
!moderatePost(slices[0].items[0].post, moderationOpts).content.filter
|
||||||
slices[0].items[0].post,
|
|
||||||
store.preferences.moderationOpts,
|
|
||||||
).content.filter
|
|
||||||
) {
|
) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}, [api, tuner, feedTuners, store.preferences.moderationOpts, enabled])
|
}, [api, tuner, feedTuners, moderationOpts, enabled])
|
||||||
|
|
||||||
const out = useInfiniteQuery<
|
const out = useInfiniteQuery<
|
||||||
FeedPage,
|
FeedPage,
|
||||||
|
|
Loading…
Reference in New Issue