mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-12 19:49:56 +02:00
fixing subscription labels and ids.
This commit is contained in:
parent
3f66c60b5f
commit
85fc74fd22
9
relay.go
9
relay.go
@ -385,19 +385,16 @@ func (r *Relay) QuerySync(ctx context.Context, filter Filter) []*Event {
|
||||
}
|
||||
|
||||
func (r *Relay) PrepareSubscription() *Subscription {
|
||||
id := subscriptionIdCounter
|
||||
current := subscriptionIdCounter
|
||||
subscriptionIdCounter++
|
||||
|
||||
sub := &Subscription{
|
||||
return &Subscription{
|
||||
Relay: r,
|
||||
conn: r.Connection,
|
||||
id: id,
|
||||
counter: current,
|
||||
Events: make(chan *Event),
|
||||
EndOfStoredEvents: make(chan struct{}, 1),
|
||||
}
|
||||
|
||||
r.subscriptions.Store(sub.GetID(), sub)
|
||||
return sub
|
||||
}
|
||||
|
||||
func (r *Relay) Close() error {
|
||||
|
@ -7,10 +7,10 @@ import (
|
||||
)
|
||||
|
||||
type Subscription struct {
|
||||
label string
|
||||
id int
|
||||
conn *Connection
|
||||
mutex sync.Mutex
|
||||
label string
|
||||
counter int
|
||||
conn *Connection
|
||||
mutex sync.Mutex
|
||||
|
||||
Relay *Relay
|
||||
Filters Filters
|
||||
@ -35,7 +35,7 @@ func (sub *Subscription) SetLabel(label string) {
|
||||
|
||||
// GetID return the Nostr subscription ID as given to the relay, it will be a sequential number, stringified.
|
||||
func (sub *Subscription) GetID() string {
|
||||
return sub.label + ":" + strconv.Itoa(sub.id)
|
||||
return sub.label + ":" + strconv.Itoa(sub.counter)
|
||||
}
|
||||
|
||||
// Unsub closes the subscription, sending "CLOSE" to relay as in NIP-01.
|
||||
@ -60,6 +60,8 @@ func (sub *Subscription) Sub(ctx context.Context, filters Filters) {
|
||||
// Fire sends the "REQ" command to the relay.
|
||||
// When ctx is cancelled, sub.Unsub() is called, closing the subscription.
|
||||
func (sub *Subscription) Fire(ctx context.Context) error {
|
||||
sub.Relay.subscriptions.Store(sub.GetID(), sub)
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
sub.Context = ctx
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user