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

View File

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