diff --git a/service/app/handler_save_received_event.go b/service/app/handler_save_received_event.go index 8c5a504..80f23e1 100644 --- a/service/app/handler_save_received_event.go +++ b/service/app/handler_save_received_event.go @@ -2,6 +2,7 @@ package app import ( "context" + "fmt" "github.com/boreq/errors" "github.com/planetary-social/nos-event-service/internal/logging" @@ -46,9 +47,11 @@ func (h *SaveReceivedEventHandler) Handle(ctx context.Context, cmd SaveReceivedE WithField("event.kind", cmd.event.Kind().Int()). Message("saving received event") - if err := h.transactionProvider.Transact(ctx, func(ctx context.Context, adapters Adapters) error { - // todo check if event should be saved + if !h.shouldBeGloballyDownloaded(cmd.event.Kind()) { + return fmt.Errorf("event shouldn't have been downloaded, relay '%s' may be misbehaving", cmd.relay.String()) + } + if err := h.transactionProvider.Transact(ctx, func(ctx context.Context, adapters Adapters) error { if err := adapters.Events.Save(ctx, cmd.event); err != nil { return errors.Wrap(err, "error saving the event") } @@ -64,3 +67,12 @@ func (h *SaveReceivedEventHandler) Handle(ctx context.Context, cmd SaveReceivedE return nil } + +func (h *SaveReceivedEventHandler) shouldBeGloballyDownloaded(kind domain.EventKind) bool { + for _, v := range globalEventTypesToDownload { + if v == kind { + return true + } + } + return false +}