2024-04-22 06:23:56 +00:00
|
|
|
|
import { assertEquals } from "https://deno.land/std@0.202.0/assert/assert_equals.ts";
|
|
|
|
|
import {
|
|
|
|
|
ChatMessage,
|
|
|
|
|
ContentItem,
|
|
|
|
|
findUrlInString,
|
|
|
|
|
groupContinuousMessages,
|
|
|
|
|
parseContent,
|
|
|
|
|
} from "./message.ts";
|
2024-01-01 17:28:10 +00:00
|
|
|
|
import { PrivateKey, PublicKey } from "../../libs/nostr.ts/key.ts";
|
2024-03-15 13:44:17 +00:00
|
|
|
|
|
2024-01-01 17:28:10 +00:00
|
|
|
|
import { NostrKind } from "../../libs/nostr.ts/nostr.ts";
|
2024-04-22 06:23:56 +00:00
|
|
|
|
import { Nevent, NostrAddress, NostrProfile } from "../../libs/nostr.ts/nip19.ts";
|
2023-06-30 14:05:57 +00:00
|
|
|
|
|
|
|
|
|
Deno.test("inline parse", async (t) => {
|
2024-04-22 06:23:56 +00:00
|
|
|
|
const data: {
|
|
|
|
|
input: string;
|
|
|
|
|
output: ContentItem[];
|
|
|
|
|
}[] = [
|
2023-06-30 14:05:57 +00:00
|
|
|
|
{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
input: "",
|
2023-06-30 14:05:57 +00:00
|
|
|
|
output: [],
|
|
|
|
|
},
|
2024-04-22 06:23:56 +00:00
|
|
|
|
{
|
|
|
|
|
input: `nothing`,
|
|
|
|
|
output: [{
|
|
|
|
|
text: "nothing",
|
|
|
|
|
type: "raw",
|
|
|
|
|
}],
|
|
|
|
|
},
|
2023-06-30 14:05:57 +00:00
|
|
|
|
{
|
|
|
|
|
input:
|
|
|
|
|
`https://nostr.build/i/f91187675750791b652f7e129b374c2b682d7cc0e9dbc28def58ffdf66508867.jpg`,
|
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
text:
|
|
|
|
|
"https://nostr.build/i/f91187675750791b652f7e129b374c2b682d7cc0e9dbc28def58ffdf66508867.jpg",
|
2023-06-30 14:05:57 +00:00
|
|
|
|
type: "url",
|
|
|
|
|
}],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input:
|
|
|
|
|
` https://nostr.build/i/f91187675750791b652f7e129b374c2b682d7cc0e9dbc28def58ffdf66508867.jpg`,
|
2024-04-22 06:23:56 +00:00
|
|
|
|
output: [
|
|
|
|
|
{
|
|
|
|
|
text: " ",
|
|
|
|
|
type: "raw",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text:
|
|
|
|
|
"https://nostr.build/i/f91187675750791b652f7e129b374c2b682d7cc0e9dbc28def58ffdf66508867.jpg",
|
|
|
|
|
type: "url",
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-06-30 14:05:57 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input:
|
|
|
|
|
`https://nostr.build/i/f91187675750791b652f7e129b374c2b682d7cc0e9dbc28def58ffdf66508867.jpg `,
|
2024-04-22 06:23:56 +00:00
|
|
|
|
output: [
|
|
|
|
|
{
|
|
|
|
|
text:
|
|
|
|
|
"https://nostr.build/i/f91187675750791b652f7e129b374c2b682d7cc0e9dbc28def58ffdf66508867.jpg",
|
|
|
|
|
type: "url",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: " ",
|
|
|
|
|
type: "raw",
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-06-30 14:05:57 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input:
|
|
|
|
|
` https://nostr.build/i/f91187675750791b652f7e129b374c2b682d7cc0e9dbc28def58ffdf66508867.jpg `,
|
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
text: " ",
|
|
|
|
|
type: "raw",
|
|
|
|
|
}, {
|
|
|
|
|
text:
|
|
|
|
|
"https://nostr.build/i/f91187675750791b652f7e129b374c2b682d7cc0e9dbc28def58ffdf66508867.jpg",
|
2023-06-30 14:05:57 +00:00
|
|
|
|
type: "url",
|
2024-04-22 06:23:56 +00:00
|
|
|
|
}, {
|
|
|
|
|
text: " ",
|
|
|
|
|
type: "raw",
|
2023-06-30 14:05:57 +00:00
|
|
|
|
}],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input: `Hi https://some.jpg`,
|
2024-04-22 06:23:56 +00:00
|
|
|
|
output: [
|
|
|
|
|
{
|
|
|
|
|
text: "Hi ",
|
|
|
|
|
type: "raw",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: "https://some.jpg",
|
|
|
|
|
type: "url",
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-06-30 14:05:57 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input: `Hi https://some.jpg http://some.jpg`,
|
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
text: "Hi ",
|
|
|
|
|
type: "raw",
|
|
|
|
|
}, {
|
|
|
|
|
text: "https://some.jpg",
|
2023-06-30 14:05:57 +00:00
|
|
|
|
type: "url",
|
|
|
|
|
}, {
|
2024-04-22 06:23:56 +00:00
|
|
|
|
text: " ",
|
|
|
|
|
type: "raw",
|
|
|
|
|
}, {
|
|
|
|
|
text: "http://some.jpg",
|
2023-06-30 14:05:57 +00:00
|
|
|
|
type: "url",
|
|
|
|
|
}],
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
input: `npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl`,
|
2023-06-30 14:05:57 +00:00
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
text: "npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl",
|
2023-06-30 14:05:57 +00:00
|
|
|
|
type: "npub",
|
2024-04-22 06:23:56 +00:00
|
|
|
|
pubkey: PublicKey.FromBech32(
|
|
|
|
|
"npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl",
|
|
|
|
|
) as PublicKey,
|
2023-06-30 14:05:57 +00:00
|
|
|
|
}],
|
|
|
|
|
},
|
2023-09-09 15:01:07 +00:00
|
|
|
|
{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
input: `nostr:npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4ylログボ`,
|
2023-09-09 15:01:07 +00:00
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
text: "nostr:npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl",
|
2023-09-09 15:01:07 +00:00
|
|
|
|
type: "npub",
|
2024-04-22 06:23:56 +00:00
|
|
|
|
pubkey: PublicKey.FromBech32(
|
|
|
|
|
"npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl",
|
|
|
|
|
) as PublicKey,
|
|
|
|
|
}, {
|
|
|
|
|
text: "ログボ",
|
|
|
|
|
type: "raw",
|
2023-09-09 15:01:07 +00:00
|
|
|
|
}],
|
|
|
|
|
},
|
2023-08-24 17:32:52 +00:00
|
|
|
|
{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
input: `sherryiscutenpub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4ylログボ`,
|
2023-08-24 17:32:52 +00:00
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
text: "sherryiscute",
|
|
|
|
|
type: "raw",
|
|
|
|
|
}, {
|
|
|
|
|
text: "npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl",
|
2023-08-24 17:32:52 +00:00
|
|
|
|
type: "npub",
|
2024-04-22 06:23:56 +00:00
|
|
|
|
pubkey: PublicKey.FromBech32(
|
|
|
|
|
"npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl",
|
|
|
|
|
) as PublicKey,
|
|
|
|
|
}, {
|
|
|
|
|
text: "ログボ",
|
|
|
|
|
type: "raw",
|
2023-08-24 17:32:52 +00:00
|
|
|
|
}],
|
|
|
|
|
},
|
2024-04-22 06:23:56 +00:00
|
|
|
|
|
2023-09-12 15:50:14 +00:00
|
|
|
|
{
|
|
|
|
|
input:
|
|
|
|
|
`nostr:nprofile1qqsf37u9q4up37etd4w4fgdfkxvurxk74gcmsf9ea0g7vgyasfdjeycpp4mhxue69uhkummn9ekx7mqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduqscamnwvaz7tmzwf3zu6t0qyd8wumn8ghj7mn0wd68ytn0wfskuem9wp5kcmpwv3jhvqghwaehxw309aex2mrp0yhxxatjwfjkuapwveukjqgswaehxw309ahx7um5wgh8w6twv5q3samnwvaz7tmjv4kxz7fwwdhx7un59eek7cmfv9kqz9thwden5te0v4jx2m3wdehhxarj9ekxzmnyqyd8wumn8ghj7un9d3shjtnwdaehgun8wfshq6pwdejhgqgewaehxw309ac82unpwe5kgcfwdehhxarj9ekxzmnyqyvhwumn8ghj7mn0wd68ytn6v43x2er9v5hxxmr0w4jqzynhwden5te0wp6hyurvv4cxzeewv4esz9nhwden5te0v96xcctn9ehx7um5wghxcctwvsq3camnwvaz7tmwdaehgu3wd46hg6tw09mkzmrvv46zucm0d5lxp0l4`,
|
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
type: "nprofile",
|
|
|
|
|
text:
|
|
|
|
|
"nostr:nprofile1qqsf37u9q4up37etd4w4fgdfkxvurxk74gcmsf9ea0g7vgyasfdjeycpp4mhxue69uhkummn9ekx7mqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduqscamnwvaz7tmzwf3zu6t0qyd8wumn8ghj7mn0wd68ytn0wfskuem9wp5kcmpwv3jhvqghwaehxw309aex2mrp0yhxxatjwfjkuapwveukjqgswaehxw309ahx7um5wgh8w6twv5q3samnwvaz7tmjv4kxz7fwwdhx7un59eek7cmfv9kqz9thwden5te0v4jx2m3wdehhxarj9ekxzmnyqyd8wumn8ghj7un9d3shjtnwdaehgun8wfshq6pwdejhgqgewaehxw309ac82unpwe5kgcfwdehhxarj9ekxzmnyqyvhwumn8ghj7mn0wd68ytn6v43x2er9v5hxxmr0w4jqzynhwden5te0wp6hyurvv4cxzeewv4esz9nhwden5te0v96xcctn9ehx7um5wghxcctwvsq3camnwvaz7tmwdaehgu3wd46hg6tw09mkzmrvv46zucm0d5lxp0l4",
|
|
|
|
|
nprofile: NostrProfile.decode(
|
|
|
|
|
"nprofile1qqsf37u9q4up37etd4w4fgdfkxvurxk74gcmsf9ea0g7vgyasfdjeycpp4mhxue69uhkummn9ekx7mqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduqscamnwvaz7tmzwf3zu6t0qyd8wumn8ghj7mn0wd68ytn0wfskuem9wp5kcmpwv3jhvqghwaehxw309aex2mrp0yhxxatjwfjkuapwveukjqgswaehxw309ahx7um5wgh8w6twv5q3samnwvaz7tmjv4kxz7fwwdhx7un59eek7cmfv9kqz9thwden5te0v4jx2m3wdehhxarj9ekxzmnyqyd8wumn8ghj7un9d3shjtnwdaehgun8wfshq6pwdejhgqgewaehxw309ac82unpwe5kgcfwdehhxarj9ekxzmnyqyvhwumn8ghj7mn0wd68ytn6v43x2er9v5hxxmr0w4jqzynhwden5te0wp6hyurvv4cxzeewv4esz9nhwden5te0v96xcctn9ehx7um5wghxcctwvsq3camnwvaz7tmwdaehgu3wd46hg6tw09mkzmrvv46zucm0d5lxp0l4",
|
|
|
|
|
) as NostrProfile,
|
2023-09-12 15:50:14 +00:00
|
|
|
|
}],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input:
|
|
|
|
|
`sherryiscutenprofile1qqsf37u9q4up37etd4w4fgdfkxvurxk74gcmsf9ea0g7vgyasfdjeycpp4mhxue69uhkummn9ekx7mqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduqscamnwvaz7tmzwf3zu6t0qyd8wumn8ghj7mn0wd68ytn0wfskuem9wp5kcmpwv3jhvqghwaehxw309aex2mrp0yhxxatjwfjkuapwveukjqgswaehxw309ahx7um5wgh8w6twv5q3samnwvaz7tmjv4kxz7fwwdhx7un59eek7cmfv9kqz9thwden5te0v4jx2m3wdehhxarj9ekxzmnyqyd8wumn8ghj7un9d3shjtnwdaehgun8wfshq6pwdejhgqgewaehxw309ac82unpwe5kgcfwdehhxarj9ekxzmnyqyvhwumn8ghj7mn0wd68ytn6v43x2er9v5hxxmr0w4jqzynhwden5te0wp6hyurvv4cxzeewv4esz9nhwden5te0v96xcctn9ehx7um5wghxcctwvsq3camnwvaz7tmwdaehgu3wd46hg6tw09mkzmrvv46zucm0d5lxp0l4 123`,
|
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
text: "sherryiscute",
|
|
|
|
|
type: "raw",
|
|
|
|
|
}, {
|
|
|
|
|
type: "nprofile",
|
|
|
|
|
text:
|
|
|
|
|
"nprofile1qqsf37u9q4up37etd4w4fgdfkxvurxk74gcmsf9ea0g7vgyasfdjeycpp4mhxue69uhkummn9ekx7mqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduqscamnwvaz7tmzwf3zu6t0qyd8wumn8ghj7mn0wd68ytn0wfskuem9wp5kcmpwv3jhvqghwaehxw309aex2mrp0yhxxatjwfjkuapwveukjqgswaehxw309ahx7um5wgh8w6twv5q3samnwvaz7tmjv4kxz7fwwdhx7un59eek7cmfv9kqz9thwden5te0v4jx2m3wdehhxarj9ekxzmnyqyd8wumn8ghj7un9d3shjtnwdaehgun8wfshq6pwdejhgqgewaehxw309ac82unpwe5kgcfwdehhxarj9ekxzmnyqyvhwumn8ghj7mn0wd68ytn6v43x2er9v5hxxmr0w4jqzynhwden5te0wp6hyurvv4cxzeewv4esz9nhwden5te0v96xcctn9ehx7um5wghxcctwvsq3camnwvaz7tmwdaehgu3wd46hg6tw09mkzmrvv46zucm0d5lxp0l4",
|
|
|
|
|
nprofile: NostrProfile.decode(
|
|
|
|
|
"nprofile1qqsf37u9q4up37etd4w4fgdfkxvurxk74gcmsf9ea0g7vgyasfdjeycpp4mhxue69uhkummn9ekx7mqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduqscamnwvaz7tmzwf3zu6t0qyd8wumn8ghj7mn0wd68ytn0wfskuem9wp5kcmpwv3jhvqghwaehxw309aex2mrp0yhxxatjwfjkuapwveukjqgswaehxw309ahx7um5wgh8w6twv5q3samnwvaz7tmjv4kxz7fwwdhx7un59eek7cmfv9kqz9thwden5te0v4jx2m3wdehhxarj9ekxzmnyqyd8wumn8ghj7un9d3shjtnwdaehgun8wfshq6pwdejhgqgewaehxw309ac82unpwe5kgcfwdehhxarj9ekxzmnyqyvhwumn8ghj7mn0wd68ytn6v43x2er9v5hxxmr0w4jqzynhwden5te0wp6hyurvv4cxzeewv4esz9nhwden5te0v96xcctn9ehx7um5wghxcctwvsq3camnwvaz7tmwdaehgu3wd46hg6tw09mkzmrvv46zucm0d5lxp0l4",
|
|
|
|
|
) as NostrProfile,
|
|
|
|
|
}, {
|
|
|
|
|
text: " 123",
|
|
|
|
|
type: "raw",
|
2023-09-12 15:50:14 +00:00
|
|
|
|
}],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input:
|
|
|
|
|
`nprofile1qqsf37u9q4up37etd4w4fgdfkxvurxk74gcmsf9ea0g7vgyasfdjeycpp4mhxue69uhkummn9ekx7mqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduqscamnwvaz7tmzwf3zu6t0qyd8wumn8ghj7mn0wd68ytn0wfskuem9wp5kcmpwv3jhvqghwaehxw309aex2mrp0yhxxatjwfjkuapwveukjqgswaehxw309ahx7um5wgh8w6twv5q3samnwvaz7tmjv4kxz7fwwdhx7un59eek7cmfv9kqz9thwden5te0v4jx2m3wdehhxarj9ekxzmnyqyd8wumn8ghj7un9d3shjtnwdaehgun8wfshq6pwdejhgqgewaehxw309ac82unpwe5kgcfwdehhxarj9ekxzmnyqyvhwumn8ghj7mn0wd68ytn6v43x2er9v5hxxmr0w4jqzynhwden5te0wp6hyurvv4cxzeewv4esz9nhwden5te0v96xcctn9ehx7um5wghxcctwvsq3camnwvaz7tmwdaehgu3wd46hg6tw09mkzmrvv46zucm0d5lxp0l4`,
|
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
type: "nprofile",
|
|
|
|
|
text:
|
|
|
|
|
"nprofile1qqsf37u9q4up37etd4w4fgdfkxvurxk74gcmsf9ea0g7vgyasfdjeycpp4mhxue69uhkummn9ekx7mqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduqscamnwvaz7tmzwf3zu6t0qyd8wumn8ghj7mn0wd68ytn0wfskuem9wp5kcmpwv3jhvqghwaehxw309aex2mrp0yhxxatjwfjkuapwveukjqgswaehxw309ahx7um5wgh8w6twv5q3samnwvaz7tmjv4kxz7fwwdhx7un59eek7cmfv9kqz9thwden5te0v4jx2m3wdehhxarj9ekxzmnyqyd8wumn8ghj7un9d3shjtnwdaehgun8wfshq6pwdejhgqgewaehxw309ac82unpwe5kgcfwdehhxarj9ekxzmnyqyvhwumn8ghj7mn0wd68ytn6v43x2er9v5hxxmr0w4jqzynhwden5te0wp6hyurvv4cxzeewv4esz9nhwden5te0v96xcctn9ehx7um5wghxcctwvsq3camnwvaz7tmwdaehgu3wd46hg6tw09mkzmrvv46zucm0d5lxp0l4",
|
|
|
|
|
nprofile: NostrProfile.decode(
|
|
|
|
|
"nprofile1qqsf37u9q4up37etd4w4fgdfkxvurxk74gcmsf9ea0g7vgyasfdjeycpp4mhxue69uhkummn9ekx7mqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduqscamnwvaz7tmzwf3zu6t0qyd8wumn8ghj7mn0wd68ytn0wfskuem9wp5kcmpwv3jhvqghwaehxw309aex2mrp0yhxxatjwfjkuapwveukjqgswaehxw309ahx7um5wgh8w6twv5q3samnwvaz7tmjv4kxz7fwwdhx7un59eek7cmfv9kqz9thwden5te0v4jx2m3wdehhxarj9ekxzmnyqyd8wumn8ghj7un9d3shjtnwdaehgun8wfshq6pwdejhgqgewaehxw309ac82unpwe5kgcfwdehhxarj9ekxzmnyqyvhwumn8ghj7mn0wd68ytn6v43x2er9v5hxxmr0w4jqzynhwden5te0wp6hyurvv4cxzeewv4esz9nhwden5te0v96xcctn9ehx7um5wghxcctwvsq3camnwvaz7tmwdaehgu3wd46hg6tw09mkzmrvv46zucm0d5lxp0l4",
|
|
|
|
|
) as NostrProfile,
|
2023-09-12 15:50:14 +00:00
|
|
|
|
}],
|
|
|
|
|
},
|
2023-09-16 22:12:41 +00:00
|
|
|
|
{
|
|
|
|
|
input:
|
|
|
|
|
`naddr1qqxnzd3exsmnjvphxqunqv33qgsp7hwmlh5zccs55shzpfued50pznvypj0wwzn00dtyjzlqkr04w4grqsqqqa28vct2px`,
|
|
|
|
|
output: [{
|
|
|
|
|
type: "naddr",
|
2024-04-22 06:23:56 +00:00
|
|
|
|
text:
|
|
|
|
|
"naddr1qqxnzd3exsmnjvphxqunqv33qgsp7hwmlh5zccs55shzpfued50pznvypj0wwzn00dtyjzlqkr04w4grqsqqqa28vct2px",
|
2023-09-16 22:12:41 +00:00
|
|
|
|
addr: new NostrAddress({
|
|
|
|
|
pubkey: PublicKey.FromHex(
|
|
|
|
|
"1f5ddbfde82c6214a42e20a7996d1e114d840c9ee70a6f7b56490be0b0df5755",
|
|
|
|
|
) as PublicKey,
|
|
|
|
|
identifier: "1694790709021",
|
|
|
|
|
kind: NostrKind.Long_Form,
|
|
|
|
|
relays: [],
|
|
|
|
|
}),
|
|
|
|
|
}],
|
|
|
|
|
},
|
2023-09-22 15:11:26 +00:00
|
|
|
|
{
|
|
|
|
|
input:
|
|
|
|
|
`nostr:nevent1qqsz25j8nrppstgmyry8hgsg4fggtfa6xnym2n4c2xth7usxtydtgpcpp4mhxue69uhhjctzw5hx6egzyze7g05vclndlu36x0vjzw37jykcjkcu8ep9qfqwpjvahmlrq6947qcyqqqqqqgj5mjek`,
|
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
text:
|
|
|
|
|
"nostr:nevent1qqsz25j8nrppstgmyry8hgsg4fggtfa6xnym2n4c2xth7usxtydtgpcpp4mhxue69uhhjctzw5hx6egzyze7g05vclndlu36x0vjzw37jykcjkcu8ep9qfqwpjvahmlrq6947qcyqqqqqqgj5mjek",
|
|
|
|
|
type: "nevent",
|
|
|
|
|
nevent: new Nevent(
|
2023-09-22 15:11:26 +00:00
|
|
|
|
{
|
|
|
|
|
id: "25524798c2182d1b20c87ba208aa5085a7ba34c9b54eb851977f7206591ab407",
|
|
|
|
|
kind: 1,
|
|
|
|
|
pubkey: PublicKey.FromHex(
|
|
|
|
|
"b3e43e8cc7e6dff23a33d9213a3e912d895b1c3e4250240e0c99dbefe3068b5f",
|
|
|
|
|
) as PublicKey,
|
|
|
|
|
relays: [
|
|
|
|
|
"wss://yabu.me",
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
}],
|
|
|
|
|
},
|
2023-06-30 14:05:57 +00:00
|
|
|
|
{
|
|
|
|
|
input: `Thank you #[0] #[2]#[3]`,
|
2024-04-22 06:23:56 +00:00
|
|
|
|
output: [
|
|
|
|
|
{
|
|
|
|
|
type: "raw",
|
|
|
|
|
text: "Thank you ",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "tag",
|
|
|
|
|
text: "#[0]",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "raw",
|
|
|
|
|
text: " ",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "tag",
|
|
|
|
|
text: "#[2]",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "tag",
|
|
|
|
|
text: "#[3]",
|
|
|
|
|
},
|
|
|
|
|
],
|
2023-06-30 14:05:57 +00:00
|
|
|
|
},
|
2023-10-09 21:02:13 +00:00
|
|
|
|
{
|
|
|
|
|
input:
|
2024-04-22 06:23:56 +00:00
|
|
|
|
`nostr:npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl https://example.com`,
|
|
|
|
|
output: [
|
|
|
|
|
{
|
|
|
|
|
type: "npub",
|
|
|
|
|
text: "nostr:npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl",
|
|
|
|
|
pubkey: PublicKey.FromBech32(
|
|
|
|
|
"npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl",
|
|
|
|
|
) as PublicKey,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "raw",
|
|
|
|
|
text: " ",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "url",
|
|
|
|
|
text: "https://example.com",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input:
|
|
|
|
|
`hi https://example.com nostr:npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl`,
|
|
|
|
|
output: [
|
|
|
|
|
{
|
|
|
|
|
type: "raw",
|
|
|
|
|
text: "hi ",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "url",
|
|
|
|
|
text: "https://example.com",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "raw",
|
|
|
|
|
text: " ",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "npub",
|
|
|
|
|
text: "nostr:npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl",
|
|
|
|
|
pubkey: PublicKey.FromBech32(
|
|
|
|
|
"npub17dxnfw2vrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7s6ng4yl",
|
|
|
|
|
) as PublicKey,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
input: `pubkey error: nostr:npub1xxxxxxxxrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7sxxxxxx`,
|
2023-10-09 21:02:13 +00:00
|
|
|
|
output: [{
|
2024-04-22 06:23:56 +00:00
|
|
|
|
type: "raw",
|
|
|
|
|
text: "pubkey error: nostr:npub1xxxxxxxxrhgtk4fgqdmpuqxv05u9raau3w0shay7msmr0dzs4m7sxxxxxx",
|
2023-10-09 21:02:13 +00:00
|
|
|
|
}],
|
|
|
|
|
},
|
2023-06-30 14:05:57 +00:00
|
|
|
|
];
|
2024-04-22 06:23:56 +00:00
|
|
|
|
for (const test of data) {
|
|
|
|
|
await t.step(`t-${test.input}`, () => {
|
|
|
|
|
assertEquals(Array.from(parseContent(test.input)), test.output);
|
2023-06-30 14:05:57 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test("message group", () => {
|
|
|
|
|
const data: ChatMessage[] = [
|
|
|
|
|
{
|
|
|
|
|
// don't care the value of event
|
|
|
|
|
event: {
|
|
|
|
|
content: "",
|
|
|
|
|
created_at: 1,
|
|
|
|
|
id: "",
|
2023-10-07 23:23:53 +00:00
|
|
|
|
kind: NostrKind.DIRECT_MESSAGE,
|
2023-06-30 14:05:57 +00:00
|
|
|
|
pubkey: "",
|
|
|
|
|
sig: "",
|
|
|
|
|
tags: [],
|
2023-07-16 15:04:23 +00:00
|
|
|
|
parsedTags: {
|
|
|
|
|
e: [],
|
|
|
|
|
p: [],
|
|
|
|
|
},
|
|
|
|
|
publicKey: PrivateKey.Generate().toPublicKey(),
|
2023-10-07 23:23:53 +00:00
|
|
|
|
decryptedContent: "",
|
2023-06-30 14:05:57 +00:00
|
|
|
|
},
|
2023-10-07 23:23:53 +00:00
|
|
|
|
author: PrivateKey.Generate().toPublicKey(),
|
2023-06-30 14:05:57 +00:00
|
|
|
|
"content": "sendDirectMessage",
|
|
|
|
|
"type": "text",
|
|
|
|
|
"created_at": new Date("2023-03-11T09:50:47.000Z"),
|
|
|
|
|
lamport: 0,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
const groups = Array.from(groupContinuousMessages([
|
|
|
|
|
{
|
|
|
|
|
root: data[0],
|
|
|
|
|
replies: [],
|
|
|
|
|
},
|
|
|
|
|
], () => true));
|
|
|
|
|
assertEquals(groups.length, 1);
|
|
|
|
|
assertEquals(groups[0].length, 1);
|
|
|
|
|
});
|
2023-10-08 15:53:44 +00:00
|
|
|
|
|
|
|
|
|
Deno.test("if there is no message, should not yield any group", () => {
|
|
|
|
|
const group = groupContinuousMessages([], () => true).next();
|
|
|
|
|
assertEquals(group.value, undefined);
|
|
|
|
|
assertEquals(group.done, true);
|
|
|
|
|
});
|
2023-12-07 13:18:26 +00:00
|
|
|
|
|
|
|
|
|
Deno.test("findUrlInString should include non-URL parts", () => {
|
|
|
|
|
const result = findUrlInString("Visit http://example.com for more info.");
|
|
|
|
|
assertEquals(result, ["Visit ", new URL("http://example.com"), " for more info."]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test("findUrlInString with multiple URLs and text parts", () => {
|
|
|
|
|
const result = findUrlInString("Go to http://example.com and https://example.org for info.");
|
|
|
|
|
assertEquals(result, [
|
|
|
|
|
"Go to ",
|
|
|
|
|
new URL("http://example.com"),
|
|
|
|
|
" and ",
|
|
|
|
|
new URL("https://example.org"),
|
|
|
|
|
" for info.",
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test("findUrlInString with only text", () => {
|
|
|
|
|
const result = findUrlInString("No URLs here.");
|
|
|
|
|
assertEquals(result, ["No URLs here."]);
|
|
|
|
|
});
|