Add isFollowed function
This commit is contained in:
parent
0bfd9d83c1
commit
9671a77bee
|
@ -1,7 +1,7 @@
|
||||||
import { type Filter, type Insertable } from '@/deps.ts';
|
import { type Filter, type Insertable } from '@/deps.ts';
|
||||||
import { type SignedEvent } from '@/event.ts';
|
import { type SignedEvent } from '@/event.ts';
|
||||||
|
|
||||||
import { db, type TagRow } from '../db.ts';
|
import { db, type TagRow } from '@/db.ts';
|
||||||
|
|
||||||
function insertEvent(event: SignedEvent): Promise<void> {
|
function insertEvent(event: SignedEvent): Promise<void> {
|
||||||
return db.transaction().execute(async (trx) => {
|
return db.transaction().execute(async (trx) => {
|
||||||
|
@ -90,4 +90,12 @@ function getFilter<K extends number = number>(filter: Filter<K>): Promise<Signed
|
||||||
return getFilters<K>([filter]);
|
return getFilters<K>([filter]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { getFilter, getFilters, insertEvent };
|
async function isFollowed({ pubkey }: SignedEvent): Promise<boolean> {
|
||||||
|
const event = await getFilterQuery({ kinds: [3], '#p': [pubkey], limit: 1 })
|
||||||
|
.innerJoin('users', 'users.pubkey', 'events.pubkey')
|
||||||
|
.executeTakeFirst();
|
||||||
|
|
||||||
|
return !!event;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getFilter, getFilters, insertEvent, isFollowed };
|
||||||
|
|
Loading…
Reference in New Issue