2022-01-06 08:00:24 +00:00
|
|
|
package senders
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
import "github.com/zitadel/zitadel/internal/notification/channels"
|
2022-01-06 08:00:24 +00:00
|
|
|
|
|
|
|
var _ channels.NotificationChannel = (*Chain)(nil)
|
|
|
|
|
|
|
|
type Chain struct {
|
|
|
|
channels []channels.NotificationChannel
|
|
|
|
}
|
|
|
|
|
2023-10-10 13:20:53 +00:00
|
|
|
func ChainChannels(channel ...channels.NotificationChannel) *Chain {
|
2022-01-06 08:00:24 +00:00
|
|
|
return &Chain{channels: channel}
|
|
|
|
}
|
|
|
|
|
|
|
|
// HandleMessage returns a non nil error from a provider immediately if any occurs
|
2023-10-10 13:20:53 +00:00
|
|
|
// messages are sent to channels in the same order they were provided to ChainChannels()
|
2022-01-06 08:00:24 +00:00
|
|
|
func (c *Chain) HandleMessage(message channels.Message) error {
|
|
|
|
for i := range c.channels {
|
|
|
|
if err := c.channels[i].HandleMessage(message); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-03-07 13:22:37 +00:00
|
|
|
|
|
|
|
func (c *Chain) Len() int {
|
|
|
|
return len(c.channels)
|
|
|
|
}
|