mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-17 21:32:55 +01:00
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package khatru
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/nbd-wtf/go-nostr"
|
|
)
|
|
|
|
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
|
|
for _, query := range rl.QueryEvents {
|
|
ch, err := query(ctx, nostr.Filter{IDs: []string{tag[1]}})
|
|
if err != nil {
|
|
continue
|
|
}
|
|
target := <-ch
|
|
if target == nil {
|
|
continue
|
|
}
|
|
// got the event, now check if the user can delete it
|
|
acceptDeletion := target.PubKey == evt.PubKey
|
|
var msg string
|
|
if acceptDeletion == false {
|
|
msg = "you are not the author of this event"
|
|
}
|
|
// but if we have a function to overwrite this outcome, use that instead
|
|
for _, odo := range rl.OverwriteDeletionOutcome {
|
|
acceptDeletion, msg = odo(ctx, target, evt)
|
|
}
|
|
if acceptDeletion {
|
|
// delete it
|
|
for _, del := range rl.DeleteEvent {
|
|
del(ctx, target)
|
|
}
|
|
} else {
|
|
// fail and stop here
|
|
return fmt.Errorf("blocked: %s", msg)
|
|
}
|
|
|
|
// don't try to query this same event again
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|