mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-09-17 16:53:32 +02:00
fix replaceable handlers to not delete things all the time.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
11
utils.go
11
utils.go
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user