🐛 Fix passing wrong id

This commit is contained in:
LittleSheep 2024-08-23 21:01:47 +08:00
parent eb77ecbeb7
commit a8a3c8cc71
2 changed files with 8 additions and 8 deletions

View File

@ -18,7 +18,7 @@ func (v *Server) EmitStreamEvent(_ context.Context, in *proto.StreamEventRequest
switch in.GetEvent() {
case "status.typing":
var data struct {
ChannelID uint `json:"channel_id"`
ChannelID uint `json:"channel_id" validate:"required"`
}
err := jsoniter.Unmarshal(in.GetPayload(), &data)
@ -26,7 +26,7 @@ func (v *Server) EmitStreamEvent(_ context.Context, in *proto.StreamEventRequest
err = exts.ValidateStruct(data)
}
if err != nil {
sc.PushStream(context.Background(), &proto.PushStreamRequest{
_, _ = sc.PushStream(context.Background(), &proto.PushStreamRequest{
ClientId: &in.ClientId,
Body: hyper.NetworkPackage{
Action: "error",
@ -37,7 +37,7 @@ func (v *Server) EmitStreamEvent(_ context.Context, in *proto.StreamEventRequest
err = services.SetTypingStatus(data.ChannelID, uint(in.GetUserId()))
if err != nil {
sc.PushStream(context.Background(), &proto.PushStreamRequest{
_, _ = sc.PushStream(context.Background(), &proto.PushStreamRequest{
ClientId: &in.ClientId,
Body: hyper.NetworkPackage{
Action: "error",

View File

@ -13,13 +13,13 @@ import (
func SetTypingStatus(channelId uint, userId uint) error {
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)
}
var member models.ChannelMember
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 {
return fmt.Errorf("channel member not found: %v", err)
} else {
@ -34,17 +34,17 @@ func SetTypingStatus(channelId uint, userId uint) error {
return fmt.Errorf("channel not found: %v", err)
}
var boardcastTarget []uint64
var broadcastTarget []uint64
for _, item := range channel.Members {
if item.AccountID == member.AccountID {
continue
}
boardcastTarget = append(boardcastTarget, uint64(item.AccountID))
broadcastTarget = append(broadcastTarget, uint64(item.AccountID))
}
sc := proto.NewStreamControllerClient(gap.H.GetDealerGrpcConn())
_, err := sc.PushStreamBatch(context.Background(), &proto.PushStreamBatchRequest{
UserId: boardcastTarget,
UserId: broadcastTarget,
Body: hyper.NetworkPackage{
Action: "status.typing",
Payload: map[string]any{