fix replaceable handlers to not delete things all the time.

This commit is contained in:
fiatjaf
2023-11-07 14:14:53 -03:00
parent e6078b1a68
commit a15cd4e545
2 changed files with 12 additions and 5 deletions

View File

@@ -38,8 +38,7 @@ func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) error {
if err != nil {
continue
}
previous := <-ch
if previous != nil {
if previous := <-ch; previous != nil && isOlder(previous, evt) {
for _, del := range rl.DeleteEvent {
del(ctx, previous)
}
@@ -54,8 +53,7 @@ func (rl *Relay) AddEvent(ctx context.Context, evt *nostr.Event) error {
if err != nil {
continue
}
previous := <-ch
if previous != nil {
if previous := <-ch; previous != nil && isOlder(previous, evt) {
for _, del := range rl.DeleteEvent {
del(ctx, previous)
}

View File

@@ -5,6 +5,8 @@ import (
"hash/maphash"
"regexp"
"unsafe"
"github.com/nbd-wtf/go-nostr"
)
const (
@@ -26,4 +28,11 @@ func GetAuthed(ctx context.Context) string {
return authedPubkey.(string)
}
func pointerHasher[V any](_ maphash.Seed, k *V) uint64 { return uint64(uintptr(unsafe.Pointer(k))) }
func pointerHasher[V any](_ maphash.Seed, k *V) uint64 {
return uint64(uintptr(unsafe.Pointer(k)))
}
func isOlder(previous, next *nostr.Event) bool {
return previous.CreatedAt < next.CreatedAt ||
(previous.CreatedAt == next.CreatedAt && previous.ID > next.ID)
}