nostr publish event fix
This commit is contained in:
@@ -238,7 +238,7 @@ class NostrService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Publishes an event to all connected relays.
|
||||
/// Publishes an event to all enabled relays.
|
||||
///
|
||||
/// [event] - The Nostr event to publish.
|
||||
///
|
||||
@@ -247,14 +247,36 @@ class NostrService {
|
||||
final results = <String, bool>{};
|
||||
|
||||
for (final relay in _relays) {
|
||||
if (relay.isConnected) {
|
||||
// Only publish to enabled relays
|
||||
if (!relay.isEnabled) {
|
||||
results[relay.url] = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to connect if not already connected
|
||||
if (!relay.isConnected) {
|
||||
try {
|
||||
await publishEvent(event, relay.url);
|
||||
results[relay.url] = true;
|
||||
final stream = await connectRelay(relay.url).timeout(
|
||||
const Duration(seconds: 3),
|
||||
onTimeout: () {
|
||||
throw Exception('Connection timeout');
|
||||
},
|
||||
);
|
||||
// Start listening to establish connection, then cancel immediately
|
||||
final subscription = stream.listen(null);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
subscription.cancel();
|
||||
} catch (e) {
|
||||
results[relay.url] = false;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
// Publish to the relay
|
||||
try {
|
||||
await publishEvent(event, relay.url);
|
||||
results[relay.url] = true;
|
||||
} catch (e) {
|
||||
results[relay.url] = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user