mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
init and close quibbles.
This commit is contained in:
parent
b5e7e446fb
commit
9736da1a8c
@ -40,33 +40,12 @@ type NoticeMessage struct {
|
||||
Relay string
|
||||
}
|
||||
|
||||
func (nm *NoticeMessage) UnmarshalJSON(b []byte) error {
|
||||
var temp []json.RawMessage
|
||||
if err := json.Unmarshal(b, &temp); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(temp) < 2 {
|
||||
return errors.New("message is not an array of 2 or more")
|
||||
}
|
||||
var tag string
|
||||
if err := json.Unmarshal(temp[0], &tag); err != nil {
|
||||
return err
|
||||
}
|
||||
if tag != "notice" {
|
||||
return errors.New("tag is not 'notice'")
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(temp[1], &nm.Message); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// New creates a new RelayPool with no relays in it
|
||||
func New() *RelayPool {
|
||||
return &RelayPool{
|
||||
Relays: make(map[string]Policy),
|
||||
websockets: make(map[string]*websocket.Conn),
|
||||
Relays: make(map[string]Policy),
|
||||
websockets: make(map[string]*websocket.Conn),
|
||||
subscriptions: make(map[string]*Subscription),
|
||||
|
||||
Notices: make(chan *NoticeMessage),
|
||||
}
|
||||
|
@ -30,7 +30,12 @@ func (subscription Subscription) Unsub() {
|
||||
})
|
||||
}
|
||||
|
||||
close(subscription.Events)
|
||||
if subscription.Events != nil {
|
||||
close(subscription.Events)
|
||||
}
|
||||
if subscription.UniqueEvents != nil {
|
||||
close(subscription.UniqueEvents)
|
||||
}
|
||||
}
|
||||
|
||||
func (subscription Subscription) Sub(filter *filter.EventFilter) {
|
||||
@ -46,7 +51,7 @@ func (subscription Subscription) Sub(filter *filter.EventFilter) {
|
||||
})
|
||||
}
|
||||
|
||||
if subscription.started {
|
||||
if !subscription.started {
|
||||
go subscription.startHandlingUnique()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user