diff --git a/src/modules/base/nostr/relay-hub.ts b/src/modules/base/nostr/relay-hub.ts index 486d3f2..7cdd00f 100644 --- a/src/modules/base/nostr/relay-hub.ts +++ b/src/modules/base/nostr/relay-hub.ts @@ -540,9 +540,13 @@ export class RelayHub extends BaseService { const successful = results.filter(result => result.status === 'fulfilled').length const total = results.length - this.emit('eventPublished', { eventId: event.id, success: successful, total }) + // Throw error if no relays accepted the event + if (successful === 0) { + throw new Error(`Failed to publish event - none of the ${total} relay(s) accepted it`) + } + return { success: successful, total } } diff --git a/src/modules/nostr-feed/services/ScheduledEventService.ts b/src/modules/nostr-feed/services/ScheduledEventService.ts index 4911b24..d2ef6b4 100644 --- a/src/modules/nostr-feed/services/ScheduledEventService.ts +++ b/src/modules/nostr-feed/services/ScheduledEventService.ts @@ -499,8 +499,8 @@ export class ScheduledEventService extends BaseService { const result = await this.relayHub.publishEvent(signedEvent) console.log('✅ Task status published to', result.success, '/', result.total, 'relays') - // Optimistically update local state - console.log('🔄 Optimistically updating local state') + // Update local state (publishEvent throws if no relays accepted) + console.log('🔄 Updating local state (event published successfully)') this.handleCompletionEvent(signedEvent) } catch (error) { @@ -562,7 +562,7 @@ export class ScheduledEventService extends BaseService { const result = await this.relayHub.publishEvent(signedEvent) console.log('✅ Deletion request published to', result.success, '/', result.total, 'relays') - // Optimistically remove from local state + // Remove from local state (publishEvent throws if no relays accepted) this._completions.delete(completionKey) console.log('🗑️ Removed completion from local state:', completionKey) @@ -624,7 +624,7 @@ export class ScheduledEventService extends BaseService { const result = await this.relayHub.publishEvent(signedEvent) console.log('✅ Task deletion request published to', result.success, '/', result.total, 'relays') - // Optimistically remove from local state + // Remove from local state (publishEvent throws if no relays accepted) this._scheduledEvents.delete(eventAddress) console.log('🗑️ Removed task from local state:', eventAddress)