From 5a27d791e3cbf37dca06026cb37376d1bc322618 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 17 Aug 2023 13:15:47 -0500 Subject: [PATCH] queries: make getFeed accept a pubkey instead of event3 --- src/controllers/api/timelines.ts | 9 ++------- src/queries.ts | 5 ++++- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/controllers/api/timelines.ts b/src/controllers/api/timelines.ts index 5b5fdcdb..82e1cf38 100644 --- a/src/controllers/api/timelines.ts +++ b/src/controllers/api/timelines.ts @@ -1,4 +1,4 @@ -import { getFeed, getFollows, getPublicFeed } from '@/queries.ts'; +import { getFeed, getPublicFeed } from '@/queries.ts'; import { toStatus } from '@/transformers/nostr-to-mastoapi.ts'; import { buildLinkHeader, paginationSchema } from '@/utils.ts'; @@ -8,12 +8,7 @@ const homeController: AppController = async (c) => { const params = paginationSchema.parse(c.req.query()); const pubkey = c.get('pubkey')!; - const follows = await getFollows(pubkey); - if (!follows) { - return c.json([]); - } - - const events = await getFeed(follows, params); + const events = await getFeed(pubkey, params); if (!events.length) { return c.json([]); } diff --git a/src/queries.ts b/src/queries.ts index 0c8cb86c..0734d981 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -24,7 +24,10 @@ const getFollows = async (pubkey: string): Promise | undefined> => { }; /** Get events from people the user follows. */ -async function getFeed(event3: Event<3>, params: PaginationParams): Promise[]> { +async function getFeed(pubkey: string, params: PaginationParams): Promise[]> { + const event3 = await getFollows(pubkey); + if (!event3) return []; + const authors = event3.tags .filter((tag) => tag[0] === 'p') .map((tag) => tag[1]);