2024-10-31 13:26:25 +00:00
|
|
|
package authkit
|
|
|
|
|
|
|
|
import (
|
2024-11-02 04:48:17 +00:00
|
|
|
"context"
|
2024-10-31 13:26:25 +00:00
|
|
|
"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)
|
|
|
|
}
|
2024-11-02 04:48:17 +00:00
|
|
|
_, err = proto.NewNotifyServiceClient(conn).NotifyUser(context.Background(), &proto.NotifyUserRequest{
|
2024-10-31 13:26:25 +00:00
|
|
|
UserId: userId,
|
2024-10-31 14:40:10 +00:00
|
|
|
Notify: &proto.NotifyInfoPayload{
|
2024-10-31 13:26:25 +00:00
|
|
|
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)
|
|
|
|
}
|
2024-11-02 04:48:17 +00:00
|
|
|
_, err = proto.NewNotifyServiceClient(conn).NotifyUserBatch(context.Background(), &proto.NotifyUserBatchRequest{
|
2024-10-31 13:26:25 +00:00
|
|
|
UserId: userId,
|
2024-10-31 14:40:10 +00:00
|
|
|
Notify: &proto.NotifyInfoPayload{
|
2024-10-31 13:26:25 +00:00
|
|
|
Unsaved: unsaved[0],
|
|
|
|
Data: raw,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
}
|