mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-09-28 04:49:33 +02:00
init and close quibbles.
This commit is contained in:
@@ -40,33 +40,12 @@ type NoticeMessage struct {
|
|||||||
Relay string
|
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
|
// New creates a new RelayPool with no relays in it
|
||||||
func New() *RelayPool {
|
func New() *RelayPool {
|
||||||
return &RelayPool{
|
return &RelayPool{
|
||||||
Relays: make(map[string]Policy),
|
Relays: make(map[string]Policy),
|
||||||
websockets: make(map[string]*websocket.Conn),
|
websockets: make(map[string]*websocket.Conn),
|
||||||
|
subscriptions: make(map[string]*Subscription),
|
||||||
|
|
||||||
Notices: make(chan *NoticeMessage),
|
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) {
|
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()
|
go subscription.startHandlingUnique()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user