2024-07-21 05:51:46 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-09-15 05:03:11 +00:00
|
|
|
"sync"
|
|
|
|
|
2024-07-21 05:51:46 +00:00
|
|
|
"git.solsynth.dev/hydrogen/dealer/pkg/internal/services"
|
|
|
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v *Server) DeliverNotification(ctx context.Context, request *proto.DeliverNotificationRequest) (*proto.DeliverResponse, error) {
|
2024-07-23 10:27:43 +00:00
|
|
|
services.DealDeliveryTask(request)
|
2024-07-21 05:51:46 +00:00
|
|
|
return &proto.DeliverResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Server) DeliverNotificationBatch(ctx context.Context, request *proto.DeliverNotificationBatchRequest) (*proto.DeliverResponse, error) {
|
2024-07-23 10:27:43 +00:00
|
|
|
var wg sync.WaitGroup
|
2024-07-21 05:51:46 +00:00
|
|
|
for idx, provider := range request.GetProviders() {
|
|
|
|
token := request.GetDeviceTokens()[idx]
|
2024-07-23 10:27:43 +00:00
|
|
|
provider := provider
|
2024-09-15 05:03:11 +00:00
|
|
|
wg.Add(1)
|
2024-07-23 10:27:43 +00:00
|
|
|
go func() {
|
|
|
|
services.DealDeliveryTask(&proto.DeliverNotificationRequest{
|
|
|
|
Provider: provider,
|
|
|
|
DeviceToken: token,
|
|
|
|
Notify: request.GetNotify(),
|
|
|
|
})
|
|
|
|
wg.Done()
|
|
|
|
}()
|
2024-07-21 05:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &proto.DeliverResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Server) DeliverEmail(ctx context.Context, request *proto.DeliverEmailRequest) (*proto.DeliverResponse, error) {
|
2024-07-23 10:27:43 +00:00
|
|
|
services.DealDeliveryTask(request)
|
2024-07-21 05:51:46 +00:00
|
|
|
return &proto.DeliverResponse{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Server) DeliverEmailBatch(ctx context.Context, request *proto.DeliverEmailBatchRequest) (*proto.DeliverResponse, error) {
|
2024-07-23 10:27:43 +00:00
|
|
|
var wg sync.WaitGroup
|
2024-07-21 05:51:46 +00:00
|
|
|
for _, to := range request.GetTo() {
|
2024-07-23 10:27:43 +00:00
|
|
|
to := to
|
2024-09-15 05:03:11 +00:00
|
|
|
wg.Add(1)
|
2024-07-23 10:27:43 +00:00
|
|
|
go func() {
|
|
|
|
services.DealDeliveryTask(&proto.DeliverEmailRequest{
|
|
|
|
To: to,
|
|
|
|
Email: request.GetEmail(),
|
|
|
|
})
|
|
|
|
wg.Done()
|
|
|
|
}()
|
2024-07-21 05:51:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &proto.DeliverResponse{}, nil
|
|
|
|
}
|