nostr publish event fix

This commit is contained in:
gitea
2025-11-06 21:43:09 +01:00
parent 120a04c69f
commit 947fb667cf
7 changed files with 207 additions and 459 deletions
+27 -5
View File
@@ -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;
}
}