PublishEvent() fixes.
This commit is contained in:
@@ -24,7 +24,7 @@ for notice := range pool.Notices {
|
|||||||
### Listening for events
|
### Listening for events
|
||||||
|
|
||||||
```go
|
```go
|
||||||
subId, allEvents, uniqueEvents := pool.Sub(nostr.Filters{
|
subId, events := pool.Sub(nostr.Filters{
|
||||||
{
|
{
|
||||||
Authors: []string{"0ded86bf80c76847320b16f22b7451c08169434837a51ad5fe3b178af6c35f5d"},
|
Authors: []string{"0ded86bf80c76847320b16f22b7451c08169434837a51ad5fe3b178af6c35f5d"},
|
||||||
Kinds: []int{nostr.KindTextNote}, // or {1}
|
Kinds: []int{nostr.KindTextNote}, // or {1}
|
||||||
@@ -32,7 +32,7 @@ subId, allEvents, uniqueEvents := pool.Sub(nostr.Filters{
|
|||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for event := range uniqueEvents {
|
for event := range nostr.Unique(events) {
|
||||||
log.Print(event)
|
log.Print(event)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
3
relay.go
3
relay.go
@@ -170,7 +170,7 @@ func (r *Relay) Connect() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r Relay) Publish(event Event) chan Status {
|
func (r Relay) Publish(event Event) chan Status {
|
||||||
statusChan := make(chan Status)
|
statusChan := make(chan Status, 4)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// we keep track of this so the OK message can be used to close it
|
// we keep track of this so the OK message can be used to close it
|
||||||
@@ -181,6 +181,7 @@ func (r Relay) Publish(event Event) chan Status {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
statusChan <- PublishStatusFailed
|
statusChan <- PublishStatusFailed
|
||||||
close(statusChan)
|
close(statusChan)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
statusChan <- PublishStatusSent
|
statusChan <- PublishStatusSent
|
||||||
|
|
||||||
|
|||||||
@@ -149,7 +149,12 @@ func Unique(all chan EventMessage) chan Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RelayPool) PublishEvent(evt *Event) (*Event, chan PublishStatus, error) {
|
func (r *RelayPool) PublishEvent(evt *Event) (*Event, chan PublishStatus, error) {
|
||||||
status := make(chan PublishStatus, 1)
|
size := 0
|
||||||
|
r.Relays.Range(func(_ string, _ *Relay) bool {
|
||||||
|
size++
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
status := make(chan PublishStatus, size)
|
||||||
|
|
||||||
if r.SecretKey == nil && (evt.PubKey == "" || evt.Sig == "") {
|
if r.SecretKey == nil && (evt.PubKey == "" || evt.Sig == "") {
|
||||||
return nil, status, errors.New("PublishEvent needs either a signed event to publish or to have been configured with a .SecretKey.")
|
return nil, status, errors.New("PublishEvent needs either a signed event to publish or to have been configured with a .SecretKey.")
|
||||||
|
|||||||
Reference in New Issue
Block a user