From fd8f6800a4c84bfc20c4c74e790d47368353ee90 Mon Sep 17 00:00:00 2001 From: Sherry <26760878+shaibearary@users.noreply.github.com> Date: Sun, 17 Sep 2023 06:12:41 +0800 Subject: [PATCH] Naddr parsing (#178) Co-authored-by: BlowaterNostr <127284497+BlowaterNostr@users.noreply.github.com> --- UI/message.test.ts | 19 +++++++++++++++++++ UI/message.ts | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/UI/message.test.ts b/UI/message.test.ts index cfb9acf..c251080 100644 --- a/UI/message.test.ts +++ b/UI/message.test.ts @@ -1,6 +1,8 @@ import { assertEquals } from "https://deno.land/std@0.176.0/testing/asserts.ts"; import { ChatMessage, groupContinuousMessages, parseContent } from "./message.ts"; import { PrivateKey, PublicKey } from "../lib/nostr-ts/key.ts"; +import { NostrAddress } from "../lib/nostr-ts/nip19.ts"; +import { NostrKind } from "../lib/nostr-ts/nostr.ts"; Deno.test("inline parse", async (t) => { const data = [ @@ -169,6 +171,23 @@ Deno.test("inline parse", async (t) => { ], }], }, + { + input: + `naddr1qqxnzd3exsmnjvphxqunqv33qgsp7hwmlh5zccs55shzpfued50pznvypj0wwzn00dtyjzlqkr04w4grqsqqqa28vct2px`, + output: [{ + type: "naddr", + start: 0, + end: 99, + addr: new NostrAddress({ + pubkey: PublicKey.FromHex( + "1f5ddbfde82c6214a42e20a7996d1e114d840c9ee70a6f7b56490be0b0df5755", + ) as PublicKey, + identifier: "1694790709021", + kind: NostrKind.Long_Form, + relays: [], + }), + }], + }, // { // input: `nostr:nevent1qqsz25j8nrppstgmyry8hgsg4fggtfa6xnym2n4c2xth7usxtydtgpcpp4mhxue69uhhjctzw5hx6egzyze7g05vclndlu36x0vjzw37jykcjkcu8ep9qfqwpjvahmlrq6947qcyqqqqqqgj5mjek`, // output: [{ diff --git a/UI/message.ts b/UI/message.ts index 69cc199..8fa1d4b 100644 --- a/UI/message.ts +++ b/UI/message.ts @@ -1,7 +1,9 @@ import { PublicKey } from "../lib/nostr-ts/key.ts"; import { MessageThread } from "./dm.tsx"; import { DirectedMessage_Event, Text_Note_Event } from "../nostr.ts"; -import { NostrProfile, NoteID } from "../lib/nostr-ts/nip19.ts"; +import { NostrAddress, NostrProfile, NoteID } from "../lib/nostr-ts/nip19.ts"; +import { Int } from "https://deno.land/x/automerge@2.1.0-alpha.12/types.ts"; +import { NostrKind } from "../lib/nostr-ts/nostr.ts"; export function* parseContent(content: string) { // URLs @@ -13,6 +15,9 @@ export function* parseContent(content: string) { //nprofile yield* match(/(nostr:)?nprofile[0-9a-z]+/g, content, "nprofile"); + //naddr + yield* match(/(nostr:)?naddr[0-9a-z]+/g, content, "naddr"); + // notes yield* match(/note[0-9a-z]{59}/g, content, "note"); @@ -82,6 +87,24 @@ function* match(regex: RegExp, content: string, type: ItemType): Generator