Replace getAgent() with reading agent (#4243)

* Replace getAgent() with agent

* Replace {agent} with agent
This commit is contained in:
dan 2024-05-28 16:37:51 +01:00 committed by GitHub
parent 8a2f43c218
commit 9bd411c151
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
74 changed files with 400 additions and 438 deletions

View file

@ -16,7 +16,7 @@ const POST_AGE_CUTOFF = 60e3 * 60 * 24 // 24hours
export class MergeFeedAPI implements FeedAPI {
userInterests?: string
getAgent: () => BskyAgent
agent: BskyAgent
params: FeedParams
feedTuners: FeedTunerFn[]
following: MergeFeedSource_Following
@ -26,29 +26,29 @@ export class MergeFeedAPI implements FeedAPI {
sampleCursor = 0
constructor({
getAgent,
agent,
feedParams,
feedTuners,
userInterests,
}: {
getAgent: () => BskyAgent
agent: BskyAgent
feedParams: FeedParams
feedTuners: FeedTunerFn[]
userInterests?: string
}) {
this.getAgent = getAgent
this.agent = agent
this.params = feedParams
this.feedTuners = feedTuners
this.userInterests = userInterests
this.following = new MergeFeedSource_Following({
getAgent: this.getAgent,
agent: this.agent,
feedTuners: this.feedTuners,
})
}
reset() {
this.following = new MergeFeedSource_Following({
getAgent: this.getAgent,
agent: this.agent,
feedTuners: this.feedTuners,
})
this.customFeeds = []
@ -60,7 +60,7 @@ export class MergeFeedAPI implements FeedAPI {
this.params.mergeFeedSources.map(
feedUri =>
new MergeFeedSource_Custom({
getAgent: this.getAgent,
agent: this.agent,
feedUri,
feedTuners: this.feedTuners,
userInterests: this.userInterests,
@ -73,7 +73,7 @@ export class MergeFeedAPI implements FeedAPI {
}
async peekLatest(): Promise<AppBskyFeedDefs.FeedViewPost> {
const res = await this.getAgent().getTimeline({
const res = await this.agent.getTimeline({
limit: 1,
})
return res.data.feed[0]
@ -167,7 +167,7 @@ export class MergeFeedAPI implements FeedAPI {
}
class MergeFeedSource {
getAgent: () => BskyAgent
agent: BskyAgent
feedTuners: FeedTunerFn[]
sourceInfo: ReasonFeedSource | undefined
cursor: string | undefined = undefined
@ -175,13 +175,13 @@ class MergeFeedSource {
hasMore = true
constructor({
getAgent,
agent,
feedTuners,
}: {
getAgent: () => BskyAgent
agent: BskyAgent
feedTuners: FeedTunerFn[]
}) {
this.getAgent = getAgent
this.agent = agent
this.feedTuners = feedTuners
}
@ -245,7 +245,7 @@ class MergeFeedSource_Following extends MergeFeedSource {
cursor: string | undefined,
limit: number,
): Promise<AppBskyFeedGetTimeline.Response> {
const res = await this.getAgent().getTimeline({cursor, limit})
const res = await this.agent.getTimeline({cursor, limit})
// run the tuner pre-emptively to ensure better mixing
const slices = this.tuner.tune(res.data.feed, {
dryRun: false,
@ -257,27 +257,27 @@ class MergeFeedSource_Following extends MergeFeedSource {
}
class MergeFeedSource_Custom extends MergeFeedSource {
getAgent: () => BskyAgent
agent: BskyAgent
minDate: Date
feedUri: string
userInterests?: string
constructor({
getAgent,
agent,
feedUri,
feedTuners,
userInterests,
}: {
getAgent: () => BskyAgent
agent: BskyAgent
feedUri: string
feedTuners: FeedTunerFn[]
userInterests?: string
}) {
super({
getAgent,
agent,
feedTuners,
})
this.getAgent = getAgent
this.agent = agent
this.feedUri = feedUri
this.userInterests = userInterests
this.sourceInfo = {
@ -295,7 +295,7 @@ class MergeFeedSource_Custom extends MergeFeedSource {
try {
const contentLangs = getContentLanguages().join(',')
const isBlueskyOwned = isBlueskyOwnedFeed(this.feedUri)
const res = await this.getAgent().app.bsky.feed.getFeed(
const res = await this.agent.app.bsky.feed.getFeed(
{
cursor,
limit,