Browse Source

unified the kind24 publishing

master
silberengel 7 months ago
parent
commit
49e8293fbe
  1. 26
      src/lib/utils/kind24_utils.ts

26
src/lib/utils/kind24_utils.ts

@ -4,6 +4,7 @@ import { userStore } from "../stores/userStore";
import { NDKEvent, NDKRelaySet, NDKUser } from "@nostr-dev-kit/ndk"; import { NDKEvent, NDKRelaySet, NDKUser } from "@nostr-dev-kit/ndk";
import type NDK from "@nostr-dev-kit/ndk"; import type NDK from "@nostr-dev-kit/ndk";
import { nip19 } from "nostr-tools"; import { nip19 } from "nostr-tools";
import { createSignedEvent } from "./nostrEventService.ts";
/** /**
* Fetches user's outbox relays from NIP-65 relay list * Fetches user's outbox relays from NIP-65 relay list
@ -140,10 +141,6 @@ export async function createKind24Reply(
return { success: false, error: "No relays available for publishing" }; return { success: false, error: "No relays available for publishing" };
} }
// Create the kind 24 event
const event = new NDKEvent(ndk);
event.kind = 24;
// Build content with quoted message if replying // Build content with quoted message if replying
let finalContent = content; let finalContent = content;
if (originalEvent) { if (originalEvent) {
@ -155,13 +152,9 @@ export async function createKind24Reply(
const quotedContent = originalEvent.content ? originalEvent.content.slice(0, 200) : "No content"; const quotedContent = originalEvent.content ? originalEvent.content.slice(0, 200) : "No content";
// Use a more visible quote format with a clickable link // Use a more visible quote format with a clickable link
finalContent = `> QUOTED: ${quotedContent}\n> LINK: ${nevent}\n\n${content}`; finalContent = `> QUOTED: ${quotedContent}\n> LINK: ${nevent}\n\n${content}`;
} }
event.content = finalContent; // Build tags for the kind 24 event
event.created_at = Math.floor(Date.now() / 1000);
// Add p tag for recipient with relay URL
const tags: string[][] = [ const tags: string[][] = [
["p", recipientPubkey, prioritizedRelays[0]] // Use first relay as primary ["p", recipientPubkey, prioritizedRelays[0]] // Use first relay as primary
]; ];
@ -175,11 +168,16 @@ export async function createKind24Reply(
tags.push(["q", nevent, prioritizedRelays[0]]); tags.push(["q", nevent, prioritizedRelays[0]]);
} }
event.tags = tags; // Create and sign the event using the unified function (includes expiration tag)
event.pubkey = ndk.activeUser.pubkey; const { event: signedEventData } = await createSignedEvent(
finalContent,
// Sign the event ndk.activeUser.pubkey,
await event.sign(); 24,
tags
);
// Create NDKEvent from the signed event data
const event = new NDKEvent(ndk, signedEventData);
// Publish to relays // Publish to relays
const relaySet = NDKRelaySet.fromRelayUrls(prioritizedRelays, ndk); const relaySet = NDKRelaySet.fromRelayUrls(prioritizedRelays, ndk);

Loading…
Cancel
Save