👽 Use hyper's NetworkPackage instead of own UnifiedCommand
This commit is contained in:
parent
31fcfa2bf5
commit
5e76fa07b7
@ -6,7 +6,7 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":alien: Change avatar and banner id to string">
|
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":alien: Change avatar and banner id to string">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pkg/internal/models/unified.go" beforeDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/notifications.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/notifications.go" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pkg/internal/services/notifications.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/notifications.go" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import jsoniter "github.com/json-iterator/go"
|
|
||||||
|
|
||||||
type UnifiedCommand struct {
|
|
||||||
Action string `json:"w"`
|
|
||||||
Message string `json:"m"`
|
|
||||||
Payload any `json:"p"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func UnifiedCommandFromError(err error) UnifiedCommand {
|
|
||||||
return UnifiedCommand{
|
|
||||||
Action: "error",
|
|
||||||
Message: err.Error(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v UnifiedCommand) Marshal() []byte {
|
|
||||||
data, _ := jsoniter.Marshal(v)
|
|
||||||
return data
|
|
||||||
}
|
|
@ -3,6 +3,7 @@ package services
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -71,7 +72,7 @@ func PushNotification(notification models.Notification) error {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
_, err := proto.NewStreamControllerClient(gap.H.GetDealerGrpcConn()).PushStream(ctx, &proto.PushStreamRequest{
|
_, err := proto.NewStreamControllerClient(gap.H.GetDealerGrpcConn()).PushStream(ctx, &proto.PushStreamRequest{
|
||||||
UserId: lo.ToPtr(uint64(notification.AccountID)),
|
UserId: lo.ToPtr(uint64(notification.AccountID)),
|
||||||
Body: models.UnifiedCommand{
|
Body: hyper.NetworkPackage{
|
||||||
Action: "notifications.new",
|
Action: "notifications.new",
|
||||||
Payload: notification,
|
Payload: notification,
|
||||||
}.Marshal(),
|
}.Marshal(),
|
||||||
@ -134,7 +135,7 @@ func PushNotificationBatch(notifications []models.Notification) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
_, _ = stream.PushStream(ctx, &proto.PushStreamRequest{
|
_, _ = stream.PushStream(ctx, &proto.PushStreamRequest{
|
||||||
UserId: lo.ToPtr(uint64(notification.AccountID)),
|
UserId: lo.ToPtr(uint64(notification.AccountID)),
|
||||||
Body: models.UnifiedCommand{
|
Body: hyper.NetworkPackage{
|
||||||
Action: "notifications.new",
|
Action: "notifications.new",
|
||||||
Payload: notification,
|
Payload: notification,
|
||||||
}.Marshal(),
|
}.Marshal(),
|
||||||
|
Loading…
Reference in New Issue
Block a user