fix bug: init conn once

This commit is contained in:
wangchuxiao 2023-07-13 19:57:52 +08:00
parent 7cf48c89f3
commit 38a191e5d1
3 changed files with 14 additions and 23 deletions

View File

@ -15,7 +15,6 @@
package api
import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
"github.com/mitchellh/mapstructure"
@ -291,13 +290,13 @@ func (m *MessageApi) ManagementBatchSendMsg(c *gin.Context) {
pbReq := m.newUserSendMsgReq(c, t)
var recvList []string
if params.IsSendAll {
req2 := &user.GetAllUserIDReq{}
resp2, err := m.Message.GetAllUserID(c, req2)
if err != nil {
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error()))
return
}
recvList = resp2.UserIDs
// req2 := &user.GetAllUserIDReq{}
// resp2, err := m.Message.GetAllUserID(c, req2)
// if err != nil {
// apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error()))
// return
// }
// recvList = resp2.UserIDs
} else {
recvList = params.RecvIDList
}

View File

@ -93,6 +93,9 @@ func (c *ConversationRpcClient) GetConversation(ctx context.Context, ownerUserID
}
func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*pbConversation.Conversation, error) {
if len(conversationIDs) == 0 {
return nil, nil
}
resp, err := c.Client.GetConversationsByConversationID(ctx, &pbConversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs})
if err != nil {
return nil, err

View File

@ -17,7 +17,6 @@ package rpcclient
import (
"context"
"encoding/json"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
@ -121,10 +120,9 @@ func newSessionTypeConf() map[int32]int32 {
}
type Message struct {
conn grpc.ClientConnInterface
Client msg.MsgClient
discov discoveryregistry.SvcDiscoveryRegistry
userClient user.UserClient
conn grpc.ClientConnInterface
Client msg.MsgClient
discov discoveryregistry.SvcDiscoveryRegistry
}
func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry) *Message {
@ -137,16 +135,7 @@ func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry) *Message {
if err != nil {
panic(err)
}
userClient := user.NewUserClient(conn)
return &Message{discov: discov, conn: conn, Client: client, userClient: userClient}
}
func (m *Message) GetAllUserID(ctx context.Context, req *user.GetAllUserIDReq) (*user.GetAllUserIDResp, error) {
resp, err := m.userClient.GetAllUserID(ctx, req)
if err != nil {
return nil, err
}
return resp, nil
return &Message{discov: discov, conn: conn, Client: client}
}
type MessageRpcClient Message