Add missing passive feed interactions (#9043)

This commit is contained in:
Samuel Newman
2025-09-15 13:02:37 +03:00
committed by Hailey
parent 1c855603d2
commit 0a6eddb1ab
+11 -42
View File
@@ -28,39 +28,9 @@ import {useAgent} from './session'
export const FEEDBACK_FEEDS = [...PROD_FEEDS, ...STAGING_FEEDS]
export const PASSIVE_FEEDBACK_INTERACTIONS = [
'app.bsky.feed.defs#clickthroughItem',
'app.bsky.feed.defs#clickthroughAuthor',
'app.bsky.feed.defs#clickthroughReposter',
'app.bsky.feed.defs#clickthroughEmbed',
'app.bsky.feed.defs#interactionSeen',
] as const
export type PassiveFeedbackInteraction =
(typeof PASSIVE_FEEDBACK_INTERACTIONS)[number]
export const DIRECT_FEEDBACK_INTERACTIONS = [
'app.bsky.feed.defs#requestLess',
'app.bsky.feed.defs#requestMore',
] as const
export type DirectFeedbackInteraction =
(typeof DIRECT_FEEDBACK_INTERACTIONS)[number]
export const ALL_FEEDBACK_INTERACTIONS = [
...PASSIVE_FEEDBACK_INTERACTIONS,
...DIRECT_FEEDBACK_INTERACTIONS,
] as const
export type FeedbackInteraction = (typeof ALL_FEEDBACK_INTERACTIONS)[number]
export function isFeedbackInteraction(
interactionEvent: string,
): interactionEvent is FeedbackInteraction {
return ALL_FEEDBACK_INTERACTIONS.includes(
interactionEvent as FeedbackInteraction,
)
}
export const DIRECT_FEEDBACK_INTERACTIONS = new Set<
AppBskyFeedDefs.Interaction['event']
>(['app.bsky.feed.defs#requestLess', 'app.bsky.feed.defs#requestMore'])
const logger = Logger.create(Logger.Context.FeedFeedback)
@@ -97,7 +67,6 @@ export function useFeedFeedback(
const proxyDid = feed?.view?.did
const enabled =
Boolean(feed) && Boolean(proxyDid) && acceptsInteractions && hasSession
const enabledInteractions = getEnabledInteractions(enabled, feed, isDiscover)
const queue = useRef<Set<string>>(new Set())
const history = useRef<
@@ -123,8 +92,7 @@ export function useFeedFeedback(
const interactionsToSend = interactions.filter(
interaction =>
interaction.event &&
isFeedbackInteraction(interaction.event) &&
enabledInteractions.includes(interaction.event),
isInteractionAllowed(enabled, feed, interaction.event),
)
if (interactionsToSend.length === 0) {
@@ -158,7 +126,7 @@ export function useFeedFeedback(
)
throttledFlushAggregatedStats()
logger.debug('flushed')
}, [agent, throttledFlushAggregatedStats, proxyDid, enabledInteractions])
}, [agent, throttledFlushAggregatedStats, proxyDid, enabled, feed])
const sendToFeed = useMemo(
() =>
@@ -251,15 +219,16 @@ export function isDiscoverFeed(feed?: FeedDescriptor) {
return !!feed && FEEDBACK_FEEDS.includes(feed)
}
function getEnabledInteractions(
function isInteractionAllowed(
enabled: boolean,
feed: FeedSourceFeedInfo | undefined,
isDiscover: boolean,
): readonly FeedbackInteraction[] {
interaction: AppBskyFeedDefs.Interaction['event'],
) {
if (!enabled || !feed) {
return []
return false
}
return isDiscover ? ALL_FEEDBACK_INTERACTIONS : DIRECT_FEEDBACK_INTERACTIONS
const isDiscover = isDiscoverFeed(feed.feedDescriptor)
return isDiscover ? true : DIRECT_FEEDBACK_INTERACTIONS.has(interaction)
}
function toString(interaction: AppBskyFeedDefs.Interaction): string {