support deleting "a" references.

This commit is contained in:
fiatjaf
2024-08-28 08:43:56 -03:00
parent 4e2b921af9
commit aa2ac552ea

View File

@@ -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
}