PreventTimestampsInThePast() and PreventTimestampsInTheFuture() helpers.

This commit is contained in:
fiatjaf 2023-11-04 18:21:26 -03:00
parent c0848182c4
commit 0ad33f78f1
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -56,3 +56,21 @@ func RestrictToSpecifiedKinds(kinds ...uint16) func(context.Context, *nostr.Even
return true, "event kind not allowed"
}
}
func PreventTimestampsInThePast(thresholdSeconds nostr.Timestamp) func(context.Context, *nostr.Event) (bool, string) {
return func(ctx context.Context, event *nostr.Event) (reject bool, msg string) {
if nostr.Now()-event.CreatedAt > thresholdSeconds {
return true, "event too old"
}
return false, ""
}
}
func PreventTimestampsInTheFuture(thresholdSeconds nostr.Timestamp) func(context.Context, *nostr.Event) (bool, string) {
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"
}
return false, ""
}
}