grain/server/db/mongo/storeMongo.go

49 lines
1.4 KiB
Go
Raw Permalink Normal View History

package mongo
2024-09-02 00:51:02 +00:00
import (
"context"
"fmt"
"grain/server/db/mongo/kinds"
2024-09-02 00:51:02 +00:00
"grain/server/handlers/response"
nostr "grain/server/types"
"golang.org/x/net/websocket"
)
func StoreMongoEvent(ctx context.Context, evt nostr.Event, ws *websocket.Conn) {
collection := GetCollection(evt.Kind)
var err error
switch {
case evt.Kind == 0:
err = kinds.HandleReplaceableKind(ctx, evt, collection, ws)
2024-09-02 00:51:02 +00:00
case evt.Kind == 1:
err = kinds.HandleRegularKind(ctx, evt, collection, ws)
2024-09-02 00:51:02 +00:00
case evt.Kind == 2:
err = kinds.HandleDeprecatedKind(ctx, evt, ws)
2024-09-02 00:51:02 +00:00
case evt.Kind == 3:
err = kinds.HandleReplaceableKind(ctx, evt, collection, ws)
case evt.Kind == 5:
err = kinds.HandleDeleteKind(ctx, evt, GetClient(), ws)
2024-09-02 00:51:02 +00:00
case evt.Kind >= 4 && evt.Kind < 45:
err = kinds.HandleRegularKind(ctx, evt, collection, ws)
case evt.Kind >= 1000 && evt.Kind < 10000:
err = kinds.HandleRegularKind(ctx, evt, collection, ws)
case evt.Kind >= 10000 && evt.Kind < 20000:
err = kinds.HandleReplaceableKind(ctx, evt, collection, ws)
case evt.Kind >= 20000 && evt.Kind < 30000:
fmt.Println("Ephemeral event received and ignored:", evt.ID)
case evt.Kind >= 30000 && evt.Kind < 40000:
err = kinds.HandleParameterizedReplaceableKind(ctx, evt, collection, ws)
default:
err = kinds.HandleUnknownKind(ctx, evt, collection, ws)
}
if err != nil {
response.SendOK(ws, evt.ID, false, fmt.Sprintf("error: %v", err))
return
}
response.SendOK(ws, evt.ID, true, "")
}