update nostr.ts (#267)

This commit is contained in:
BlowaterNostr 2023-10-26 16:42:04 +08:00 committed by GitHub
parent 943f042c7c
commit a919a350f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 30 deletions

View File

@ -365,9 +365,10 @@ export async function* UI_Interaction_Update(args: {
}
const profileEvent = await prepareNormalNostrEvent(
groupCreation.groupKey,
NostrKind.META_DATA,
[],
JSON.stringify(profileData),
{
kind: NostrKind.META_DATA,
content: JSON.stringify(profileData),
},
);
const err2 = pool.sendEvent(profileEvent);
if (err2 instanceof Error) {

View File

@ -68,7 +68,7 @@ Deno.test("Relay Config", async () => {
{
const err = await relayConfig.syncWithPool(pool);
if (err != undefined) {
assertEquals(err.message, "wss://somewhere has been closed, can't wait for it to open");
assertEquals(err.message, "wss://somewhere/ has been closed, can't wait for it to open");
}
// add one relay to the pool directly
@ -83,7 +83,7 @@ Deno.test("Relay Config", async () => {
// will remove urls that's in the pool but not in the config
const err2 = await relayConfig.syncWithPool(pool);
if (err2 != undefined) {
assertEquals(err2.message, "wss://somewhere has been closed, can't wait for it to open");
assertEquals(err2.message, "wss://somewhere/ has been closed, can't wait for it to open");
}
assertEquals(pool.getRelays().map((r) => r.url), ["wss://relay.damus.io"]); // wirednet is removed
}

View File

@ -12,7 +12,7 @@ Deno.test("Database", async () => {
if (db instanceof Error) fail(db.message);
const stream = db.subscribe();
const event_to_add = await prepareNormalNostrEvent(ctx, NostrKind.TEXT_NOTE, [], "1");
const event_to_add = await prepareNormalNostrEvent(ctx, { kind: NostrKind.TEXT_NOTE, content: "1" });
await db.addEvent(event_to_add);
assertEquals(
db.events.map((e): NostrEvent => {
@ -48,7 +48,7 @@ Deno.test("Database", async () => {
await db.addEvent(event_to_add); // add a duplicated event
assertEquals(db.events.length, 1); // no changes
const event_to_add2 = await prepareNormalNostrEvent(ctx, NostrKind.TEXT_NOTE, [], "2");
const event_to_add2 = await prepareNormalNostrEvent(ctx, { kind: NostrKind.TEXT_NOTE, content: "2" });
// console.log(event_to_add2.id, event_to_add.id)
await db.addEvent(event_to_add2);
const e2 = await stream.pop() as NostrEvent;

View File

@ -51,9 +51,7 @@ export async function saveProfile(
) {
const event = await prepareNormalNostrEvent(
sender,
NostrKind.META_DATA,
[],
JSON.stringify(profile),
{ kind: NostrKind.META_DATA, content: JSON.stringify(profile) },
);
pool.sendEvent(event);
}

@ -1 +1 @@
Subproject commit a2327172fdf711c2e3bf02d8fefe4b6dae9a2910
Subproject commit 53303f151e4787ec46e1e77584508634129e6cfd

View File

@ -50,9 +50,11 @@ Deno.test("Generate reply event", async () => {
const message1 = await prepareNormalNostrEvent(
userAContext,
NostrKind.DIRECT_MESSAGE,
[],
"text message 1",
{
kind: NostrKind.DIRECT_MESSAGE,
content: "text message 1",
},
);
const replyMessage1WithText = await prepareReplyEvent(

View File

@ -168,23 +168,25 @@ export async function prepareReplyEvent(
return prepareNormalNostrEvent(
sender,
targetEvent.kind,
[
[
"e",
targetEvent.id,
"",
"reply",
],
...ps.map((p) =>
{
kind: targetEvent.kind,
tags: [
[
"p",
p,
] as TagPubKey
),
...tags,
],
content,
"e",
targetEvent.id,
"",
"reply",
],
...ps.map((p) =>
[
"p",
p,
] as TagPubKey
),
...tags,
],
content,
},
);
}