relay options passed to pool should take the relay sometimes.
This commit is contained in:
16
relay.go
16
relay.go
@@ -40,9 +40,9 @@ type Relay struct {
|
||||
connectionContextCancel context.CancelCauseFunc
|
||||
|
||||
challenge string // NIP-42 challenge, we only keep the last
|
||||
authHandler func(context.Context, *Event) error
|
||||
noticeHandler func(string) // NIP-01 NOTICEs
|
||||
customHandler func(string) // nonstandard unparseable messages
|
||||
authHandler func(context.Context, *Relay, *Event) error
|
||||
noticeHandler func(*Relay, string) // NIP-01 NOTICEs
|
||||
customHandler func(string) // nonstandard unparseable messages
|
||||
okCallbacks map[ID]okcallback
|
||||
okCallbacksMutex sync.Mutex
|
||||
subscriptionChannelCloseQueue chan *Subscription
|
||||
@@ -85,11 +85,11 @@ func RelayConnect(ctx context.Context, url string, opts RelayOptions) (*Relay, e
|
||||
|
||||
type RelayOptions struct {
|
||||
// AuthHandler is fired when an AUTH message is received. It is given the AUTH event, unsigned, and expects you to sign it.
|
||||
AuthHandler func(context.Context, *Event) error
|
||||
AuthHandler func(context.Context, *Relay, *Event) error
|
||||
|
||||
// NoticeHandler just takes notices and is expected to do something with them.
|
||||
// When not given defaults to logging the notices.
|
||||
NoticeHandler func(notice string)
|
||||
NoticeHandler func(relay *Relay, notice string)
|
||||
|
||||
// CustomHandler, if given, must be a function that handles any relay message
|
||||
// that couldn't be parsed as a standard envelope.
|
||||
@@ -180,7 +180,7 @@ func (r *Relay) handleMessage(message string) {
|
||||
case *NoticeEnvelope:
|
||||
// see WithNoticeHandler
|
||||
if r.noticeHandler != nil {
|
||||
r.noticeHandler(string(*env))
|
||||
r.noticeHandler(r, string(*env))
|
||||
} else {
|
||||
log.Printf("NOTICE from %s: '%s'\n", r.URL, string(*env))
|
||||
}
|
||||
@@ -190,7 +190,9 @@ func (r *Relay) handleMessage(message string) {
|
||||
}
|
||||
r.challenge = *env.Challenge
|
||||
if r.authHandler != nil {
|
||||
r.Auth(r.Context(), r.authHandler)
|
||||
r.Auth(r.Context(), func(ctx context.Context, evt *Event) error {
|
||||
return r.authHandler(ctx, r, evt)
|
||||
})
|
||||
}
|
||||
case *EventEnvelope:
|
||||
// we already have the subscription from the pre-check above, so we can just reuse it
|
||||
|
||||
Reference in New Issue
Block a user