Only track events which are locally followed
This commit is contained in:
parent
2d2157293c
commit
3b3947ea61
|
@ -90,7 +90,8 @@ function getFilter<K extends number = number>(filter: Filter<K>): Promise<Signed
|
||||||
return getFilters<K>([filter]);
|
return getFilters<K>([filter]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isFollowed({ pubkey }: SignedEvent): Promise<boolean> {
|
/** Returns whether the pubkey is followed by a local user. */
|
||||||
|
async function isLocallyFollowed(pubkey: string): Promise<boolean> {
|
||||||
const event = await getFilterQuery({ kinds: [3], '#p': [pubkey], limit: 1 })
|
const event = await getFilterQuery({ kinds: [3], '#p': [pubkey], limit: 1 })
|
||||||
.innerJoin('users', 'users.pubkey', 'events.pubkey')
|
.innerJoin('users', 'users.pubkey', 'events.pubkey')
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
@ -98,4 +99,4 @@ async function isFollowed({ pubkey }: SignedEvent): Promise<boolean> {
|
||||||
return !!event;
|
return !!event;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { getFilter, getFilters, insertEvent, isFollowed };
|
export { getFilter, getFilters, insertEvent, isLocallyFollowed };
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { insertEvent } from '@/db/events.ts';
|
import { insertEvent, isLocallyFollowed } from '@/db/events.ts';
|
||||||
import { RelayPool } from '@/deps.ts';
|
import { RelayPool } from '@/deps.ts';
|
||||||
import { trends } from '@/trends.ts';
|
import { trends } from '@/trends.ts';
|
||||||
import { nostrDate, nostrNow } from '@/utils.ts';
|
import { nostrDate, nostrNow } from '@/utils.ts';
|
||||||
|
@ -20,10 +20,14 @@ relay.subscribe(
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Handle events through the loopback pipeline. */
|
/** Handle events through the loopback pipeline. */
|
||||||
function handleEvent(event: SignedEvent): void {
|
async function handleEvent(event: SignedEvent): Promise<void> {
|
||||||
console.info('loopback event:', event.id);
|
console.info('loopback event:', event.id);
|
||||||
insertEvent(event).catch(console.warn);
|
|
||||||
trackHashtags(event);
|
trackHashtags(event);
|
||||||
|
|
||||||
|
if (await isLocallyFollowed(event.pubkey)) {
|
||||||
|
insertEvent(event).catch(console.warn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Track whenever a hashtag is used, for processing trending tags. */
|
/** Track whenever a hashtag is used, for processing trending tags. */
|
||||||
|
|
Loading…
Reference in New Issue