migrate the custom, merge and home feed apis to the appview client
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+45
-43
@@ -1,46 +1,46 @@
|
|||||||
import {
|
import {type AppBskyFeedDefs, AtpAgent, jsonStringToLex} from '@atproto/api'
|
||||||
type AppBskyFeedDefs,
|
import {type Client, type XrpcRequestParams} from '@atproto/lex'
|
||||||
type AppBskyFeedGetFeed as GetCustomFeed,
|
|
||||||
AtpAgent,
|
|
||||||
jsonStringToLex,
|
|
||||||
} from '@atproto/api'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getAppLanguageAsContentLanguage,
|
getAppLanguageAsContentLanguage,
|
||||||
getContentLanguages,
|
getContentLanguages,
|
||||||
} from '#/state/preferences/languages'
|
} from '#/state/preferences/languages'
|
||||||
|
import {app} from '#/lexicons'
|
||||||
import {type FeedAPI, type FeedAPIResponse} from './types'
|
import {type FeedAPI, type FeedAPIResponse} from './types'
|
||||||
import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils'
|
import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils'
|
||||||
|
|
||||||
|
type GetCustomFeedParams = XrpcRequestParams<typeof app.bsky.feed.getFeed.main>
|
||||||
|
|
||||||
export class CustomFeedAPI implements FeedAPI {
|
export class CustomFeedAPI implements FeedAPI {
|
||||||
agent: AtpAgent
|
client: Client
|
||||||
params: GetCustomFeed.QueryParams
|
params: GetCustomFeedParams
|
||||||
userInterests?: string
|
userInterests?: string
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
agent,
|
client,
|
||||||
feedParams,
|
feedParams,
|
||||||
userInterests,
|
userInterests,
|
||||||
}: {
|
}: {
|
||||||
agent: AtpAgent
|
client: Client
|
||||||
feedParams: GetCustomFeed.QueryParams
|
feedParams: GetCustomFeedParams
|
||||||
userInterests?: string
|
userInterests?: string
|
||||||
}) {
|
}) {
|
||||||
this.agent = agent
|
this.client = client
|
||||||
this.params = feedParams
|
this.params = feedParams
|
||||||
this.userInterests = userInterests
|
this.userInterests = userInterests
|
||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||||
const contentLangs = getContentLanguages().join(',')
|
const contentLangs = getContentLanguages().join(',')
|
||||||
const res = await this.agent.app.bsky.feed.getFeed(
|
const data = await this.client.call(
|
||||||
|
app.bsky.feed.getFeed,
|
||||||
{
|
{
|
||||||
...this.params,
|
...this.params,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
},
|
},
|
||||||
{headers: {'Accept-Language': contentLangs}},
|
{headers: {'Accept-Language': contentLangs}},
|
||||||
)
|
)
|
||||||
return res.data.feed[0]
|
return data.feed[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetch({
|
async fetch({
|
||||||
@@ -51,11 +51,17 @@ export class CustomFeedAPI implements FeedAPI {
|
|||||||
limit: number
|
limit: number
|
||||||
}): Promise<FeedAPIResponse> {
|
}): Promise<FeedAPIResponse> {
|
||||||
const contentLangs = getContentLanguages().join(',')
|
const contentLangs = getContentLanguages().join(',')
|
||||||
const agent = this.agent
|
|
||||||
const isBlueskyOwned = isBlueskyOwnedFeed(this.params.feed)
|
const isBlueskyOwned = isBlueskyOwnedFeed(this.params.feed)
|
||||||
|
|
||||||
const res = agent.did
|
/*
|
||||||
? await this.agent.app.bsky.feed.getFeed(
|
* The authed branch rejects on failure, so the error propagates to the
|
||||||
|
* query and drives the feed error UI (feedgen offline, misconfigured, rate
|
||||||
|
* limited). Only the logged-out branch can resolve without data, and it
|
||||||
|
* signals that with a null body.
|
||||||
|
*/
|
||||||
|
const data = this.client.did
|
||||||
|
? await this.client.call(
|
||||||
|
app.bsky.feed.getFeed,
|
||||||
{
|
{
|
||||||
...this.params,
|
...this.params,
|
||||||
cursor,
|
cursor,
|
||||||
@@ -71,21 +77,22 @@ export class CustomFeedAPI implements FeedAPI {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
: await loggedOutFetch({...this.params, cursor, limit})
|
: await loggedOutFetch({...this.params, cursor, limit})
|
||||||
if (res.success) {
|
|
||||||
// NOTE
|
if (!data) {
|
||||||
// some custom feeds fail to enforce the pagination limit
|
|
||||||
// so we manually truncate here
|
|
||||||
// -prf
|
|
||||||
if (res.data.feed.length > limit) {
|
|
||||||
res.data.feed = res.data.feed.slice(0, limit)
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
cursor: res.data.feed.length ? res.data.cursor : undefined,
|
feed: [],
|
||||||
feed: res.data.feed,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE
|
||||||
|
// some custom feeds fail to enforce the pagination limit
|
||||||
|
// so we manually truncate here
|
||||||
|
// -prf
|
||||||
|
const feed =
|
||||||
|
data.feed.length > limit ? data.feed.slice(0, limit) : data.feed
|
||||||
return {
|
return {
|
||||||
feed: [],
|
cursor: feed.length ? data.cursor : undefined,
|
||||||
|
feed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,7 +112,7 @@ async function loggedOutFetch({
|
|||||||
feed: string
|
feed: string
|
||||||
limit: number
|
limit: number
|
||||||
cursor?: string
|
cursor?: string
|
||||||
}) {
|
}): Promise<app.bsky.feed.getFeed.$OutputBody | null> {
|
||||||
let contentLangs = getAppLanguageAsContentLanguage()
|
let contentLangs = getAppLanguageAsContentLanguage()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,14 +135,15 @@ async function loggedOutFetch({
|
|||||||
headers: {'Accept-Language': contentLangs, ...labelersHeader},
|
headers: {'Accept-Language': contentLangs, ...labelersHeader},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
/*
|
||||||
|
* The response is hand-decoded rather than validated, so the lex output shape
|
||||||
|
* is asserted here just as the old-world one was.
|
||||||
|
*/
|
||||||
let data = res.ok
|
let data = res.ok
|
||||||
? (jsonStringToLex(await res.text()) as GetCustomFeed.OutputSchema)
|
? (jsonStringToLex(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
|
||||||
: null
|
: null
|
||||||
if (data?.feed?.length) {
|
if (data?.feed?.length) {
|
||||||
return {
|
return data
|
||||||
success: true,
|
|
||||||
data,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// no data, try again with language headers removed
|
// no data, try again with language headers removed
|
||||||
@@ -146,17 +154,11 @@ async function loggedOutFetch({
|
|||||||
{method: 'GET', headers: {'Accept-Language': '', ...labelersHeader}},
|
{method: 'GET', headers: {'Accept-Language': '', ...labelersHeader}},
|
||||||
)
|
)
|
||||||
data = res.ok
|
data = res.ok
|
||||||
? (jsonStringToLex(await res.text()) as GetCustomFeed.OutputSchema)
|
? (jsonStringToLex(await res.text()) as app.bsky.feed.getFeed.$OutputBody)
|
||||||
: null
|
: null
|
||||||
if (data?.feed?.length) {
|
if (data?.feed?.length) {
|
||||||
return {
|
return data
|
||||||
success: true,
|
|
||||||
data,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return null
|
||||||
success: false,
|
|
||||||
data: {feed: []},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-11
@@ -1,4 +1,6 @@
|
|||||||
import {type AppBskyFeedDefs, type AtpAgent} from '@atproto/api'
|
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||||
|
import {type Client} from '@atproto/lex'
|
||||||
|
import {type AtUriString} from '@atproto/syntax'
|
||||||
|
|
||||||
import {PROD_DEFAULT_FEED} from '#/lib/constants'
|
import {PROD_DEFAULT_FEED} from '#/lib/constants'
|
||||||
import {CustomFeedAPI} from './custom'
|
import {CustomFeedAPI} from './custom'
|
||||||
@@ -27,7 +29,7 @@ export const FALLBACK_MARKER_POST: AppBskyFeedDefs.FeedViewPost = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class HomeFeedAPI implements FeedAPI {
|
export class HomeFeedAPI implements FeedAPI {
|
||||||
agent: AtpAgent
|
client: Client
|
||||||
following: FollowingFeedAPI
|
following: FollowingFeedAPI
|
||||||
discover: CustomFeedAPI
|
discover: CustomFeedAPI
|
||||||
usingDiscover = false
|
usingDiscover = false
|
||||||
@@ -36,25 +38,25 @@ export class HomeFeedAPI implements FeedAPI {
|
|||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
userInterests,
|
userInterests,
|
||||||
agent,
|
client,
|
||||||
}: {
|
}: {
|
||||||
userInterests?: string
|
userInterests?: string
|
||||||
agent: AtpAgent
|
client: Client
|
||||||
}) {
|
}) {
|
||||||
this.agent = agent
|
this.client = client
|
||||||
this.following = new FollowingFeedAPI({agent})
|
this.following = new FollowingFeedAPI({client})
|
||||||
this.discover = new CustomFeedAPI({
|
this.discover = new CustomFeedAPI({
|
||||||
agent,
|
client,
|
||||||
feedParams: {feed: PROD_DEFAULT_FEED('whats-hot')},
|
feedParams: {feed: PROD_DEFAULT_FEED('whats-hot') as AtUriString},
|
||||||
})
|
})
|
||||||
this.userInterests = userInterests
|
this.userInterests = userInterests
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.following = new FollowingFeedAPI({agent: this.agent})
|
this.following = new FollowingFeedAPI({client: this.client})
|
||||||
this.discover = new CustomFeedAPI({
|
this.discover = new CustomFeedAPI({
|
||||||
agent: this.agent,
|
client: this.client,
|
||||||
feedParams: {feed: PROD_DEFAULT_FEED('whats-hot')},
|
feedParams: {feed: PROD_DEFAULT_FEED('whats-hot') as AtUriString},
|
||||||
userInterests: this.userInterests,
|
userInterests: this.userInterests,
|
||||||
})
|
})
|
||||||
this.usingDiscover = false
|
this.usingDiscover = false
|
||||||
|
|||||||
+65
-46
@@ -1,8 +1,6 @@
|
|||||||
import {
|
import {type AppBskyFeedDefs} from '@atproto/api'
|
||||||
type AppBskyFeedDefs,
|
import {type Client} from '@atproto/lex'
|
||||||
type AppBskyFeedGetTimeline,
|
import {type AtUriString} from '@atproto/syntax'
|
||||||
type AtpAgent,
|
|
||||||
} from '@atproto/api'
|
|
||||||
import shuffle from 'lodash.shuffle'
|
import shuffle from 'lodash.shuffle'
|
||||||
|
|
||||||
import {bundleAsync} from '#/lib/async/bundle'
|
import {bundleAsync} from '#/lib/async/bundle'
|
||||||
@@ -10,6 +8,7 @@ import {timeout} from '#/lib/async/timeout'
|
|||||||
import {feedUriToHref} from '#/lib/strings/url-helpers'
|
import {feedUriToHref} from '#/lib/strings/url-helpers'
|
||||||
import {getContentLanguages} from '#/state/preferences/languages'
|
import {getContentLanguages} from '#/state/preferences/languages'
|
||||||
import {type FeedParams} from '#/state/queries/post-feed'
|
import {type FeedParams} from '#/state/queries/post-feed'
|
||||||
|
import {app} from '#/lexicons'
|
||||||
import {FeedTuner} from '../feed-manip'
|
import {FeedTuner} from '../feed-manip'
|
||||||
import {type FeedTunerFn} from '../feed-manip'
|
import {type FeedTunerFn} from '../feed-manip'
|
||||||
import {
|
import {
|
||||||
@@ -22,9 +21,19 @@ import {createBskyTopicsHeader, isBlueskyOwnedFeed} from './utils'
|
|||||||
const REQUEST_WAIT_MS = 500 // 500ms
|
const REQUEST_WAIT_MS = 500 // 500ms
|
||||||
const POST_AGE_CUTOFF = 60e3 * 60 * 24 // 24hours
|
const POST_AGE_CUTOFF = 60e3 * 60 * 24 // 24hours
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A page of feed items, or `null` when the source could not produce one. Only
|
||||||
|
* sources that deliberately swallow their own errors return `null`; the rest
|
||||||
|
* reject so the error reaches the caller.
|
||||||
|
*/
|
||||||
|
type MergeFeedPage = {
|
||||||
|
cursor?: string
|
||||||
|
feed: AppBskyFeedDefs.FeedViewPost[]
|
||||||
|
} | null
|
||||||
|
|
||||||
export class MergeFeedAPI implements FeedAPI {
|
export class MergeFeedAPI implements FeedAPI {
|
||||||
userInterests?: string
|
userInterests?: string
|
||||||
agent: AtpAgent
|
client: Client
|
||||||
params: FeedParams
|
params: FeedParams
|
||||||
feedTuners: FeedTunerFn[]
|
feedTuners: FeedTunerFn[]
|
||||||
following: MergeFeedSource_Following
|
following: MergeFeedSource_Following
|
||||||
@@ -34,29 +43,29 @@ export class MergeFeedAPI implements FeedAPI {
|
|||||||
sampleCursor = 0
|
sampleCursor = 0
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
agent,
|
client,
|
||||||
feedParams,
|
feedParams,
|
||||||
feedTuners,
|
feedTuners,
|
||||||
userInterests,
|
userInterests,
|
||||||
}: {
|
}: {
|
||||||
agent: AtpAgent
|
client: Client
|
||||||
feedParams: FeedParams
|
feedParams: FeedParams
|
||||||
feedTuners: FeedTunerFn[]
|
feedTuners: FeedTunerFn[]
|
||||||
userInterests?: string
|
userInterests?: string
|
||||||
}) {
|
}) {
|
||||||
this.agent = agent
|
this.client = client
|
||||||
this.params = feedParams
|
this.params = feedParams
|
||||||
this.feedTuners = feedTuners
|
this.feedTuners = feedTuners
|
||||||
this.userInterests = userInterests
|
this.userInterests = userInterests
|
||||||
this.following = new MergeFeedSource_Following({
|
this.following = new MergeFeedSource_Following({
|
||||||
agent: this.agent,
|
client: this.client,
|
||||||
feedTuners: this.feedTuners,
|
feedTuners: this.feedTuners,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.following = new MergeFeedSource_Following({
|
this.following = new MergeFeedSource_Following({
|
||||||
agent: this.agent,
|
client: this.client,
|
||||||
feedTuners: this.feedTuners,
|
feedTuners: this.feedTuners,
|
||||||
})
|
})
|
||||||
this.customFeeds = []
|
this.customFeeds = []
|
||||||
@@ -68,7 +77,7 @@ export class MergeFeedAPI implements FeedAPI {
|
|||||||
this.params.mergeFeedSources.map(
|
this.params.mergeFeedSources.map(
|
||||||
feedUri =>
|
feedUri =>
|
||||||
new MergeFeedSource_Custom({
|
new MergeFeedSource_Custom({
|
||||||
agent: this.agent,
|
client: this.client,
|
||||||
feedUri,
|
feedUri,
|
||||||
feedTuners: this.feedTuners,
|
feedTuners: this.feedTuners,
|
||||||
userInterests: this.userInterests,
|
userInterests: this.userInterests,
|
||||||
@@ -81,10 +90,10 @@ export class MergeFeedAPI implements FeedAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
|
||||||
const res = await this.agent.getTimeline({
|
const data = await this.client.call(app.bsky.feed.getTimeline, {
|
||||||
limit: 1,
|
limit: 1,
|
||||||
})
|
})
|
||||||
return res.data.feed[0]
|
return data.feed[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetch({
|
async fetch({
|
||||||
@@ -175,7 +184,7 @@ export class MergeFeedAPI implements FeedAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MergeFeedSource {
|
class MergeFeedSource {
|
||||||
agent: AtpAgent
|
client: Client
|
||||||
feedTuners: FeedTunerFn[]
|
feedTuners: FeedTunerFn[]
|
||||||
sourceInfo: ReasonFeedSource | undefined
|
sourceInfo: ReasonFeedSource | undefined
|
||||||
cursor: string | undefined = undefined
|
cursor: string | undefined = undefined
|
||||||
@@ -183,13 +192,13 @@ class MergeFeedSource {
|
|||||||
hasMore = true
|
hasMore = true
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
agent,
|
client,
|
||||||
feedTuners,
|
feedTuners,
|
||||||
}: {
|
}: {
|
||||||
agent: AtpAgent
|
client: Client
|
||||||
feedTuners: FeedTunerFn[]
|
feedTuners: FeedTunerFn[]
|
||||||
}) {
|
}) {
|
||||||
this.agent = agent
|
this.client = client
|
||||||
this.feedTuners = feedTuners
|
this.feedTuners = feedTuners
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,11 +219,11 @@ class MergeFeedSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_fetchNextInner = bundleAsync(async (n: number) => {
|
_fetchNextInner = bundleAsync(async (n: number) => {
|
||||||
const res = await this._getFeed(this.cursor, n)
|
const page = await this._getFeed(this.cursor, n)
|
||||||
if (res.success) {
|
if (page) {
|
||||||
this.cursor = res.data.cursor
|
this.cursor = page.cursor
|
||||||
if (res.data.feed.length) {
|
if (page.feed.length) {
|
||||||
this.queue = this.queue.concat(res.data.feed)
|
this.queue = this.queue.concat(page.feed)
|
||||||
} else {
|
} else {
|
||||||
this.hasMore = false
|
this.hasMore = false
|
||||||
}
|
}
|
||||||
@@ -226,7 +235,7 @@ class MergeFeedSource {
|
|||||||
protected _getFeed(
|
protected _getFeed(
|
||||||
_cursor: string | undefined,
|
_cursor: string | undefined,
|
||||||
_limit: number,
|
_limit: number,
|
||||||
): Promise<AppBskyFeedGetTimeline.Response> {
|
): Promise<MergeFeedPage> {
|
||||||
throw new Error('Must be overridden')
|
throw new Error('Must be overridden')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,42 +247,49 @@ class MergeFeedSource_Following extends MergeFeedSource {
|
|||||||
return this._fetchNextInner(n)
|
return this._fetchNextInner(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* No error handling: a failed timeline read rejects, which is what the agent
|
||||||
|
* did too, so the error still reaches `MergeFeedAPI.fetch` and the query.
|
||||||
|
*/
|
||||||
protected async _getFeed(
|
protected async _getFeed(
|
||||||
cursor: string | undefined,
|
cursor: string | undefined,
|
||||||
limit: number,
|
limit: number,
|
||||||
): Promise<AppBskyFeedGetTimeline.Response> {
|
): Promise<MergeFeedPage> {
|
||||||
const res = await this.agent.getTimeline({cursor, limit})
|
const data = await this.client.call(app.bsky.feed.getTimeline, {
|
||||||
|
cursor,
|
||||||
|
limit,
|
||||||
|
})
|
||||||
// run the tuner pre-emptively to ensure better mixing
|
// run the tuner pre-emptively to ensure better mixing
|
||||||
const slices = this.tuner.tune(res.data.feed, {
|
const slices = this.tuner.tune(data.feed, {
|
||||||
dryRun: false,
|
dryRun: false,
|
||||||
})
|
})
|
||||||
res.data.feed = slices.map(slice => slice._feedPost)
|
return {
|
||||||
return res
|
cursor: data.cursor,
|
||||||
|
feed: slices.map(slice => slice._feedPost),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MergeFeedSource_Custom extends MergeFeedSource {
|
class MergeFeedSource_Custom extends MergeFeedSource {
|
||||||
agent: AtpAgent
|
|
||||||
minDate: Date
|
minDate: Date
|
||||||
feedUri: string
|
feedUri: string
|
||||||
userInterests?: string
|
userInterests?: string
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
agent,
|
client,
|
||||||
feedUri,
|
feedUri,
|
||||||
feedTuners,
|
feedTuners,
|
||||||
userInterests,
|
userInterests,
|
||||||
}: {
|
}: {
|
||||||
agent: AtpAgent
|
client: Client
|
||||||
feedUri: string
|
feedUri: string
|
||||||
feedTuners: FeedTunerFn[]
|
feedTuners: FeedTunerFn[]
|
||||||
userInterests?: string
|
userInterests?: string
|
||||||
}) {
|
}) {
|
||||||
super({
|
super({
|
||||||
agent,
|
client,
|
||||||
feedTuners,
|
feedTuners,
|
||||||
})
|
})
|
||||||
this.agent = agent
|
|
||||||
this.feedUri = feedUri
|
this.feedUri = feedUri
|
||||||
this.userInterests = userInterests
|
this.userInterests = userInterests
|
||||||
this.sourceInfo = {
|
this.sourceInfo = {
|
||||||
@@ -287,15 +303,16 @@ class MergeFeedSource_Custom extends MergeFeedSource {
|
|||||||
protected async _getFeed(
|
protected async _getFeed(
|
||||||
cursor: string | undefined,
|
cursor: string | undefined,
|
||||||
limit: number,
|
limit: number,
|
||||||
): Promise<AppBskyFeedGetTimeline.Response> {
|
): Promise<MergeFeedPage> {
|
||||||
try {
|
try {
|
||||||
const contentLangs = getContentLanguages().join(',')
|
const contentLangs = getContentLanguages().join(',')
|
||||||
const isBlueskyOwned = isBlueskyOwnedFeed(this.feedUri)
|
const isBlueskyOwned = isBlueskyOwnedFeed(this.feedUri)
|
||||||
const res = await this.agent.app.bsky.feed.getFeed(
|
const data = await this.client.call(
|
||||||
|
app.bsky.feed.getFeed,
|
||||||
{
|
{
|
||||||
cursor,
|
cursor,
|
||||||
limit,
|
limit,
|
||||||
feed: this.feedUri,
|
feed: this.feedUri as AtUriString,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -310,22 +327,24 @@ class MergeFeedSource_Custom extends MergeFeedSource {
|
|||||||
// some custom feeds fail to enforce the pagination limit
|
// some custom feeds fail to enforce the pagination limit
|
||||||
// so we manually truncate here
|
// so we manually truncate here
|
||||||
// -prf
|
// -prf
|
||||||
if (limit && res.data.feed.length > limit) {
|
let feed: AppBskyFeedDefs.FeedViewPost[] =
|
||||||
res.data.feed = res.data.feed.slice(0, limit)
|
limit && data.feed.length > limit
|
||||||
}
|
? data.feed.slice(0, limit)
|
||||||
|
: data.feed
|
||||||
// filter out older posts
|
// filter out older posts
|
||||||
res.data.feed = res.data.feed.filter(
|
feed = feed.filter(post => new Date(post.post.indexedAt) > this.minDate)
|
||||||
post => new Date(post.post.indexedAt) > this.minDate,
|
|
||||||
)
|
|
||||||
// attach source info
|
// attach source info
|
||||||
for (const post of res.data.feed) {
|
for (const post of feed) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
post.__source = this.sourceInfo
|
post.__source = this.sourceInfo
|
||||||
}
|
}
|
||||||
return res
|
return {
|
||||||
|
cursor: data.cursor,
|
||||||
|
feed,
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// dont bubble custom-feed errors
|
// dont bubble custom-feed errors
|
||||||
return {success: false, headers: {}, data: {feed: []}}
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user