[Session] Experiment: Don't use withProxy (#4762)

* Reorder statements

* Remove withProxy() usage behind a gate
zio/stable
dan 2024-07-10 00:12:26 +01:00 committed by GitHub
parent ce0bf867ff
commit 9b9e09d002
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 88 additions and 31 deletions

View File

@ -6,6 +6,7 @@ import {useLingui} from '@lingui/react'
import {getLabelingServiceTitle} from '#/lib/moderation' import {getLabelingServiceTitle} from '#/lib/moderation'
import {ReportOption} from '#/lib/moderation/useReportOptions' import {ReportOption} from '#/lib/moderation/useReportOptions'
import {useGate} from '#/lib/statsig/statsig'
import {useAgent} from '#/state/session' import {useAgent} from '#/state/session'
import {CharProgress} from '#/view/com/composer/char-progress/CharProgress' import {CharProgress} from '#/view/com/composer/char-progress/CharProgress'
import * as Toast from '#/view/com/util/Toast' import * as Toast from '#/view/com/util/Toast'
@ -36,6 +37,7 @@ export function SubmitView({
const t = useTheme() const t = useTheme()
const {_} = useLingui() const {_} = useLingui()
const agent = useAgent() const agent = useAgent()
const gate = useGate()
const [details, setDetails] = React.useState<string>('') const [details, setDetails] = React.useState<string>('')
const [submitting, setSubmitting] = React.useState<boolean>(false) const [submitting, setSubmitting] = React.useState<boolean>(false)
const [selectedServices, setSelectedServices] = React.useState<string[]>([ const [selectedServices, setSelectedServices] = React.useState<string[]>([
@ -60,15 +62,29 @@ export function SubmitView({
reason: details, reason: details,
} }
const results = await Promise.all( const results = await Promise.all(
selectedServices.map(did => selectedServices.map(did => {
agent if (gate('session_withproxy_fix')) {
return agent
.createModerationReport(report, {
encoding: 'application/json',
headers: {
'atproto-proxy': `${did}#atproto_labeler`,
},
})
.then(
_ => true,
_ => false,
)
} else {
return agent
.withProxy('atproto_labeler', did) .withProxy('atproto_labeler', did)
.createModerationReport(report) .createModerationReport(report)
.then( .then(
_ => true, _ => true,
_ => false, _ => false,
), )
), }
}),
) )
setSubmitting(false) setSubmitting(false)
@ -92,6 +108,7 @@ export function SubmitView({
onSubmitComplete, onSubmitComplete,
setError, setError,
agent, agent,
gate,
]) ])
return ( return (

View File

@ -7,6 +7,7 @@ import {useMutation} from '@tanstack/react-query'
import {useLabelInfo} from '#/lib/moderation/useLabelInfo' import {useLabelInfo} from '#/lib/moderation/useLabelInfo'
import {makeProfileLink} from '#/lib/routes/links' import {makeProfileLink} from '#/lib/routes/links'
import {useGate} from '#/lib/statsig/statsig'
import {sanitizeHandle} from '#/lib/strings/handles' import {sanitizeHandle} from '#/lib/strings/handles'
import {logger} from '#/logger' import {logger} from '#/logger'
import {useAgent, useSession} from '#/state/session' import {useAgent, useSession} from '#/state/session'
@ -201,12 +202,31 @@ function AppealForm({
const [details, setDetails] = React.useState('') const [details, setDetails] = React.useState('')
const isAccountReport = 'did' in subject const isAccountReport = 'did' in subject
const agent = useAgent() const agent = useAgent()
const gate = useGate()
const {mutate, isPending} = useMutation({ const {mutate, isPending} = useMutation({
mutationFn: async () => { mutationFn: async () => {
const $type = !isAccountReport const $type = !isAccountReport
? 'com.atproto.repo.strongRef' ? 'com.atproto.repo.strongRef'
: 'com.atproto.admin.defs#repoRef' : 'com.atproto.admin.defs#repoRef'
if (gate('session_withproxy_fix')) {
await agent.createModerationReport(
{
reasonType: ComAtprotoModerationDefs.REASONAPPEAL,
subject: {
$type,
...subject,
},
reason: details,
},
{
encoding: 'application/json',
headers: {
'atproto-proxy': `${label.src}#atproto_labeler`,
},
},
)
} else {
await agent await agent
.withProxy('atproto_labeler', label.src) .withProxy('atproto_labeler', label.src)
.createModerationReport({ .createModerationReport({
@ -217,6 +237,7 @@ function AppealForm({
}, },
reason: details, reason: details,
}) })
}
}, },
onError: err => { onError: err => {
logger.error('Failed to submit label appeal', {message: err}) logger.error('Failed to submit label appeal', {message: err})

View File

@ -7,6 +7,7 @@ export type Gate =
| 'new_user_progress_guide' | 'new_user_progress_guide'
| 'onboarding_minimum_interests' | 'onboarding_minimum_interests'
| 'request_notifications_permission_after_onboarding_v2' | 'request_notifications_permission_after_onboarding_v2'
| 'session_withproxy_fix'
| 'show_avi_follow_button' | 'show_avi_follow_button'
| 'show_follow_back_label_v2' | 'show_follow_back_label_v2'
| 'suggested_feeds_interstitial' | 'suggested_feeds_interstitial'

View File

@ -5,6 +5,7 @@ import throttle from 'lodash.throttle'
import {PROD_DEFAULT_FEED} from '#/lib/constants' import {PROD_DEFAULT_FEED} from '#/lib/constants'
import {logEvent} from '#/lib/statsig/statsig' import {logEvent} from '#/lib/statsig/statsig'
import {useGate} from '#/lib/statsig/statsig'
import {logger} from '#/logger' import {logger} from '#/logger'
import {FeedDescriptor, FeedPostSliceItem} from '#/state/queries/post-feed' import {FeedDescriptor, FeedPostSliceItem} from '#/state/queries/post-feed'
import {getFeedPostSlice} from '#/view/com/posts/Feed' import {getFeedPostSlice} from '#/view/com/posts/Feed'
@ -24,6 +25,7 @@ const stateContext = React.createContext<StateContext>({
export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) { export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) {
const agent = useAgent() const agent = useAgent()
const gate = useGate()
const enabled = isDiscoverFeed(feed) && hasSession const enabled = isDiscoverFeed(feed) && hasSession
const queue = React.useRef<Set<string>>(new Set()) const queue = React.useRef<Set<string>>(new Set())
const history = React.useRef< const history = React.useRef<
@ -43,22 +45,38 @@ export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) {
) )
const sendToFeedNoDelay = React.useCallback(() => { const sendToFeedNoDelay = React.useCallback(() => {
const interactions = Array.from(queue.current).map(toInteraction)
queue.current.clear()
// Send to the feed
if (gate('session_withproxy_fix')) {
agent.app.bsky.feed
.sendInteractions(
{interactions},
{
encoding: 'application/json',
headers: {
// TODO when we start sending to other feeds, we need to grab their DID -prf
'atproto-proxy': 'did:web:discover.bsky.app#bsky_fg',
},
},
)
.catch((e: any) => {
logger.warn('Failed to send feed interactions', {error: e})
})
} else {
const proxyAgent = agent.withProxy( const proxyAgent = agent.withProxy(
// @ts-ignore TODO need to update withProxy() to support this key -prf // @ts-ignore TODO need to update withProxy() to support this key -prf
'bsky_fg', 'bsky_fg',
// TODO when we start sending to other feeds, we need to grab their DID -prf // TODO when we start sending to other feeds, we need to grab their DID -prf
'did:web:discover.bsky.app', 'did:web:discover.bsky.app',
) as BskyAgent ) as BskyAgent
const interactions = Array.from(queue.current).map(toInteraction)
queue.current.clear()
// Send to the feed
proxyAgent.app.bsky.feed proxyAgent.app.bsky.feed
.sendInteractions({interactions}) .sendInteractions({interactions})
.catch((e: any) => { .catch((e: any) => {
logger.warn('Failed to send feed interactions', {error: e}) logger.warn('Failed to send feed interactions', {error: e})
}) })
}
// Send to Statsig // Send to Statsig
if (aggregatedStats.current === null) { if (aggregatedStats.current === null) {
@ -66,7 +84,7 @@ export function useFeedFeedback(feed: FeedDescriptor, hasSession: boolean) {
} }
sendOrAggregateInteractionsForStats(aggregatedStats.current, interactions) sendOrAggregateInteractionsForStats(aggregatedStats.current, interactions)
throttledFlushAggregatedStats() throttledFlushAggregatedStats()
}, [agent, throttledFlushAggregatedStats]) }, [agent, gate, throttledFlushAggregatedStats])
const sendToFeed = React.useMemo( const sendToFeed = React.useMemo(
() => () =>