mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
fix kind 0 lookups for account search
This commit is contained in:
parent
b805c4c67e
commit
78cae13885
3 changed files with 23 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@
|
|||
*.cpuprofile
|
||||
*.swp
|
||||
deno-test.xml
|
||||
*.db
|
||||
|
|
@ -48,6 +48,19 @@ const getAuthor = async (pubkey: string, opts: GetEventOpts = {}): Promise<Nostr
|
|||
.then(([event]) => event);
|
||||
};
|
||||
|
||||
const getAuthorFallback = async (pubkey: string, opts: GetEventOpts = {}): Promise<NostrEvent | undefined> => {
|
||||
const author = await getAuthor(pubkey, opts);
|
||||
const { signal = AbortSignal.timeout(1000) } = opts;
|
||||
|
||||
if (author) return author;
|
||||
|
||||
const pool = await Storages.client();
|
||||
return await pool.query([{ authors: [pubkey], kinds: [0], limit: 1 }], { limit: 1, signal })
|
||||
.then((events) => hydrateEvents({ events, store: pool, signal }))
|
||||
.then(([event]) => event);
|
||||
|
||||
};
|
||||
|
||||
/** Get users the given pubkey follows. */
|
||||
const getFollows = async (pubkey: string, signal?: AbortSignal): Promise<NostrEvent | undefined> => {
|
||||
const store = await Storages.db();
|
||||
|
|
@ -113,6 +126,7 @@ async function isLocallyFollowed(pubkey: string): Promise<boolean> {
|
|||
export {
|
||||
getAncestors,
|
||||
getAuthor,
|
||||
getAuthorFallback,
|
||||
getDescendants,
|
||||
getEvent,
|
||||
getFeedPubkeys,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { NIP05, NostrEvent, NSchema as n } from '@nostrify/nostrify';
|
||||
|
||||
import { getAuthor } from '@/queries.ts';
|
||||
import { getAuthorFallback } from '@/queries.ts';
|
||||
import { bech32ToPubkey } from '@/utils.ts';
|
||||
import { nip05Cache } from '@/utils/nip05.ts';
|
||||
import { Stickynotes } from '@soapbox/stickynotes';
|
||||
|
|
@ -13,21 +13,21 @@ export async function lookupAccount(
|
|||
const pubkey = await lookupPubkey(value, signal);
|
||||
|
||||
if (pubkey) {
|
||||
return getAuthor(pubkey);
|
||||
return getAuthorFallback(pubkey);
|
||||
}
|
||||
}
|
||||
|
||||
/** Resolve a bech32 or NIP-05 identifier to a pubkey. */
|
||||
export async function lookupPubkey(value: string, signal?: AbortSignal): Promise<string | undefined> {
|
||||
export async function lookupPubkey(identifier: string, signal?: AbortSignal): Promise<string | undefined> {
|
||||
const console = new Stickynotes('ditto:lookup');
|
||||
|
||||
if (n.bech32().safeParse(value).success) {
|
||||
return bech32ToPubkey(value);
|
||||
if (n.bech32().safeParse(identifier).success) {
|
||||
return bech32ToPubkey(identifier);
|
||||
}
|
||||
|
||||
if (NIP05.regex().test(value)) {
|
||||
if (NIP05.regex().test(identifier)) {
|
||||
try {
|
||||
const { pubkey } = await nip05Cache.fetch(value, { signal });
|
||||
const { pubkey } = await nip05Cache.fetch(identifier, { signal });
|
||||
return pubkey;
|
||||
} catch (e) {
|
||||
console.debug(e);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue