mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
PublishEvent() fixes.
This commit is contained in:
parent
381ee2cc01
commit
480ee0ef87
@ -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)
|
||||
}
|
||||
}()
|
||||
|
3
relay.go
3
relay.go
@ -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
|
||||
|
||||
|
@ -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.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user