queries: make getFeed accept a pubkey instead of event3

This commit is contained in:
Alex Gleason 2023-08-17 13:15:47 -05:00
parent 870a6f5261
commit 5a27d791e3
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 6 additions and 8 deletions

View File

@ -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([]);
}

View File

@ -24,7 +24,10 @@ const getFollows = async (pubkey: string): Promise<Event<3> | undefined> => {
};
/** Get events from people the user follows. */
async function getFeed(event3: Event<3>, params: PaginationParams): Promise<Event<1>[]> {
async function getFeed(pubkey: string, params: PaginationParams): Promise<Event<1>[]> {
const event3 = await getFollows(pubkey);
if (!event3) return [];
const authors = event3.tags
.filter((tag) => tag[0] === 'p')
.map((tag) => tag[1]);