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 {
|
2023-05-27 20:02:16 +02:00
|
|
|
Message models.Message
|
|
|
|
Client models.Client
|
|
|
|
CompatTitleOverride *string
|
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]
|
|
|
|
}
|
|
|
|
|
2023-05-27 20:02:16 +02:00
|
|
|
func (d *TestSink) SendNotification(ctx context.Context, client models.Client, msg models.Message, compatTitleOverride *string) (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{
|
2023-05-27 20:02:16 +02:00
|
|
|
Message: msg,
|
|
|
|
Client: client,
|
|
|
|
CompatTitleOverride: compatTitleOverride,
|
2022-11-23 20:21:49 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
return key, nil
|
|
|
|
}
|