Skip to content

Commit

Permalink
fix: online notifications do not push to herself.
Browse files Browse the repository at this point in the history
  • Loading branch information
FGadvancer committed Dec 15, 2023
1 parent f6ff58d commit 7ff3880
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions internal/push/push_to_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"context"
"encoding/json"
"errors"
"golang.org/x/sync/errgroup"
"sync"

"github.com/OpenIMSDK/protocol/constant"
"github.com/OpenIMSDK/protocol/conversation"
Expand Down Expand Up @@ -285,33 +287,41 @@ func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData,
return nil, err
}

//var (
// mu sync.Mutex
// wg = errgroup.Group{}
// input = &msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs}
// maxWorkers = config.Config.Push.MaxConcurrentWorkers
//)
//
//if maxWorkers < 3 {
// maxWorkers = 3
//}
//
//wg.SetLimit(maxWorkers)
var (
mu sync.Mutex
wg = errgroup.Group{}
input = &msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs}
maxWorkers = config.Config.Push.MaxConcurrentWorkers
)

if maxWorkers < 3 {
maxWorkers = 3
}

wg.SetLimit(maxWorkers)

// Online push message
for _, v := range conns {
msgClient := msggateway.NewMsgGatewayClient(v)
reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(ctx, &msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs})
if err != nil {
continue
}
log.ZDebug(ctx, "push result", "reply", reply)
if reply != nil && reply.SinglePushResult != nil {
wsResults = append(wsResults, reply.SinglePushResult...)
}
for _, conn := range conns {
conn := conn // loop var safe
wg.Go(func() error {
msgClient := msggateway.NewMsgGatewayClient(conn)
reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(ctx, input)
if err != nil {
return nil
}

log.ZDebug(ctx, "push result", "reply", reply)
if reply != nil && reply.SinglePushResult != nil {
mu.Lock()
wsResults = append(wsResults, reply.SinglePushResult...)
mu.Unlock()
}

return nil
})
}

//_ = wg.Wait()
_ = wg.Wait()

// always return nil
return wsResults, nil
Expand Down

0 comments on commit 7ff3880

Please sign in to comment.