mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Only save the nip05 in author search if it's valid
This commit is contained in:
parent
a8df213aec
commit
8510f22d1b
1 changed files with 28 additions and 33 deletions
|
|
@ -140,11 +140,13 @@ async function parseMetadata(event: NostrEvent, signal: AbortSignal): Promise<vo
|
||||||
|
|
||||||
// Get nip05.
|
// Get nip05.
|
||||||
const { name, nip05 } = metadata.data;
|
const { name, nip05 } = metadata.data;
|
||||||
|
const result = nip05 ? await nip05Cache.fetch(nip05, { signal }).catch(() => undefined) : undefined;
|
||||||
|
|
||||||
// Populate author_search.
|
// Populate author_search.
|
||||||
try {
|
try {
|
||||||
const search = [name, nip05].filter(Boolean).join(' ').trim();
|
const search = result?.pubkey === event.pubkey ? [name, nip05].filter(Boolean).join(' ').trim() : name ?? '';
|
||||||
|
|
||||||
|
if (search) {
|
||||||
await kysely.insertInto('author_search').values({
|
await kysely.insertInto('author_search').values({
|
||||||
pubkey: event.pubkey,
|
pubkey: event.pubkey,
|
||||||
search,
|
search,
|
||||||
|
|
@ -154,27 +156,19 @@ async function parseMetadata(event: NostrEvent, signal: AbortSignal): Promise<vo
|
||||||
.doUpdateSet({ search }),
|
.doUpdateSet({ search }),
|
||||||
)
|
)
|
||||||
.execute();
|
.execute();
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nip05) return;
|
if (nip05 && result && result.pubkey === event.pubkey) {
|
||||||
|
|
||||||
// Fetch nip05.
|
|
||||||
const result = await nip05Cache.fetch(nip05, { signal }).catch(() => undefined);
|
|
||||||
if (!result) return;
|
|
||||||
|
|
||||||
// Ensure pubkey matches event.
|
|
||||||
const { pubkey } = result;
|
|
||||||
if (pubkey !== event.pubkey) return;
|
|
||||||
|
|
||||||
// Track pubkey domain.
|
// Track pubkey domain.
|
||||||
try {
|
try {
|
||||||
const { domain } = parseNip05(nip05);
|
const { domain } = parseNip05(nip05);
|
||||||
|
|
||||||
await sql`
|
await sql`
|
||||||
INSERT INTO pubkey_domains (pubkey, domain, last_updated_at)
|
INSERT INTO pubkey_domains (pubkey, domain, last_updated_at)
|
||||||
VALUES (${pubkey}, ${domain}, ${event.created_at})
|
VALUES (${event.pubkey}, ${domain}, ${event.created_at})
|
||||||
ON CONFLICT(pubkey) DO UPDATE SET
|
ON CONFLICT(pubkey) DO UPDATE SET
|
||||||
domain = excluded.domain,
|
domain = excluded.domain,
|
||||||
last_updated_at = excluded.last_updated_at
|
last_updated_at = excluded.last_updated_at
|
||||||
|
|
@ -183,6 +177,7 @@ async function parseMetadata(event: NostrEvent, signal: AbortSignal): Promise<vo
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update the event in the database and set its language. */
|
/** Update the event in the database and set its language. */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue