Use event store in relay
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
package zooid
|
package zooid
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
func EnableGroups(instance *Instance) {
|
func EnableGroups(instance *Instance) {
|
||||||
instance.Relay.Info.SupportedNIPs = append(instance.Relay.Info.SupportedNIPs, 29)
|
instance.Relay.Info.SupportedNIPs = append(instance.Relay.Info.SupportedNIPs, 29)
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-9
@@ -1,18 +1,23 @@
|
|||||||
package zooid
|
package zooid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
"iter"
|
|
||||||
"net/http"
|
|
||||||
"context"
|
"context"
|
||||||
|
"iter"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"fiatjaf.com/nostr/khatru"
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
|
"fiatjaf.com/nostr/eventstore"
|
||||||
|
"fiatjaf.com/nostr/khatru"
|
||||||
|
"zooid/sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Instance struct {
|
type Instance struct {
|
||||||
Host string
|
Host string
|
||||||
Config *Config
|
Config *Config
|
||||||
|
Events eventstore.Store
|
||||||
Relay *khatru.Relay
|
Relay *khatru.Relay
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +40,7 @@ func MakeInstance(hostname string) (*Instance, error) {
|
|||||||
instance := &Instance{
|
instance := &Instance{
|
||||||
Host: hostname,
|
Host: hostname,
|
||||||
Config: config,
|
Config: config,
|
||||||
|
Events: &sqlite.SqliteBackend{Path: config.Data.Events},
|
||||||
Relay: khatru.NewRelay(),
|
Relay: khatru.NewRelay(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +52,8 @@ func MakeInstance(hostname string) (*Instance, error) {
|
|||||||
instance.Relay.Info.Software = "https://github.com/coracle-social/zooid"
|
instance.Relay.Info.Software = "https://github.com/coracle-social/zooid"
|
||||||
instance.Relay.Info.Version = "v0.1.0"
|
instance.Relay.Info.Version = "v0.1.0"
|
||||||
|
|
||||||
|
instance.Relay.UseEventstore(instance.Events, 400)
|
||||||
|
|
||||||
instance.Relay.OnConnect = instance.OnConnect
|
instance.Relay.OnConnect = instance.OnConnect
|
||||||
instance.Relay.OnEvent = instance.OnEvent
|
instance.Relay.OnEvent = instance.OnEvent
|
||||||
instance.Relay.StoreEvent = instance.StoreEvent
|
instance.Relay.StoreEvent = instance.StoreEvent
|
||||||
@@ -70,6 +78,16 @@ func MakeInstance(hostname string) (*Instance, error) {
|
|||||||
EnableManagement(instance)
|
EnableManagement(instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize stuff
|
||||||
|
|
||||||
|
if err := os.MkdirAll(instance.Config.Data.Events, 0755); err != nil {
|
||||||
|
log.Fatal("Failed to create event store path:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := instance.Events.Init(); err != nil {
|
||||||
|
log.Fatal("Failed to initialize event store:", err)
|
||||||
|
}
|
||||||
|
|
||||||
return instance, nil
|
return instance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,15 +140,15 @@ func (instance *Instance) OnEvent(ctx context.Context, event nostr.Event) (rejec
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) StoreEvent(ctx context.Context, event nostr.Event) error {
|
func (instance *Instance) StoreEvent(ctx context.Context, event nostr.Event) error {
|
||||||
return nil
|
return instance.Events.SaveEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) ReplaceEvent(ctx context.Context, event nostr.Event) error {
|
func (instance *Instance) ReplaceEvent(ctx context.Context, event nostr.Event) error {
|
||||||
return nil
|
return instance.Events.ReplaceEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) DeleteEvent(ctx context.Context, id nostr.ID) error {
|
func (instance *Instance) DeleteEvent(ctx context.Context, id nostr.ID) error {
|
||||||
return nil
|
return instance.Events.DeleteEvent(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) OnEventSaved(ctx context.Context, event nostr.Event) {
|
func (instance *Instance) OnEventSaved(ctx context.Context, event nostr.Event) {
|
||||||
@@ -145,8 +163,11 @@ func (instance *Instance) OnRequest(ctx context.Context, filter nostr.Filter) (r
|
|||||||
|
|
||||||
func (instance *Instance) QueryStored(ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event] {
|
func (instance *Instance) QueryStored(ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event] {
|
||||||
return func(yield func(nostr.Event) bool) {
|
return func(yield func(nostr.Event) bool) {
|
||||||
// TODO: Implement actual event querying logic
|
for evt := range instance.Events.QueryEvents(filter, 400) {
|
||||||
// For now, return empty sequence
|
if !yield(evt) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
package zooid
|
package zooid
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
func EnableManagement(instance *Instance) {
|
func EnableManagement(instance *Instance) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user