Move isLocallyFollowed to queries.ts

This commit is contained in:
Alex Gleason 2023-08-17 19:32:05 -05:00
parent 2011ca6e1d
commit dc49c305bd
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 12 additions and 17 deletions

View File

@ -119,16 +119,4 @@ async function getFilters<K extends number>(
));
}
/** Returns whether the pubkey is followed by a local user. */
async function isLocallyFollowed(pubkey: string): Promise<boolean> {
return Boolean(
await getFilterQuery({
kinds: [3],
'#p': [pubkey],
limit: 1,
local: true,
}).executeTakeFirst(),
);
}
export { getFilters, insertEvent, isLocallyFollowed };
export { getFilters, insertEvent };

View File

@ -2,6 +2,7 @@ import * as eventsDB from '@/db/events.ts';
import { addRelays } from '@/db/relays.ts';
import { findUser } from '@/db/users.ts';
import { type Event } from '@/deps.ts';
import { isLocallyFollowed } from '@/queries.ts';
import { trends } from '@/trends.ts';
import { isRelay, nostrDate } from '@/utils.ts';
@ -19,7 +20,7 @@ async function handleEvent(event: Event): Promise<void> {
/** Maybe store the event, if eligible. */
async function storeEvent(event: Event): Promise<void> {
if (await findUser({ pubkey: event.pubkey }) || await eventsDB.isLocallyFollowed(event.pubkey)) {
if (await findUser({ pubkey: event.pubkey }) || await isLocallyFollowed(event.pubkey)) {
await eventsDB.insertEvent(event).catch(console.warn);
}
}

View File

@ -1,8 +1,8 @@
import * as eventsDB from '@/db/events.ts';
import { type Event, type Filter, findReplyTag } from '@/deps.ts';
import * as mixer from '@/mixer.ts';
import { type PaginationParams } from '@/utils.ts';
import * as mixer from './mixer.ts';
interface GetEventOpts<K extends number> {
/** Timeout in milliseconds. */
timeout?: number;
@ -83,4 +83,10 @@ function getDescendants(eventId: string): Promise<Event<1>[]> {
return mixer.getFilters([{ kinds: [1], '#e': [eventId] }], { limit: 200, timeout: 2000 });
}
export { getAncestors, getAuthor, getDescendants, getEvent, getFeed, getFollows, getPublicFeed };
/** Returns whether the pubkey is followed by a local user. */
async function isLocallyFollowed(pubkey: string): Promise<boolean> {
const [event] = await eventsDB.getFilters([{ kinds: [3], '#p': [pubkey], local: true }], { limit: 1 });
return Boolean(event);
}
export { getAncestors, getAuthor, getDescendants, getEvent, getFeed, getFollows, getPublicFeed, isLocallyFollowed };