From c28c644265a082f70e2db088d1aaa6fea10c23cf Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 18 Mar 2023 16:39:34 -0500 Subject: [PATCH] Upgrade nostr-tools, do npub stuff, query own events in feed --- src/client.ts | 1 + src/deps.ts | 2 +- src/transmute.ts | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/client.ts b/src/client.ts index 287fbca..8d5e5d7 100644 --- a/src/client.ts +++ b/src/client.ts @@ -38,6 +38,7 @@ const fetchFollows = (pubkey: string): Promise | null> => { function fetchFeed(event3: Event<3>): Promise[]> { const authors = event3.tags.filter((tag) => tag[0] === 'p').map((tag) => tag[1]); const results: SignedEvent<1>[] = []; + authors.push(event3.pubkey); // see own events in feed return new Promise((resolve) => { pool.subscribe( diff --git a/src/deps.ts b/src/deps.ts index 23acd59..8385391 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -3,5 +3,5 @@ export { Hono, validator }; export { cors } from 'https://deno.land/x/hono@v3.0.2/middleware.ts'; export { z } from 'https://deno.land/x/zod@v3.20.5/mod.ts'; export { Author, RelayPool } from 'https://dev.jspm.io/nostr-relaypool@0.5.3'; -export { getEventHash, getPublicKey, signEvent } from 'https://dev.jspm.io/nostr-tools@1.6.0'; +export { getEventHash, getPublicKey, nip19, signEvent } from 'npm:nostr-tools@^1.7.4'; export type { Context }; diff --git a/src/transmute.ts b/src/transmute.ts index 4cba0c9..83f2d77 100644 --- a/src/transmute.ts +++ b/src/transmute.ts @@ -1,3 +1,5 @@ +import { nip19 } from '@/deps.ts'; + import { LOCAL_DOMAIN } from './config.ts'; import { fetchUser } from './client.ts'; import { jsonSchema, MetaContent, metaContentSchema } from './schema.ts'; @@ -16,10 +18,11 @@ function toAccount(event: Event<0>) { const { pubkey } = event; const content: MetaContent = parseContent(event); const { host, origin } = new URL(LOCAL_DOMAIN); + const npub = nip19.npubEncode(pubkey); return { id: pubkey, - acct: content.nip05 || pubkey, + acct: content.nip05 || npub, avatar: content.picture || DEFAULT_AVATAR, avatar_static: content.picture || DEFAULT_AVATAR, bot: false, @@ -35,9 +38,9 @@ function toAccount(event: Event<0>) { header_static: content.banner, locked: false, note: content.about, - fqn: content.nip05 || `${pubkey}@${host}`, + fqn: content.nip05 || `${npub}@${host}`, url: `${origin}/users/${pubkey}`, - username: content.nip05 || pubkey, + username: content.nip05 || npub, }; }