PublishEvent() fixes.

This commit is contained in:
fiatjaf 2022-11-17 09:28:45 -03:00
parent 381ee2cc01
commit 480ee0ef87
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
3 changed files with 10 additions and 4 deletions

View File

@ -24,7 +24,7 @@ for notice := range pool.Notices {
### Listening for events
```go
subId, allEvents, uniqueEvents := pool.Sub(nostr.Filters{
subId, events := pool.Sub(nostr.Filters{
{
Authors: []string{"0ded86bf80c76847320b16f22b7451c08169434837a51ad5fe3b178af6c35f5d"},
Kinds: []int{nostr.KindTextNote}, // or {1}
@ -32,7 +32,7 @@ subId, allEvents, uniqueEvents := pool.Sub(nostr.Filters{
})
go func() {
for event := range uniqueEvents {
for event := range nostr.Unique(events) {
log.Print(event)
}
}()

View File

@ -170,7 +170,7 @@ func (r *Relay) Connect() error {
}
func (r Relay) Publish(event Event) chan Status {
statusChan := make(chan Status)
statusChan := make(chan Status, 4)
go func() {
// 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 {
statusChan <- PublishStatusFailed
close(statusChan)
return
}
statusChan <- PublishStatusSent

View File

@ -149,7 +149,12 @@ func Unique(all chan EventMessage) chan Event {
}
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 == "") {
return nil, status, errors.New("PublishEvent needs either a signed event to publish or to have been configured with a .SecretKey.")