Introduce ProcessDelete method in database package; update go.mod with database.orly module replacements across packages
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"encoders.orly/envelopes/eventenvelope"
|
||||
"encoders.orly/kind"
|
||||
"lol.mleku.dev/chk"
|
||||
"lol.mleku.dev/log"
|
||||
utils "utils.orly"
|
||||
@@ -53,6 +54,10 @@ func (l *Listener) HandleEvent(c context.Context, msg []byte) (
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
// if the event is a delete, process the delete
|
||||
if env.E.Kind == kind.EventDeletion.K {
|
||||
|
||||
}
|
||||
// check if the event was deleted
|
||||
//
|
||||
|
||||
@@ -5,6 +5,7 @@ go 1.25.0
|
||||
replace (
|
||||
crypto.orly => ../crypto
|
||||
encoders.orly => ../encoders
|
||||
database.orly => ../database
|
||||
interfaces.orly => ../interfaces
|
||||
next.orly.dev => ../../
|
||||
protocol.orly => ../protocol
|
||||
|
||||
@@ -26,6 +26,7 @@ require (
|
||||
replace (
|
||||
acl.orly => ../acl
|
||||
crypto.orly => ../crypto
|
||||
database.orly => ../database
|
||||
encoders.orly => ../encoders
|
||||
interfaces.orly => ../interfaces
|
||||
next.orly.dev => ../../
|
||||
|
||||
@@ -5,6 +5,7 @@ go 1.25.0
|
||||
replace (
|
||||
acl.orly => ../acl
|
||||
crypto.orly => ../crypto
|
||||
database.orly => ../database
|
||||
encoders.orly => ../encoders
|
||||
interfaces.orly => ../interfaces
|
||||
next.orly.dev => ../../
|
||||
|
||||
78
pkg/database/process-delete.go
Normal file
78
pkg/database/process-delete.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
"database.orly/indexes/types"
|
||||
"encoders.orly/event"
|
||||
"encoders.orly/filter"
|
||||
"encoders.orly/ints"
|
||||
"encoders.orly/kind"
|
||||
"encoders.orly/tag"
|
||||
"interfaces.orly/store"
|
||||
"lol.mleku.dev/chk"
|
||||
)
|
||||
|
||||
func (d *D) ProcessDelete(ev *event.E, admins [][]byte) (err error) {
|
||||
eTags := ev.Tags.GetAll([]byte("e"))
|
||||
aTags := ev.Tags.GetAll([]byte("a"))
|
||||
kTags := ev.Tags.GetAll([]byte("k"))
|
||||
// if there are no e or a tags, we assume the intent is to delete all
|
||||
// replaceable events of the kinds specified by the k tags for the pubkey of
|
||||
// the delete event.
|
||||
if len(eTags) == 0 && len(aTags) == 0 {
|
||||
// parse the kind tags
|
||||
var kinds []*kind.K
|
||||
for _, k := range kTags {
|
||||
kv := k.Value()
|
||||
iv := ints.New(0)
|
||||
if _, err = iv.Unmarshal(kv); chk.E(err) {
|
||||
continue
|
||||
}
|
||||
kinds = append(kinds, kind.New(iv.N))
|
||||
}
|
||||
var idxs []Range
|
||||
if idxs, err = GetIndexesFromFilter(
|
||||
&filter.F{
|
||||
Authors: tag.NewFromBytesSlice(ev.Pubkey),
|
||||
Kinds: kind.NewS(kinds...),
|
||||
},
|
||||
); chk.E(err) {
|
||||
return
|
||||
}
|
||||
var sers types.Uint40s
|
||||
for _, idx := range idxs {
|
||||
var s types.Uint40s
|
||||
if s, err = d.GetSerialsByRange(idx); chk.E(err) {
|
||||
return
|
||||
}
|
||||
sers = append(sers, s...)
|
||||
}
|
||||
if len(sers) > 0 {
|
||||
var idPkTss []*store.IdPkTs
|
||||
var tmp []*store.IdPkTs
|
||||
if tmp, err = d.GetFullIdPubkeyBySerials(sers); chk.E(err) {
|
||||
return
|
||||
}
|
||||
idPkTss = append(idPkTss, tmp...)
|
||||
// sort by timestamp, so the first is the oldest, so we can collect
|
||||
// all of them until the delete event created_at.
|
||||
sort.Slice(
|
||||
idPkTss, func(i, j int) bool {
|
||||
return idPkTss[i].Ts > idPkTss[j].Ts
|
||||
},
|
||||
)
|
||||
for _, v := range idPkTss {
|
||||
if v.Ts < ev.CreatedAt {
|
||||
if err = d.DeleteEvent(
|
||||
context.Background(), v.Id,
|
||||
); chk.E(err) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -31,6 +31,7 @@ require (
|
||||
replace (
|
||||
acl.orly => ../acl
|
||||
crypto.orly => ../crypto
|
||||
database.orly => ../database
|
||||
encoders.orly => ../encoders
|
||||
interfaces.orly => ../interfaces
|
||||
next.orly.dev => ../../
|
||||
|
||||
Reference in New Issue
Block a user