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
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
||||||
.env
|
.env
|
||||||
*.cpuprofile
|
*.cpuprofile
|
||||||
*.swp
|
*.swp
|
||||||
deno-test.xml
|
deno-test.xml
|
||||||
|
*.db
|
||||||
|
|
@ -48,6 +48,19 @@ const getAuthor = async (pubkey: string, opts: GetEventOpts = {}): Promise<Nostr
|
||||||
.then(([event]) => event);
|
.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. */
|
/** Get users the given pubkey follows. */
|
||||||
const getFollows = async (pubkey: string, signal?: AbortSignal): Promise<NostrEvent | undefined> => {
|
const getFollows = async (pubkey: string, signal?: AbortSignal): Promise<NostrEvent | undefined> => {
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
|
|
@ -113,6 +126,7 @@ async function isLocallyFollowed(pubkey: string): Promise<boolean> {
|
||||||
export {
|
export {
|
||||||
getAncestors,
|
getAncestors,
|
||||||
getAuthor,
|
getAuthor,
|
||||||
|
getAuthorFallback,
|
||||||
getDescendants,
|
getDescendants,
|
||||||
getEvent,
|
getEvent,
|
||||||
getFeedPubkeys,
|
getFeedPubkeys,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { NIP05, NostrEvent, NSchema as n } from '@nostrify/nostrify';
|
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 { bech32ToPubkey } from '@/utils.ts';
|
||||||
import { nip05Cache } from '@/utils/nip05.ts';
|
import { nip05Cache } from '@/utils/nip05.ts';
|
||||||
import { Stickynotes } from '@soapbox/stickynotes';
|
import { Stickynotes } from '@soapbox/stickynotes';
|
||||||
|
|
@ -13,21 +13,21 @@ export async function lookupAccount(
|
||||||
const pubkey = await lookupPubkey(value, signal);
|
const pubkey = await lookupPubkey(value, signal);
|
||||||
|
|
||||||
if (pubkey) {
|
if (pubkey) {
|
||||||
return getAuthor(pubkey);
|
return getAuthorFallback(pubkey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolve a bech32 or NIP-05 identifier to a 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');
|
const console = new Stickynotes('ditto:lookup');
|
||||||
|
|
||||||
if (n.bech32().safeParse(value).success) {
|
if (n.bech32().safeParse(identifier).success) {
|
||||||
return bech32ToPubkey(value);
|
return bech32ToPubkey(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NIP05.regex().test(value)) {
|
if (NIP05.regex().test(identifier)) {
|
||||||
try {
|
try {
|
||||||
const { pubkey } = await nip05Cache.fetch(value, { signal });
|
const { pubkey } = await nip05Cache.fetch(identifier, { signal });
|
||||||
return pubkey;
|
return pubkey;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.debug(e);
|
console.debug(e);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue