Skip to content

Commit fee2f5d

Browse files
authored
Remove indirection, insert between slices (bluesky-social#6645)
1 parent ba04bb5 commit fee2f5d

File tree

2 files changed

+43
-111
lines changed

2 files changed

+43
-111
lines changed

src/lib/statsig/gates.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ export type Gate =
22
// Keep this alphabetic please.
33
| 'debug_show_feedcontext' // DISABLED DUE TO EME
44
| 'post_feed_lang_window' // DISABLED DUE TO EME
5-
| 'suggested_feeds_interstitial'

src/view/com/posts/Feed.tsx

+43-110
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {useQueryClient} from '@tanstack/react-query'
1616

1717
import {DISCOVER_FEED_URI, KNOWN_SHUTDOWN_FEEDS} from '#/lib/constants'
1818
import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender'
19-
import {logEvent, useGate} from '#/lib/statsig/statsig'
19+
import {logEvent} from '#/lib/statsig/statsig'
2020
import {useTheme} from '#/lib/ThemeContext'
2121
import {logger} from '#/logger'
2222
import {isIOS, isWeb} from '#/platform/detection'
@@ -32,11 +32,7 @@ import {
3232
usePostFeedQuery,
3333
} from '#/state/queries/post-feed'
3434
import {useSession} from '#/state/session'
35-
import {
36-
ProgressGuide,
37-
SuggestedFeeds,
38-
SuggestedFollows,
39-
} from '#/components/FeedInterstitials'
35+
import {ProgressGuide, SuggestedFollows} from '#/components/FeedInterstitials'
4036
import {List, ListRef} from '../util/List'
4137
import {PostFeedLoadingPlaceholder} from '../util/LoadingPlaceholder'
4238
import {LoadMoreRetryBtn} from '../util/LoadMoreRetryBtn'
@@ -84,74 +80,15 @@ type FeedRow =
8480
key: string
8581
uri: string
8682
}
87-
| {
88-
type: 'interstitialFeeds'
89-
key: string
90-
params: {
91-
variant: 'default' | string
92-
}
93-
slot: number
94-
}
9583
| {
9684
type: 'interstitialFollows'
9785
key: string
98-
params: {
99-
variant: 'default' | string
100-
}
101-
slot: number
10286
}
10387
| {
10488
type: 'interstitialProgressGuide'
10589
key: string
106-
params: {
107-
variant: 'default' | string
108-
}
109-
slot: number
11090
}
11191

