Adds NIP-33 support for replaceable events.

This commit is contained in:
Steve Perkins
2023-03-31 10:03:35 -04:00
committed by fiatjaf_
parent 7ea3cd5431
commit a82e5edb0d
5 changed files with 72 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ package sqlite3
import (
"encoding/json"
"fmt"
"github.com/fiatjaf/relayer/storage"
"github.com/nbd-wtf/go-nostr"
@@ -16,6 +17,13 @@ func (b *SQLite3Backend) SaveEvent(evt *nostr.Event) error {
// delete past recommend_server events equal to this one
b.DB.Exec(`DELETE FROM event WHERE pubkey = $1 AND kind = $2 AND content = $3`,
evt.PubKey, evt.Kind, evt.Content)
} else if evt.Kind >= 30000 && evt.Kind < 40000 {
// NIP-33
d := evt.Tags.GetFirst([]string{"d"})
if d != nil {
tagsLike := fmt.Sprintf(`%%"d","%s"%%`, d.Value())
b.DB.Exec(`DELETE FROM event WHERE pubkey = $1 AND kind = $2 AND tags LIKE $3`, evt.PubKey, evt.Kind, tagsLike)
}
}
// insert