This commit is contained in:
@@ -18,6 +18,7 @@ require (
|
||||
buf.build/go/protovalidate v0.13.1 // indirect
|
||||
buf.build/go/protoyaml v0.6.0 // indirect
|
||||
cel.dev/expr v0.24.0 // indirect
|
||||
fiatjaf.com/lib v0.3.6 // indirect
|
||||
github.com/ImVexed/fasturl v0.0.0-20230304231329-4e41488060f3 // indirect
|
||||
github.com/andybalholm/brotli v1.1.1 // indirect
|
||||
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
|
||||
@@ -113,4 +114,4 @@ require (
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
replace fiatjaf.com/nostr => gitea.coracle.social/Coracle/nostrlib v0.0.0-20260313164927-662e7d271c47
|
||||
replace fiatjaf.com/nostr => gitea.coracle.social/Coracle/nostrlib v0.0.0-20260414151249-4daeb8737c1c
|
||||
|
||||
@@ -8,8 +8,12 @@ cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY=
|
||||
cel.dev/expr v0.24.0/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw=
|
||||
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
||||
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||
fiatjaf.com/lib v0.3.6 h1:GRZNSxHI2EWdjSKVuzaT+c0aifLDtS16SzkeJaHyJfY=
|
||||
fiatjaf.com/lib v0.3.6/go.mod h1:UlHaZvPHj25PtKLh9GjZkUHRmQ2xZ8Jkoa4VRaLeeQ8=
|
||||
gitea.coracle.social/Coracle/nostrlib v0.0.0-20260313164927-662e7d271c47 h1:Pg/8ZXG2diV3uWbgt3mcAWF2ifL4FZXwotieokY8TBA=
|
||||
gitea.coracle.social/Coracle/nostrlib v0.0.0-20260313164927-662e7d271c47/go.mod h1:ue7yw0zHfZj23Ml2kVSdBx0ENEaZiuvGxs/8VEN93FU=
|
||||
gitea.coracle.social/Coracle/nostrlib v0.0.0-20260414151249-4daeb8737c1c h1:RqKwqUz1R3LQC2IcsdsyYHEUAZACIAKYxGuntyBCGw8=
|
||||
gitea.coracle.social/Coracle/nostrlib v0.0.0-20260414151249-4daeb8737c1c/go.mod h1:1cmygNC87Pw06/WjkZqDV+Xo6rV10kpTjzuayosIX4Y=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||
|
||||
+9
-8
@@ -294,17 +294,17 @@ func (events *EventStore) SaveEvent(evt nostr.Event) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (events *EventStore) ReplaceEvent(evt nostr.Event) error {
|
||||
func (events *EventStore) ReplaceEvent(evt nostr.Event) ([]nostr.Event, error) {
|
||||
filter := nostr.Filter{Kinds: []nostr.Kind{evt.Kind}, Authors: []nostr.PubKey{evt.PubKey}}
|
||||
if evt.Kind.IsAddressable() {
|
||||
filter.Tags = nostr.TagMap{"d": []string{evt.Tags.GetD()}}
|
||||
}
|
||||
|
||||
shouldSave := true
|
||||
shouldDelete := make([]nostr.ID, 0)
|
||||
shouldDelete := make([]nostr.Event, 0)
|
||||
for previous := range events.QueryEvents(filter, 1) {
|
||||
if previous.CreatedAt <= evt.CreatedAt {
|
||||
shouldDelete = append(shouldDelete, previous.ID)
|
||||
shouldDelete = append(shouldDelete, previous)
|
||||
} else {
|
||||
shouldSave = false
|
||||
}
|
||||
@@ -312,16 +312,16 @@ func (events *EventStore) ReplaceEvent(evt nostr.Event) error {
|
||||
|
||||
if shouldSave {
|
||||
if err := events.SaveEvent(evt); err != nil && err != eventstore.ErrDupEvent {
|
||||
return fmt.Errorf("failed to save: %w", err)
|
||||
return nil, fmt.Errorf("failed to save: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Wait until the end to delete old events, just in case our new one doesn't save
|
||||
for _, id := range shouldDelete {
|
||||
events.DeleteEvent(id)
|
||||
for _, previous := range shouldDelete {
|
||||
events.DeleteEvent(previous.ID)
|
||||
}
|
||||
|
||||
return nil
|
||||
return shouldDelete, nil
|
||||
}
|
||||
|
||||
func (events *EventStore) CountEvents(filter nostr.Filter) (uint32, error) {
|
||||
@@ -344,7 +344,8 @@ func (events *EventStore) CountEvents(filter nostr.Filter) (uint32, error) {
|
||||
|
||||
func (events *EventStore) StoreEvent(event nostr.Event) error {
|
||||
if event.Kind.IsReplaceable() || event.Kind.IsAddressable() {
|
||||
return events.ReplaceEvent(event)
|
||||
_, err := events.ReplaceEvent(event)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := events.SaveEvent(event); err != nil && err != eventstore.ErrDupEvent {
|
||||
|
||||
@@ -391,7 +391,7 @@ func TestEventStore_ReplaceEvent(t *testing.T) {
|
||||
}
|
||||
event1.Sign(secret)
|
||||
|
||||
err := store.ReplaceEvent(event1)
|
||||
_, err := store.ReplaceEvent(event1)
|
||||
if err != nil {
|
||||
t.Errorf("ReplaceEvent() error = %v", err)
|
||||
}
|
||||
@@ -405,7 +405,7 @@ func TestEventStore_ReplaceEvent(t *testing.T) {
|
||||
}
|
||||
event2.Sign(secret)
|
||||
|
||||
err = store.ReplaceEvent(event2)
|
||||
_, err = store.ReplaceEvent(event2)
|
||||
if err != nil {
|
||||
t.Errorf("ReplaceEvent() error = %v", err)
|
||||
}
|
||||
@@ -452,7 +452,7 @@ func TestEventStore_ReplaceEvent_OlderEvent(t *testing.T) {
|
||||
}
|
||||
event2.Sign(secret)
|
||||
|
||||
err := store.ReplaceEvent(event2)
|
||||
_, err := store.ReplaceEvent(event2)
|
||||
if err != nil {
|
||||
t.Errorf("ReplaceEvent() with older event error = %v", err)
|
||||
}
|
||||
|
||||
+2
-2
@@ -101,7 +101,7 @@ func MakeInstance(filename string) (*Instance, error) {
|
||||
|
||||
// Expiration
|
||||
|
||||
instance.Relay.StartExpirationManager(instance.Relay.QueryStored, instance.Relay.DeleteEvent)
|
||||
instance.Relay.StartExpirationManager(instance.Relay.QueryStored, instance.Relay.DeleteEvent, nil)
|
||||
|
||||
// HTTP request handling
|
||||
|
||||
@@ -264,7 +264,7 @@ func (instance *Instance) StoreEvent(ctx context.Context, event nostr.Event) err
|
||||
return instance.Events.StoreEvent(event)
|
||||
}
|
||||
|
||||
func (instance *Instance) ReplaceEvent(ctx context.Context, event nostr.Event) error {
|
||||
func (instance *Instance) ReplaceEvent(ctx context.Context, event nostr.Event) ([]nostr.Event, error) {
|
||||
return instance.Events.ReplaceEvent(event)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user