-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unsubscribe to relay upon notice message, expose closed message…
…, add optional send close message to unsubscribe
- Loading branch information
Showing
3 changed files
with
9 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:nostr_dart/nostr_dart.dart'; | ||
import 'package:nostr_dart/src/model/closed_message.dart'; | ||
|
||
/// Requests stored [EventMessage]s from the provided [NostrRelay] using [RequestMessage]. | ||
/// Requests stored [RelayMessage]s from the provided [NostrRelay] using [RequestMessage]. | ||
/// | ||
/// Stored events are those controlled by the `limit` property of a filter | ||
/// and are returned before the [EoseMessage]. | ||
/// | ||
/// Upon receiving the stored events, the subscription is closed. If you | ||
/// need to keep the subscription to receive real-time [EventMessage]s, consider | ||
/// need to keep the subscription to receive real-time [RelayMessage]s, consider | ||
/// using [collectStoredEvents] instead. | ||
Stream<EventMessage> requestEvents( | ||
Stream<RelayMessage> requestEvents( | ||
RequestMessage requestMessage, | ||
NostrRelay relay, | ||
) async* { | ||
final NostrSubscription subscription = relay.subscribe(requestMessage); | ||
|
||
await for (final message in subscription.messages) { | ||
if (message is EventMessage) { | ||
yield message; | ||
} else if (message is EoseMessage || message is ClosedMessage) { | ||
relay.unsubscribe(subscription.id); | ||
yield message; | ||
if (message is EoseMessage || message is ClosedMessage || message is NoticeMessage) { | ||
relay.unsubscribe(subscription.id, sendCloseMessage: message is EoseMessage); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters