Browse Source

commenting works

master
silberengel 8 months ago
parent
commit
c1d60069a8
  1. 1
      src/lib/stores/userStore.ts
  2. 21
      src/lib/utils/nostrEventService.ts

1
src/lib/stores/userStore.ts

@ -210,6 +210,7 @@ export async function loginWithExtension() { @@ -210,6 +210,7 @@ export async function loginWithExtension() {
console.log("Login with extension - setting userStore with:", userState);
userStore.set(userState);
userPubkey.set(user.pubkey);
// Update relay stores with the new user's relays
try {

21
src/lib/utils/nostrEventService.ts

@ -2,11 +2,10 @@ import { nip19 } from "nostr-tools"; @@ -2,11 +2,10 @@ import { nip19 } from "nostr-tools";
import { getEventHash, signEvent, prefixNostrAddresses } from "./nostrUtils";
import { get } from "svelte/store";
import { goto } from "$app/navigation";
import type { NDKEvent } from "./nostrUtils";
import { EVENT_KINDS, TIME_CONSTANTS, TIMEOUTS } from "./search_constants";
import { activeInboxRelays, activeOutboxRelays } from "$lib/ndk";
import { ndkInstance } from "$lib/ndk";
import { NDKRelaySet } from "@nostr-dev-kit/ndk";
import { NDKRelaySet, NDKEvent } from "@nostr-dev-kit/ndk";
export interface RootEventInfo {
rootId: string;
@ -360,12 +359,12 @@ export async function createSignedEvent( @@ -360,12 +359,12 @@ export async function createSignedEvent(
/**
* Publishes an event to relays using the new relay management system
* @param event The event to publish
* @param event The event to publish (can be NDKEvent or plain event object)
* @param relayUrls Array of relay URLs to publish to
* @returns Promise that resolves to array of successful relay URLs
*/
export async function publishEvent(
event: NDKEvent,
event: NDKEvent | any,
relayUrls: string[],
): Promise<string[]> {
const successfulRelays: string[] = [];
@ -379,15 +378,25 @@ export async function publishEvent( @@ -379,15 +378,25 @@ export async function publishEvent(
const relaySet = NDKRelaySet.fromRelayUrls(relayUrls, ndk);
try {
// If event is a plain object, create an NDKEvent from it
let ndkEvent: NDKEvent;
if (event.publish && typeof event.publish === 'function') {
// It's already an NDKEvent
ndkEvent = event;
} else {
// It's a plain event object, create NDKEvent
ndkEvent = new NDKEvent(ndk, event);
}
// Publish with timeout
await event.publish(relaySet).withTimeout(5000);
await ndkEvent.publish(relaySet).withTimeout(5000);
// For now, assume all relays were successful
// In a more sophisticated implementation, you'd track individual relay responses
successfulRelays.push(...relayUrls);
console.debug("[nostrEventService] Published event successfully:", {
eventId: event.id,
eventId: ndkEvent.id,
relayCount: relayUrls.length,
successfulRelays
});

Loading…
Cancel
Save