diff --git a/src/db/events.ts b/src/db/events.ts index 50f1379..96f4277 100644 --- a/src/db/events.ts +++ b/src/db/events.ts @@ -90,7 +90,8 @@ function getFilter(filter: Filter): Promise([filter]); } -async function isFollowed({ pubkey }: SignedEvent): Promise { +/** Returns whether the pubkey is followed by a local user. */ +async function isLocallyFollowed(pubkey: string): Promise { const event = await getFilterQuery({ kinds: [3], '#p': [pubkey], limit: 1 }) .innerJoin('users', 'users.pubkey', 'events.pubkey') .executeTakeFirst(); @@ -98,4 +99,4 @@ async function isFollowed({ pubkey }: SignedEvent): Promise { return !!event; } -export { getFilter, getFilters, insertEvent, isFollowed }; +export { getFilter, getFilters, insertEvent, isLocallyFollowed }; diff --git a/src/loopback.ts b/src/loopback.ts index 7cd8fa2..4cb45e1 100644 --- a/src/loopback.ts +++ b/src/loopback.ts @@ -1,5 +1,5 @@ import { Conf } from '@/config.ts'; -import { insertEvent } from '@/db/events.ts'; +import { insertEvent, isLocallyFollowed } from '@/db/events.ts'; import { RelayPool } from '@/deps.ts'; import { trends } from '@/trends.ts'; import { nostrDate, nostrNow } from '@/utils.ts'; @@ -20,10 +20,14 @@ relay.subscribe( ); /** Handle events through the loopback pipeline. */ -function handleEvent(event: SignedEvent): void { +async function handleEvent(event: SignedEvent): Promise { console.info('loopback event:', event.id); - insertEvent(event).catch(console.warn); + trackHashtags(event); + + if (await isLocallyFollowed(event.pubkey)) { + insertEvent(event).catch(console.warn); + } } /** Track whenever a hashtag is used, for processing trending tags. */