From e8637afa3802d18f1dce102ab74d22c69a2117f3 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 20 Aug 2024 10:40:28 -0300 Subject: [PATCH] policies: timestamps policies take time.Duration --- policies/events.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/policies/events.go b/policies/events.go index aa2811a..aa2019b 100644 --- a/policies/events.go +++ b/policies/events.go @@ -5,6 +5,7 @@ import ( "fmt" "slices" "strings" + "time" "github.com/nbd-wtf/go-nostr" ) @@ -79,7 +80,8 @@ func RestrictToSpecifiedKinds(kinds ...uint16) func(context.Context, *nostr.Even } } -func PreventTimestampsInThePast(thresholdSeconds nostr.Timestamp) func(context.Context, *nostr.Event) (bool, string) { +func PreventTimestampsInThePast(threshold time.Duration) func(context.Context, *nostr.Event) (bool, string) { + thresholdSeconds := nostr.Timestamp(threshold.Seconds()) return func(ctx context.Context, event *nostr.Event) (reject bool, msg string) { if nostr.Now()-event.CreatedAt > thresholdSeconds { return true, "event too old" @@ -88,7 +90,8 @@ func PreventTimestampsInThePast(thresholdSeconds nostr.Timestamp) func(context.C } } -func PreventTimestampsInTheFuture(thresholdSeconds nostr.Timestamp) func(context.Context, *nostr.Event) (bool, string) { +func PreventTimestampsInTheFuture(threshold time.Duration) func(context.Context, *nostr.Event) (bool, string) { + thresholdSeconds := nostr.Timestamp(threshold.Seconds()) return func(ctx context.Context, event *nostr.Event) (reject bool, msg string) { if event.CreatedAt-nostr.Now() > thresholdSeconds { return true, "event too much in the future"