Passport/pkg/authkit/notify.go

49 lines
1.3 KiB
Go
Raw Normal View History

package authkit
import (
"context"
"fmt"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/passport/pkg/proto"
"git.solsynth.dev/hypernet/pusher/pkg/pushkit"
"github.com/goccy/go-json"
)
func NotifyUser(nx *nex.Conn, userId uint64, notify pushkit.Notification, unsaved ...bool) error {
conn, err := nx.GetClientGrpcConn(nex.ServiceTypeAuth)
if err != nil {
return fmt.Errorf("failed to get auth service client: %v", err)
}
raw, _ := json.Marshal(notify)
if len(unsaved) == 0 {
unsaved = append(unsaved, false)
}
_, err = proto.NewNotifyServiceClient(conn).NotifyUser(context.Background(), &proto.NotifyUserRequest{
UserId: userId,
2024-10-31 14:40:10 +00:00
Notify: &proto.NotifyInfoPayload{
Unsaved: unsaved[0],
Data: raw,
},
})
return err
}
func NotifyUserBatch(nx *nex.Conn, userId []uint64, notify pushkit.Notification, unsaved ...bool) error {
conn, err := nx.GetClientGrpcConn(nex.ServiceTypeAuth)
if err != nil {
return fmt.Errorf("failed to get auth service client: %v", err)
}
raw, _ := json.Marshal(notify)
if len(unsaved) == 0 {
unsaved = append(unsaved, false)
}
_, err = proto.NewNotifyServiceClient(conn).NotifyUserBatch(context.Background(), &proto.NotifyUserBatchRequest{
UserId: userId,
2024-10-31 14:40:10 +00:00
Notify: &proto.NotifyInfoPayload{
Unsaved: unsaved[0],
Data: raw,
},
})
return err
}