Interactive/pkg/internal/services/accounts.go

40 lines
1.0 KiB
Go
Raw Normal View History

2024-02-03 07:20:32 +00:00
package services
import (
2024-03-31 13:46:59 +00:00
"context"
2024-07-16 02:53:02 +00:00
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
"git.solsynth.dev/hydrogen/interactive/pkg/internal/gap"
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
2024-04-26 16:13:47 +00:00
"github.com/rs/zerolog/log"
"time"
2024-02-03 07:20:32 +00:00
)
2024-07-16 02:53:02 +00:00
func NotifyPosterAccount(user models.Account, title, body string, subtitle *string) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
2024-07-16 02:53:02 +00:00
pc, err := gap.H.GetServiceGrpcConn(hyper.ServiceTypeAuthProvider)
if err != nil {
return err
}
2024-07-16 02:53:02 +00:00
_, err = proto.NewNotifierClient(pc).NotifyUser(ctx, &proto.NotifyUserRequest{
UserId: uint64(user.ExternalID),
Notify: &proto.NotifyRequest{
Topic: "interactive.feedback",
Title: title,
Subtitle: subtitle,
Body: body,
IsRealtime: false,
IsForcePush: true,
},
})
2024-04-26 16:13:47 +00:00
if err != nil {
log.Warn().Err(err).Msg("An error occurred when notify account...")
} else {
2024-07-16 02:53:02 +00:00
log.Debug().Uint("uid", user.ExternalID).Msg("Notified account.")
2024-04-26 16:13:47 +00:00
}
return err
}