2024-10-24 16:56:22 +00:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"git.solsynth.dev/hypernet/pusher/pkg/internal/provider"
|
|
|
|
"git.solsynth.dev/hypernet/pusher/pkg/proto"
|
|
|
|
"git.solsynth.dev/hypernet/pusher/pkg/pushkit"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v *Server) PushNotification(ctx context.Context, request *proto.PushNotificationRequest) (*proto.DeliveryResponse, error) {
|
|
|
|
err := provider.PushNotification(pushkit.NotificationPushRequest{
|
|
|
|
Provider: request.GetProvider(),
|
|
|
|
Token: request.GetDeviceToken(),
|
|
|
|
Notification: pushkit.NewNotificationFromProto(request.GetNotify()),
|
|
|
|
})
|
|
|
|
return &proto.DeliveryResponse{IsSuccess: err == nil}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Server) PushNotificationBatch(ctx context.Context, request *proto.PushNotificationBatchRequest) (*proto.DeliveryResponse, error) {
|
|
|
|
go provider.PushNotificationBatch(pushkit.NotificationPushBatchRequest{
|
|
|
|
Providers: request.GetProviders(),
|
|
|
|
Tokens: request.GetDeviceTokens(),
|
|
|
|
Notification: pushkit.NewNotificationFromProto(request.GetNotify()),
|
|
|
|
})
|
|
|
|
return &proto.DeliveryResponse{IsSuccess: true}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Server) DeliverEmail(ctx context.Context, request *proto.DeliverEmailRequest) (*proto.DeliveryResponse, error) {
|
2024-10-26 15:01:40 +00:00
|
|
|
go provider.SendMail(request.GetTo(), pushkit.NewEmailDataFromProto(request.GetEmail()))
|
|
|
|
return &proto.DeliveryResponse{IsSuccess: true}, nil
|
2024-10-24 16:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Server) DeliverEmailBatch(ctx context.Context, request *proto.DeliverEmailBatchRequest) (*proto.DeliveryResponse, error) {
|
2024-10-26 15:01:40 +00:00
|
|
|
go func() {
|
|
|
|
for _, to := range request.GetTo() {
|
|
|
|
_ = provider.SendMail(to, pushkit.NewEmailDataFromProto(request.GetEmail()))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
return &proto.DeliveryResponse{IsSuccess: true}, nil
|
2024-10-24 16:56:22 +00:00
|
|
|
}
|