112-
const feedInterstitialType = 'interstitialFeeds'
113-
const followInterstitialType = 'interstitialFollows'
114-
const progressGuideInterstitialType = 'interstitialProgressGuide'
115-
const interstials: Record<
116-
'following' | 'discover' | 'profile',
117-
(FeedRow & {
118-
type:
119-
| 'interstitialFeeds'
120-
| 'interstitialFollows'
121-
| 'interstitialProgressGuide'
122-
})[]
123-
> = {
124-
following: [],
125-
discover: [
126-
{
127-
type: progressGuideInterstitialType,
128-
params: {
129-
variant: 'default',
130-
},
131-
key: progressGuideInterstitialType,
132-
slot: 0,
133-
},
134-
{
135-
type: followInterstitialType,
136-
params: {
137-
variant: 'default',
138-
},
139-
key: followInterstitialType,
140-
slot: 20,
141-
},
142-
],
143-
profile: [
144-
{
145-
type: followInterstitialType,
146-
params: {
147-
variant: 'default',
148-
},
149-
key: followInterstitialType,
150-
slot: 5,
151-
},
152-
],
153-
}
154-
15592
export function getFeedPostSlice(feedRow: FeedRow): FeedPostSlice | null {
15693
if (feedRow.type === 'sliceItem') {
15794
return feedRow.slice
@@ -217,7 +154,6 @@ let Feed = ({
217154
const checkForNewRef = React.useRef<(() => void) | null>(null)
218155
const lastFetchRef = React.useRef<number>(Date.now())
219156
const [feedType, feedUri, feedTab] = feed.split('|')
220-
const gate = useGate()
221157

222158
const opts = React.useMemo(
223159
() => ({enabled, ignoreFilterFor}),
@@ -317,6 +253,19 @@ let Feed = ({
317253
}, [pollInterval])
318254

319255
const feedItems: FeedRow[] = React.useMemo(() => {
256+
let feedKind: 'following' | 'discover' | 'profile' | undefined
257+
if (feedType === 'following') {
258+
feedKind = 'following'
259+
} else if (feedUri === DISCOVER_FEED_URI) {
260+
feedKind = 'discover'
261+
} else if (
262+
feedType === 'author' &&
263+
(feedTab === 'posts_and_author_threads' ||
264+
feedTab === 'posts_with_replies')
265+
) {
266+
feedKind = 'profile'
267+
}
268+
320269
let arr: FeedRow[] = []
321270
if (KNOWN_SHUTDOWN_FEEDS.includes(feedUri)) {
322271
arr.push({
@@ -336,8 +285,34 @@ let Feed = ({
336285
key: 'empty',
337286
})
338287
} else if (data) {
288+
let sliceIndex = -1
339289
for (const page of data?.pages) {
340290
for (const slice of page.slices) {
291+
sliceIndex++
292+
293+
if (hasSession) {
294+
if (feedKind === 'discover') {
295+
if (sliceIndex === 0) {
296+
arr.push({
297+
type: 'interstitialProgressGuide',
298+
key: 'interstitial-' + sliceIndex + '-' + lastFetchedAt,
299+
})
300+
} else if (sliceIndex === 20) {
301+
arr.push({
302+
type: 'interstitialFollows',
303+
key: 'interstitial-' + sliceIndex + '-' + lastFetchedAt,
304+
})
305+
}
306+
} else if (feedKind === 'profile') {
307+
if (sliceIndex === 5) {
308+
arr.push({
309+
type: 'interstitialFollows',
310+
key: 'interstitial-' + sliceIndex + '-' + lastFetchedAt,
311+
})
312+
}
313+
}
314+
}
315+
341316
if (slice.isIncompleteThread && slice.items.length >= 3) {
342317
const beforeLast = slice.items.length - 2
343318
const last = slice.items.length - 1
@@ -396,45 +371,6 @@ let Feed = ({
396371
})
397372
}
398373

399-
if (hasSession) {
400-
let feedKind: 'following' | 'discover' | 'profile' | undefined
401-
if (feedType === 'following') {
402-
feedKind = 'following'
403-
} else if (feedUri === DISCOVER_FEED_URI) {
404-
feedKind = 'discover'
405-
} else if (
406-
feedType === 'author' &&
407-
(feedTab === 'posts_and_author_threads' ||
408-
feedTab === 'posts_with_replies')
409-
) {
410-
feedKind = 'profile'
411-
}
412-
413-
if (feedKind) {
414-
for (const interstitial of interstials[feedKind]) {
415-
const shouldShow =
416-
(interstitial.type === feedInterstitialType &&
417-
gate('suggested_feeds_interstitial')) ||
418-
interstitial.type === followInterstitialType ||
419-
interstitial.type === progressGuideInterstitialType
420-
421-
if (shouldShow) {
422-
const variant = 'default' // replace with experiment variant
423-
const int = {
424-
...interstitial,
425-
params: {variant},
426-
// overwrite key with unique value
427-
key: [interstitial.type, variant, lastFetchedAt].join(':'),
428-
}
429-
430-
if (arr.length > interstitial.slot) {
431-
arr.splice(interstitial.slot, 0, int)
432-
}
433-
}
434-
}
435-
}
436-
}
437-
438374
return arr
439375
}, [
440376
isFetched,
@@ -445,7 +381,6 @@ let Feed = ({
445381
feedType,
446382
feedUri,
447383
feedTab,
448-
gate,
449384
hasSession,
450385
])
451386

@@ -529,11 +464,9 @@ let Feed = ({
529464
return <PostFeedLoadingPlaceholder />
530465
} else if (row.type === 'feedShutdownMsg') {
531466
return <FeedShutdownMsg feedUri={feedUri} />
532-
} else if (row.type === feedInterstitialType) {
533-
return <SuggestedFeeds />
534-
} else if (row.type === followInterstitialType) {
467+
} else if (row.type === 'interstitialFollows') {
535468
return <SuggestedFollows feed={feed} />
536-
} else if (row.type === progressGuideInterstitialType) {
469+
} else if (row.type === 'interstitialProgressGuide') {
537470
return <ProgressGuide />
538471
} else if (row.type === 'sliceItem') {
539472
const slice = row.slice

0 commit comments

Comments
 (0)