khatru: update docs again, now it seems to be mostly up to date.
This commit is contained in:
@@ -46,9 +46,9 @@ func startPollingGame(relay *khatru.Relay) {
|
||||
relay.BroadcastEvent(evt)
|
||||
|
||||
// just calling BroadcastEvent won't cause this event to be be stored,
|
||||
// if for any reason you want to store these events you must call the store functions manually
|
||||
for _, store := range relay.StoreEvent {
|
||||
store(context.TODO(), evt)
|
||||
// if for any reason you want to store these events you must call the store function manually
|
||||
if relay.StoreEvent != nil {
|
||||
relay.StoreEvent(context.TODO(), evt)
|
||||
}
|
||||
}
|
||||
if newStatus.TeamB > current.TeamB {
|
||||
|
||||
@@ -69,12 +69,13 @@ func handleWeatherQuery(ctx context.Context, filter nostr.Filter) iter.Seq[nostr
|
||||
}
|
||||
}
|
||||
evt.Sign(global.RelaySecretKey)
|
||||
ch <- evt
|
||||
if !yield(evt) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
return ch, nil
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -16,7 +16,7 @@ func main () {
|
||||
// other stuff here
|
||||
}
|
||||
|
||||
func handleEvent(ctx context.Context, event *nostr.Event) error {
|
||||
func handleEvent(ctx context.Context, event nostr.Event) error {
|
||||
// store each event as a file on google drive
|
||||
_, err := gdriveService.Files.Create(googledrive.CreateOptions{
|
||||
Name: event.ID, // with the name set to their id
|
||||
@@ -25,12 +25,9 @@ func handleEvent(ctx context.Context, event *nostr.Event) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func handleQuery(ctx context.Context, filter nostr.Filter) (ch chan *nostr.Event, err error) {
|
||||
// QueryEvents functions are expected to return a channel
|
||||
ch := make(chan *nostr.Event)
|
||||
|
||||
// and they can do their query asynchronously, emitting events to the channel as they come
|
||||
go func () {
|
||||
func handleQuery(ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event] {
|
||||
// QueryEvents functions return an iterator
|
||||
return func(yield func(nostr.Event) bool) {
|
||||
if len(filter.IDs) > 0 {
|
||||
// if the query is for ids we can do a simpler name match
|
||||
for _, id := range filter.IDS {
|
||||
@@ -40,7 +37,9 @@ func handleQuery(ctx context.Context, filter nostr.Filter) (ch chan *nostr.Event
|
||||
if len(results) > 0 {
|
||||
var evt nostr.Event
|
||||
json.Unmarshal(results[0].Body, &evt)
|
||||
ch <- evt
|
||||
if !yield(evt) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -53,14 +52,14 @@ func handleQuery(ctx context.Context, filter nostr.Filter) (ch chan *nostr.Event
|
||||
var evt nostr.Event
|
||||
json.Unmarshal(results[0].Body, &evt)
|
||||
if filter.Match(evt) {
|
||||
ch <- evt
|
||||
if !yield(evt) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return ch, nil
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -25,9 +25,24 @@ func main () {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
relay.StoreEvent = policies.SeqStore(normal.SaveEvent, search.SaveEvent)
|
||||
relay.QueryStored = policies.SeqQuery(normal.QueryEvents, search.QueryEvents)
|
||||
relay.DeleteEvent = policies.SeqDelete(normal.DeleteEvent, search.DeleteEvent)
|
||||
relay.StoreEvent = func(ctx context.Context, evt nostr.Event) error {
|
||||
if err := normal.SaveEvent(evt); err != nil {
|
||||
return err
|
||||
}
|
||||
return search.SaveEvent(evt)
|
||||
}
|
||||
relay.QueryStored = func(ctx context.Context, filter nostr.Filter) iter.Seq[nostr.Event] {
|
||||
if filter.Search != "" {
|
||||
return search.QueryEvents(filter)
|
||||
}
|
||||
return normal.QueryEvents(filter)
|
||||
}
|
||||
relay.DeleteEvent = func(ctx context.Context, id nostr.ID) error {
|
||||
if err := normal.DeleteEvent(id); err != nil {
|
||||
return err
|
||||
}
|
||||
return search.DeleteEvent(id)
|
||||
}
|
||||
|
||||
// other stuff here
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user