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

@ -23,7 +23,7 @@ const MS_2DAY = MS_1HR * 48
// =
export async function fetchPage({
getAgent,
agent,
cursor,
limit,
queryClient,
@ -31,7 +31,7 @@ export async function fetchPage({
threadMutes,
fetchAdditionalData,
}: {
getAgent: () => BskyAgent
agent: BskyAgent
cursor: string | undefined
limit: number
queryClient: QueryClient
@ -39,7 +39,7 @@ export async function fetchPage({
threadMutes: string[]
fetchAdditionalData: boolean
}): Promise<{page: FeedPage; indexedAt: string | undefined}> {
const res = await getAgent().listNotifications({
const res = await agent.listNotifications({
limit,
cursor,
})
@ -56,7 +56,7 @@ export async function fetchPage({
// we fetch subjects of notifications (usually posts) now instead of lazily
// in the UI to avoid relayouts
if (fetchAdditionalData) {
const subjects = await fetchSubjects(getAgent, notifsGrouped)
const subjects = await fetchSubjects(agent, notifsGrouped)
for (const notif of notifsGrouped) {
if (notif.subjectUri) {
notif.subject = subjects.get(notif.subjectUri)
@ -140,7 +140,7 @@ export function groupNotifications(
}
async function fetchSubjects(
getAgent: () => BskyAgent,
agent: BskyAgent,
groupedNotifs: FeedNotification[],
): Promise<Map<string, AppBskyFeedDefs.PostView>> {
const uris = new Set<string>()
@ -152,9 +152,7 @@ async function fetchSubjects(
const uriChunks = chunk(Array.from(uris), 25)
const postsChunks = await Promise.all(
uriChunks.map(uris =>
getAgent()
.app.bsky.feed.getPosts({uris})
.then(res => res.data.posts),
agent.app.bsky.feed.getPosts({uris}).then(res => res.data.posts),
),
)
const map = new Map<string, AppBskyFeedDefs.PostView>()