mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-01 19:11:05 +02:00
remove extra subscription after publishing an event to check if it is there.
just assume all relays will return OK.
This commit is contained in:
22
relay.go
22
relay.go
@ -274,10 +274,6 @@ func (r *Relay) Publish(ctx context.Context, event Event) (Status, error) {
|
||||
return status, err
|
||||
}
|
||||
|
||||
sub := r.PrepareSubscription(ctx)
|
||||
sub.SetLabel("publish-check")
|
||||
sub.Filters = Filters{Filter{IDs: []string{event.ID}}}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done(): // this will be called when we get an OK
|
||||
@ -289,24 +285,6 @@ func (r *Relay) Publish(ctx context.Context, event Event) (Status, error) {
|
||||
case <-r.connectionContext.Done():
|
||||
// same as above, but when the relay loses connectivity entirely
|
||||
return status, err
|
||||
case <-time.After(4 * time.Second):
|
||||
// if we don't get an OK after 4 seconds, try to subscribe to the event
|
||||
if err := sub.Fire(); err != nil {
|
||||
InfoLogger.Printf("failed to subscribe to just published event %s at %s: %s", event.ID, r.URL, err)
|
||||
}
|
||||
case receivedEvent := <-sub.Events:
|
||||
if receivedEvent == nil {
|
||||
// channel is closed
|
||||
return status, err
|
||||
}
|
||||
|
||||
if receivedEvent.ID == event.ID {
|
||||
// we got a success, so update our status and proceed to return
|
||||
mu.Lock()
|
||||
status = PublishStatusSucceeded
|
||||
mu.Unlock()
|
||||
return status, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user