From 5118aaf46c583fbe1d0c0170db6e600ebe97ec70 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 29 Apr 2023 15:54:21 -0500 Subject: [PATCH] Rename some client functions --- src/api/accounts.ts | 4 ++-- src/api/home.ts | 6 +++--- src/client.ts | 18 +++++++++--------- src/transmute.ts | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/api/accounts.ts b/src/api/accounts.ts index 2ad24651..520d5247 100644 --- a/src/api/accounts.ts +++ b/src/api/accounts.ts @@ -1,12 +1,12 @@ import { type AppController } from '@/app.ts'; -import { fetchUser } from '../client.ts'; +import { getAuthor } from '../client.ts'; import { toAccount } from '../transmute.ts'; const credentialsController: AppController = async (c) => { const pubkey = c.get('pubkey')!; - const event = await fetchUser(pubkey); + const event = await getAuthor(pubkey); if (event) { return c.json(toAccount(event)); } diff --git a/src/api/home.ts b/src/api/home.ts index fbf096ad..cdc32f2e 100644 --- a/src/api/home.ts +++ b/src/api/home.ts @@ -1,7 +1,7 @@ import { type AppController } from '@/app.ts'; import { z } from '@/deps.ts'; -import { fetchFeed, fetchFollows } from '../client.ts'; +import { getFeed, getFollows } from '../client.ts'; import { toStatus } from '../transmute.ts'; import { LOCAL_DOMAIN } from '../config.ts'; @@ -12,12 +12,12 @@ const homeController: AppController = async (c) => { const pubkey = c.get('pubkey')!; - const follows = await fetchFollows(pubkey); + const follows = await getFollows(pubkey); if (!follows) { return c.json([]); } - const events = await fetchFeed(follows, { since, until }); + const events = await getFeed(follows, { since, until }); const statuses = (await Promise.all(events.map(toStatus))).filter(Boolean); const next = `${LOCAL_DOMAIN}/api/v1/timelines/home?until=${events[events.length - 1].created_at}`; diff --git a/src/client.ts b/src/client.ts index 22081a7b..a2448f7d 100644 --- a/src/client.ts +++ b/src/client.ts @@ -7,21 +7,21 @@ import { eventDateComparator, nostrNow } from './utils.ts'; const pool = new RelayPool(poolRelays); -/** Fetch a Nostr event by its ID. */ -const fetchEvent = async (id: string): Promise => { +/** Get a Nostr event by its ID. */ +const getEvent = async (id: string): Promise => { const event = await (pool.getEventById(id, poolRelays, 0) as Promise); return event?.id === id ? event : null; }; -/** Fetch a Nostr `set_medatadata` event for a user's pubkey. */ -const fetchUser = async (pubkey: string): Promise | null> => { +/** Get a Nostr `set_medatadata` event for a user's pubkey. */ +const getAuthor = async (pubkey: string): Promise | null> => { const author = new Author(pool, poolRelays, pubkey); const event: SignedEvent<0> | null = await new Promise((resolve) => author.metaData(resolve, 0)); return event?.pubkey === pubkey ? event : null; }; -/** Fetch users the given pubkey follows. */ -const fetchFollows = (pubkey: string): Promise | null> => { +/** Get users the given pubkey follows. */ +const getFollows = (pubkey: string): Promise | null> => { return new Promise((resolve) => { pool.subscribe( [{ authors: [pubkey], kinds: [3] }], @@ -41,8 +41,8 @@ interface PaginationParams { limit?: number; } -/** Fetch events from people the user follows. */ -function fetchFeed(event3: Event<3>, params: PaginationParams = {}): Promise[]> { +/** Get events from people the user follows. */ +function getFeed(event3: Event<3>, params: PaginationParams = {}): Promise[]> { const limit = Math.max(params.limit ?? 20, 40); const authors = event3.tags.filter((tag) => tag[0] === 'p').map((tag) => tag[1]); const results: SignedEvent<1>[] = []; @@ -74,4 +74,4 @@ function fetchFeed(event3: Event<3>, params: PaginationParams = {}): Promise) { } async function toMention(tag: string[]) { - const profile = await fetchUser(tag[1]); + const profile = await getAuthor(tag[1]); const account = profile ? toAccount(profile) : undefined; return { @@ -50,7 +50,7 @@ async function toMention(tag: string[]) { } async function toStatus(event: Event<1>) { - const profile = await fetchUser(event.pubkey); + const profile = await getAuthor(event.pubkey); const account = profile ? toAccount(profile) : undefined; if (!account) return;