SimpleCloudNotifier/scnserver/push/testSink.go

42 lines
757 B
Go
Raw Normal View History

2022-11-23 20:21:49 +01:00
package push
import (
"blackforestbytes.com/simplecloudnotifier/models"
"context"
_ "embed"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
)
type SinkData struct {
Message models.Message
Client models.Client
2022-11-23 20:21:49 +01:00
}
type TestSink struct {
2022-11-30 17:58:04 +01:00
Data []SinkData
2022-11-23 20:21:49 +01:00
}
func NewTestSink() NotificationClient {
return &TestSink{}
}
2022-11-30 17:58:04 +01:00
func (d *TestSink) Last() SinkData {
return d.Data[len(d.Data)-1]
}
func (d *TestSink) SendNotification(ctx context.Context, user models.User, client models.Client, channel models.Channel, msg models.Message) (string, error) {
2022-11-23 20:21:49 +01:00
id, err := langext.NewHexUUID()
if err != nil {
return "", err
}
key := "TestSink[" + id + "]"
2022-11-30 17:58:04 +01:00
d.Data = append(d.Data, SinkData{
Message: msg,
Client: client,
2022-11-23 20:21:49 +01:00
})
return key, nil
}