🐛 Fix passing wrong id
This commit is contained in:
parent
eb77ecbeb7
commit
a8a3c8cc71
@ -18,7 +18,7 @@ func (v *Server) EmitStreamEvent(_ context.Context, in *proto.StreamEventRequest
|
|||||||
switch in.GetEvent() {
|
switch in.GetEvent() {
|
||||||
case "status.typing":
|
case "status.typing":
|
||||||
var data struct {
|
var data struct {
|
||||||
ChannelID uint `json:"channel_id"`
|
ChannelID uint `json:"channel_id" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
err := jsoniter.Unmarshal(in.GetPayload(), &data)
|
err := jsoniter.Unmarshal(in.GetPayload(), &data)
|
||||||
@ -26,7 +26,7 @@ func (v *Server) EmitStreamEvent(_ context.Context, in *proto.StreamEventRequest
|
|||||||
err = exts.ValidateStruct(data)
|
err = exts.ValidateStruct(data)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sc.PushStream(context.Background(), &proto.PushStreamRequest{
|
_, _ = sc.PushStream(context.Background(), &proto.PushStreamRequest{
|
||||||
ClientId: &in.ClientId,
|
ClientId: &in.ClientId,
|
||||||
Body: hyper.NetworkPackage{
|
Body: hyper.NetworkPackage{
|
||||||
Action: "error",
|
Action: "error",
|
||||||
@ -37,7 +37,7 @@ func (v *Server) EmitStreamEvent(_ context.Context, in *proto.StreamEventRequest
|
|||||||
|
|
||||||
err = services.SetTypingStatus(data.ChannelID, uint(in.GetUserId()))
|
err = services.SetTypingStatus(data.ChannelID, uint(in.GetUserId()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sc.PushStream(context.Background(), &proto.PushStreamRequest{
|
_, _ = sc.PushStream(context.Background(), &proto.PushStreamRequest{
|
||||||
ClientId: &in.ClientId,
|
ClientId: &in.ClientId,
|
||||||
Body: hyper.NetworkPackage{
|
Body: hyper.NetworkPackage{
|
||||||
Action: "error",
|
Action: "error",
|
||||||
|
@ -13,13 +13,13 @@ import (
|
|||||||
|
|
||||||
func SetTypingStatus(channelId uint, userId uint) error {
|
func SetTypingStatus(channelId uint, userId uint) error {
|
||||||
var account models.Account
|
var account models.Account
|
||||||
if err := database.C.Where("id = ?", userId).First(&account).Error; err != nil {
|
if err := database.C.Where("external_id = ?", userId).First(&account).Error; err != nil {
|
||||||
return fmt.Errorf("account not found: %v", err)
|
return fmt.Errorf("account not found: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var member models.ChannelMember
|
var member models.ChannelMember
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
Where("account_id = ? AND channel_id = ?", userId, channelId).
|
Where("account_id = ? AND channel_id = ?", account.ID, channelId).
|
||||||
First(&member).Error; err != nil {
|
First(&member).Error; err != nil {
|
||||||
return fmt.Errorf("channel member not found: %v", err)
|
return fmt.Errorf("channel member not found: %v", err)
|
||||||
} else {
|
} else {
|
||||||
@ -34,17 +34,17 @@ func SetTypingStatus(channelId uint, userId uint) error {
|
|||||||
return fmt.Errorf("channel not found: %v", err)
|
return fmt.Errorf("channel not found: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var boardcastTarget []uint64
|
var broadcastTarget []uint64
|
||||||
for _, item := range channel.Members {
|
for _, item := range channel.Members {
|
||||||
if item.AccountID == member.AccountID {
|
if item.AccountID == member.AccountID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
boardcastTarget = append(boardcastTarget, uint64(item.AccountID))
|
broadcastTarget = append(broadcastTarget, uint64(item.AccountID))
|
||||||
}
|
}
|
||||||
|
|
||||||
sc := proto.NewStreamControllerClient(gap.H.GetDealerGrpcConn())
|
sc := proto.NewStreamControllerClient(gap.H.GetDealerGrpcConn())
|
||||||
_, err := sc.PushStreamBatch(context.Background(), &proto.PushStreamBatchRequest{
|
_, err := sc.PushStreamBatch(context.Background(), &proto.PushStreamBatchRequest{
|
||||||
UserId: boardcastTarget,
|
UserId: broadcastTarget,
|
||||||
Body: hyper.NetworkPackage{
|
Body: hyper.NetworkPackage{
|
||||||
Action: "status.typing",
|
Action: "status.typing",
|
||||||
Payload: map[string]any{
|
Payload: map[string]any{
|
||||||
|
Loading…
Reference in New Issue
Block a user