From 38a191e5d1368de8dadae0681a51712e3bd8efd3 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 13 Jul 2023 19:57:52 +0800 Subject: [PATCH] fix bug: init conn once --- internal/api/msg.go | 15 +++++++-------- pkg/rpcclient/conversation.go | 3 +++ pkg/rpcclient/msg.go | 19 ++++--------------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/internal/api/msg.go b/internal/api/msg.go index ba8cf0ff5..dba6a52d7 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -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 } diff --git a/pkg/rpcclient/conversation.go b/pkg/rpcclient/conversation.go index ff65682e5..c3648a050 100644 --- a/pkg/rpcclient/conversation.go +++ b/pkg/rpcclient/conversation.go @@ -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 diff --git a/pkg/rpcclient/msg.go b/pkg/rpcclient/msg.go index 029e16e47..0559e7e3e 100644 --- a/pkg/rpcclient/msg.go +++ b/pkg/rpcclient/msg.go @@ -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