mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
1e53aab4b4
* fix: properly handle otp sms challenge notification in session api * small fix
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
)
|
|
|
|
type alreadyHandled struct {
|
|
event eventstore.Event
|
|
eventTypes []eventstore.EventType
|
|
data map[string]interface{}
|
|
|
|
handled bool
|
|
}
|
|
|
|
func (a *alreadyHandled) Reduce() error {
|
|
return nil
|
|
}
|
|
|
|
func (a *alreadyHandled) AppendEvents(event ...eventstore.Event) {
|
|
if len(event) > 0 {
|
|
a.handled = true
|
|
}
|
|
}
|
|
|
|
func (a *alreadyHandled) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
|
InstanceID(a.event.Aggregate().InstanceID).
|
|
SequenceGreater(a.event.Sequence()).
|
|
AddQuery().
|
|
AggregateTypes(a.event.Aggregate().Type).
|
|
AggregateIDs(a.event.Aggregate().ID).
|
|
EventTypes(a.eventTypes...).
|
|
EventData(a.data).
|
|
Builder()
|
|
}
|
|
|
|
func (n *NotificationQueries) IsAlreadyHandled(ctx context.Context, event eventstore.Event, data map[string]interface{}, eventTypes ...eventstore.EventType) (bool, error) {
|
|
already := &alreadyHandled{
|
|
event: event,
|
|
eventTypes: eventTypes,
|
|
data: data,
|
|
}
|
|
err := n.es.FilterToQueryReducer(ctx, already)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return already.handled, nil
|
|
}
|