fixes and tweaks from nak port work.

This commit is contained in:
fiatjaf
2025-04-21 08:35:19 -03:00
parent ee2d618285
commit 3d595039cc
10 changed files with 34 additions and 19 deletions

View File

@@ -65,7 +65,7 @@ type Relay struct {
OnEventSaved func(ctx context.Context, event nostr.Event)
OnEphemeralEvent func(ctx context.Context, event nostr.Event)
OnRequest func(ctx context.Context, filter nostr.Filter) (reject bool, msg string)
OnCountFilter func(ctx context.Context, filter nostr.Filter) (reject bool, msg string)
OnCount func(ctx context.Context, filter nostr.Filter) (reject bool, msg string)
QueryStored func(ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event]
Count func(ctx context.Context, filter nostr.Filter) (uint32, error)
CountHLL func(ctx context.Context, filter nostr.Filter, offset int) (uint32, *hyperloglog.HyperLogLog, error)

View File

@@ -39,8 +39,8 @@ func (rl *Relay) handleRequest(ctx context.Context, id string, eose *sync.WaitGr
func (rl *Relay) handleCountRequest(ctx context.Context, ws *WebSocket, filter nostr.Filter) uint32 {
// check if we'll reject this filter
if nil != rl.OnCountFilter {
if rejecting, msg := rl.OnCountFilter(ctx, filter); rejecting {
if nil != rl.OnCount {
if rejecting, msg := rl.OnCount(ctx, filter); rejecting {
ws.WriteJSON(nostr.NoticeEnvelope(msg))
return 0
}
@@ -65,8 +65,8 @@ func (rl *Relay) handleCountRequestWithHLL(
offset int,
) (uint32, *hyperloglog.HyperLogLog) {
// check if we'll reject this filter
if nil != rl.OnCountFilter {
if rejecting, msg := rl.OnCountFilter(ctx, filter); rejecting {
if nil != rl.OnCount {
if rejecting, msg := rl.OnCount(ctx, filter); rejecting {
ws.WriteJSON(nostr.NoticeEnvelope(msg))
return 0, nil
}