From aa2ac552ea02386ba3cfeacb6ae7c9183f860de5 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 28 Aug 2024 08:43:56 -0300 Subject: [PATCH] support deleting "a" references. --- deleting.go | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/deleting.go b/deleting.go index e68011f..f0be3d9 100644 --- a/deleting.go +++ b/deleting.go @@ -3,6 +3,8 @@ package khatru import ( "context" "fmt" + "strconv" + "strings" "github.com/nbd-wtf/go-nostr" ) @@ -10,10 +12,35 @@ import ( func (rl *Relay) handleDeleteRequest(ctx context.Context, evt *nostr.Event) error { // event deletion -- nip09 for _, tag := range evt.Tags { - if len(tag) >= 2 && tag[0] == "e" { - // first we fetch the event + if len(tag) >= 2 { + var f nostr.Filter + + switch tag[0] { + case "e": + f = nostr.Filter{IDs: []string{tag[1]}} + case "a": + spl := strings.Split(tag[1], ":") + if len(spl) != 3 { + continue + } + kind, err := strconv.Atoi(spl[0]) + if err != nil { + continue + } + author := spl[1] + identifier := spl[2] + f = nostr.Filter{ + Kinds: []int{kind}, + Authors: []string{author}, + Tags: nostr.TagMap{"d": []string{identifier}}, + Until: &evt.CreatedAt, + } + default: + continue + } + for _, query := range rl.QueryEvents { - ch, err := query(ctx, nostr.Filter{IDs: []string{tag[1]}}) + ch, err := query(ctx, f) if err != nil { continue }