Merge remote-tracking branch 'origin/errcode' into errcode

test-errcode
Gordon 1 year ago
commit e676a48c2c

@ -7,14 +7,13 @@ import (
"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/discoveryregistry" "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"google.golang.org/grpc"
) )
type ConversationLocalCache struct { type ConversationLocalCache struct {
lock sync.Mutex lock sync.Mutex
SuperGroupRecvMsgNotNotifyUserIDs map[string]Hash SuperGroupRecvMsgNotNotifyUserIDs map[string]Hash
ConversationIDs map[string]Hash ConversationIDs map[string]Hash
conn *grpc.ClientConn client discoveryregistry.SvcDiscoveryRegistry
} }
type Hash struct { type Hash struct {
@ -23,19 +22,19 @@ type Hash struct {
} }
func NewConversationLocalCache(client discoveryregistry.SvcDiscoveryRegistry) *ConversationLocalCache { func NewConversationLocalCache(client discoveryregistry.SvcDiscoveryRegistry) *ConversationLocalCache {
conn, err := client.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName)
if err != nil {
panic(err)
}
return &ConversationLocalCache{ return &ConversationLocalCache{
SuperGroupRecvMsgNotNotifyUserIDs: make(map[string]Hash), SuperGroupRecvMsgNotNotifyUserIDs: make(map[string]Hash),
ConversationIDs: make(map[string]Hash), ConversationIDs: make(map[string]Hash),
conn: conn, client: client,
} }
} }
func (g *ConversationLocalCache) GetRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error) { func (g *ConversationLocalCache) GetRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error) {
client := conversation.NewConversationClient(g.conn) conn, err := g.client.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName)
if err != nil {
return nil, err
}
client := conversation.NewConversationClient(conn)
resp, err := client.GetRecvMsgNotNotifyUserIDs(ctx, &conversation.GetRecvMsgNotNotifyUserIDsReq{ resp, err := client.GetRecvMsgNotNotifyUserIDs(ctx, &conversation.GetRecvMsgNotNotifyUserIDsReq{
GroupID: groupID, GroupID: groupID,
}) })
@ -46,7 +45,11 @@ func (g *ConversationLocalCache) GetRecvMsgNotNotifyUserIDs(ctx context.Context,
} }
func (g *ConversationLocalCache) GetConversationIDs(ctx context.Context, userID string) ([]string, error) { func (g *ConversationLocalCache) GetConversationIDs(ctx context.Context, userID string) ([]string, error) {
client := conversation.NewConversationClient(g.conn) conn, err := g.client.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName)
if err != nil {
return nil, err
}
client := conversation.NewConversationClient(conn)
resp, err := client.GetUserConversationIDsHash(ctx, &conversation.GetUserConversationIDsHashReq{ resp, err := client.GetUserConversationIDsHash(ctx, &conversation.GetUserConversationIDsHashReq{
OwnerUserID: userID, OwnerUserID: userID,
}) })

@ -6,24 +6,23 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend"
"google.golang.org/grpc"
) )
type BlackClient struct { type BlackClient struct {
conn *grpc.ClientConn *MetaClient
} }
func NewBlackClient(discov discoveryRegistry.SvcDiscoveryRegistry) *BlackClient { func NewBlackClient(zk discoveryRegistry.SvcDiscoveryRegistry) *BlackClient {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName) return &BlackClient{NewMetaClient(zk, config.Config.RpcRegisterName.OpenImFriendName)}
if err != nil {
panic(err)
}
return &BlackClient{conn: conn}
} }
// possibleBlackUserID是否被userID拉黑也就是是否在userID的黑名单中 // possibleBlackUserID是否被userID拉黑也就是是否在userID的黑名单中
func (b *BlackClient) IsBlocked(ctx context.Context, possibleBlackUserID, userID string) (bool, error) { func (b *BlackClient) IsBlocked(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
r, err := friend.NewFriendClient(b.conn).IsBlack(ctx, &friend.IsBlackReq{UserID1: possibleBlackUserID, UserID2: userID}) cc, err := b.getConn(ctx)
if err != nil {
return false, err
}
r, err := friend.NewFriendClient(cc).IsBlack(ctx, &friend.IsBlackReq{UserID1: possibleBlackUserID, UserID2: userID})
if err != nil { if err != nil {
return false, err return false, err
} }

@ -5,32 +5,36 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation" pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"google.golang.org/grpc"
) )
type ConversationClient struct { type ConversationClient struct {
conn *grpc.ClientConn *MetaClient
} }
func NewConversationClient(discov discoveryRegistry.SvcDiscoveryRegistry) *ConversationClient { func NewConversationClient(zk discoveryRegistry.SvcDiscoveryRegistry) *ConversationClient {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName) return &ConversationClient{NewMetaClient(zk, config.Config.RpcRegisterName.OpenImConversationName)}
if err != nil {
panic(err)
}
return &ConversationClient{conn: conn}
} }
func (c *ConversationClient) ModifyConversationField(ctx context.Context, req *pbConversation.ModifyConversationFieldReq) error { func (c *ConversationClient) ModifyConversationField(ctx context.Context, req *pbConversation.ModifyConversationFieldReq) error {
_, err := pbConversation.NewConversationClient(c.conn).ModifyConversationField(ctx, req) cc, err := c.getConn(ctx)
if err != nil {
return err
}
_, err = conversation.NewConversationClient(cc).ModifyConversationField(ctx, req)
return err return err
} }
func (c *ConversationClient) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) { func (c *ConversationClient) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) {
var req pbConversation.GetConversationReq cc, err := c.getConn(ctx)
if err != nil {
return 0, err
}
var req conversation.GetConversationReq
req.OwnerUserID = userID req.OwnerUserID = userID
req.ConversationID = conversationID req.ConversationID = conversationID
conversation, err := pbConversation.NewConversationClient(c.conn).GetConversation(ctx, &req) conversation, err := conversation.NewConversationClient(cc).GetConversation(ctx, &req)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -38,31 +42,55 @@ func (c *ConversationClient) GetSingleConversationRecvMsgOpt(ctx context.Context
} }
func (c *ConversationClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error { func (c *ConversationClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error {
_, err := pbConversation.NewConversationClient(c.conn).CreateSingleChatConversations(ctx, &pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID}) cc, err := c.getConn(ctx)
if err != nil {
return err
}
_, err = conversation.NewConversationClient(cc).CreateSingleChatConversations(ctx, &pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID})
return err return err
} }
func (c *ConversationClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error { func (c *ConversationClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error {
_, err := pbConversation.NewConversationClient(c.conn).CreateGroupChatConversations(ctx, &pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID}) cc, err := c.getConn(ctx)
if err != nil {
return err
}
_, err = conversation.NewConversationClient(cc).CreateGroupChatConversations(ctx, &pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID})
return err return err
} }
func (c *ConversationClient) DelGroupChatConversations(ctx context.Context, ownerUserIDs []string, groupID string, maxSeq int64) error { func (c *ConversationClient) DelGroupChatConversations(ctx context.Context, ownerUserIDs []string, groupID string, maxSeq int64) error {
_, err := pbConversation.NewConversationClient(c.conn).DelGroupChatConversations(ctx, &pbConversation.DelGroupChatConversationsReq{OwnerUserID: ownerUserIDs, GroupID: groupID, MaxSeq: maxSeq}) cc, err := c.getConn(ctx)
if err != nil {
return err
}
_, err = conversation.NewConversationClient(cc).DelGroupChatConversations(ctx, &pbConversation.DelGroupChatConversationsReq{OwnerUserID: ownerUserIDs, GroupID: groupID, MaxSeq: maxSeq})
return err return err
} }
func (c *ConversationClient) GetConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) { func (c *ConversationClient) GetConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) {
resp, err := pbConversation.NewConversationClient(c.conn).GetConversationIDs(ctx, &pbConversation.GetConversationIDsReq{UserID: ownerUserID}) cc, err := c.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := conversation.NewConversationClient(cc).GetConversationIDs(ctx, &pbConversation.GetConversationIDsReq{UserID: ownerUserID})
return resp.ConversationIDs, err return resp.ConversationIDs, err
} }
func (c *ConversationClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbConversation.Conversation, error) { func (c *ConversationClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbConversation.Conversation, error) {
resp, err := pbConversation.NewConversationClient(c.conn).GetConversation(ctx, &pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID}) cc, err := c.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := pbConversation.NewConversationClient(cc).GetConversation(ctx, &pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID})
return resp.Conversation, err return resp.Conversation, err
} }
func (c *ConversationClient) GetConversationByConversationID(ctx context.Context, conversationID string) (*pbConversation.Conversation, error) { func (c *ConversationClient) GetConversationByConversationID(ctx context.Context, conversationID string) (*pbConversation.Conversation, error) {
resp, err := pbConversation.NewConversationClient(c.conn).GetConversationByConversationID(ctx, &pbConversation.GetConversationByConversationIDReq{ConversationID: conversationID}) cc, err := c.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := pbConversation.NewConversationClient(cc).GetConversationByConversationID(ctx, &pbConversation.GetConversationByConversationIDReq{ConversationID: conversationID})
return resp.Conversation, err return resp.Conversation, err
} }

@ -7,23 +7,22 @@ import (
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend"
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"google.golang.org/grpc"
) )
type FriendClient struct { type FriendClient struct {
conn *grpc.ClientConn *MetaClient
} }
func NewFriendClient(discov discoveryRegistry.SvcDiscoveryRegistry) *FriendClient { func NewFriendClient(zk discoveryRegistry.SvcDiscoveryRegistry) *FriendClient {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName) return &FriendClient{NewMetaClient(zk, config.Config.RpcRegisterName.OpenImFriendName)}
if err != nil {
panic(err)
}
return &FriendClient{conn: conn}
} }
func (f *FriendClient) GetFriendsInfo(ctx context.Context, ownerUserID, friendUserID string) (resp *sdkws.FriendInfo, err error) { func (f *FriendClient) GetFriendsInfo(ctx context.Context, ownerUserID, friendUserID string) (resp *sdkws.FriendInfo, err error) {
r, err := friend.NewFriendClient(f.conn).GetDesignatedFriends(ctx, &friend.GetDesignatedFriendsReq{OwnerUserID: ownerUserID, FriendUserIDs: []string{friendUserID}}) cc, err := f.getConn(ctx)
if err != nil {
return nil, err
}
r, err := friend.NewFriendClient(cc).GetDesignatedFriends(ctx, &friend.GetDesignatedFriendsReq{OwnerUserID: ownerUserID, FriendUserIDs: []string{friendUserID}})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -33,7 +32,11 @@ func (f *FriendClient) GetFriendsInfo(ctx context.Context, ownerUserID, friendUs
// possibleFriendUserID是否在userID的好友中 // possibleFriendUserID是否在userID的好友中
func (f *FriendClient) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (bool, error) { func (f *FriendClient) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (bool, error) {
resp, err := friend.NewFriendClient(f.conn).IsFriend(ctx, &friend.IsFriendReq{UserID1: userID, UserID2: possibleFriendUserID}) cc, err := f.getConn(ctx)
if err != nil {
return false, err
}
resp, err := friend.NewFriendClient(cc).IsFriend(ctx, &friend.IsFriendReq{UserID1: userID, UserID2: possibleFriendUserID})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -42,8 +45,12 @@ func (f *FriendClient) IsFriend(ctx context.Context, possibleFriendUserID, userI
} }
func (f *FriendClient) GetFriendIDs(ctx context.Context, ownerUserID string) (friendIDs []string, err error) { func (f *FriendClient) GetFriendIDs(ctx context.Context, ownerUserID string) (friendIDs []string, err error) {
cc, err := f.getConn(ctx)
if err != nil {
return nil, err
}
req := friend.GetFriendIDsReq{UserID: ownerUserID} req := friend.GetFriendIDsReq{UserID: ownerUserID}
resp, err := friend.NewFriendClient(f.conn).GetFriendIDs(ctx, &req) resp, err := friend.NewFriendClient(cc).GetFriendIDs(ctx, &req)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -11,23 +11,27 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
) )
type GroupClient struct { type GroupClient struct {
conn *grpc.ClientConn MetaClient
} }
func NewGroupClient(discov discoveryregistry.SvcDiscoveryRegistry) *GroupClient { func NewGroupClient(client discoveryregistry.SvcDiscoveryRegistry) *GroupClient {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName) return &GroupClient{
if err != nil { MetaClient: MetaClient{
panic(err) client: client,
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
},
} }
return &GroupClient{conn: conn}
} }
func (g *GroupClient) GetGroupInfos(ctx context.Context, groupIDs []string, complete bool) ([]*sdkws.GroupInfo, error) { func (g *GroupClient) GetGroupInfos(ctx context.Context, groupIDs []string, complete bool) ([]*sdkws.GroupInfo, error) {
resp, err := group.NewGroupClient(g.conn).GetGroupsInfo(ctx, &group.GetGroupsInfoReq{ cc, err := g.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := group.NewGroupClient(cc).GetGroupsInfo(ctx, &group.GetGroupsInfoReq{
GroupIDs: groupIDs, GroupIDs: groupIDs,
}) })
if err != nil { if err != nil {
@ -62,7 +66,11 @@ func (g *GroupClient) GetGroupInfoMap(ctx context.Context, groupIDs []string, co
} }
func (g *GroupClient) GetGroupMemberInfos(ctx context.Context, groupID string, userIDs []string, complete bool) ([]*sdkws.GroupMemberFullInfo, error) { func (g *GroupClient) GetGroupMemberInfos(ctx context.Context, groupID string, userIDs []string, complete bool) ([]*sdkws.GroupMemberFullInfo, error) {
resp, err := group.NewGroupClient(g.conn).GetGroupMembersInfo(ctx, &group.GetGroupMembersInfoReq{ cc, err := g.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := group.NewGroupClient(cc).GetGroupMembersInfo(ctx, &group.GetGroupMembersInfoReq{
GroupID: groupID, GroupID: groupID,
UserIDs: userIDs, UserIDs: userIDs,
}) })
@ -98,7 +106,11 @@ func (g *GroupClient) GetGroupMemberInfoMap(ctx context.Context, groupID string,
} }
func (g *GroupClient) GetOwnerAndAdminInfos(ctx context.Context, groupID string) ([]*sdkws.GroupMemberFullInfo, error) { func (g *GroupClient) GetOwnerAndAdminInfos(ctx context.Context, groupID string) ([]*sdkws.GroupMemberFullInfo, error) {
resp, err := group.NewGroupClient(g.conn).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{ cc, err := g.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := group.NewGroupClient(cc).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
GroupID: groupID, GroupID: groupID,
RoleLevels: []int32{constant.GroupOwner, constant.GroupAdmin}, RoleLevels: []int32{constant.GroupOwner, constant.GroupAdmin},
}) })
@ -109,7 +121,11 @@ func (g *GroupClient) GetOwnerAndAdminInfos(ctx context.Context, groupID string)
} }
func (g *GroupClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) { func (g *GroupClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) {
resp, err := group.NewGroupClient(g.conn).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{ cc, err := g.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := group.NewGroupClient(cc).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
GroupID: groupID, GroupID: groupID,
RoleLevels: []int32{constant.GroupOwner}, RoleLevels: []int32{constant.GroupOwner},
}) })
@ -117,7 +133,11 @@ func (g *GroupClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.
} }
func (g *GroupClient) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) { func (g *GroupClient) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) {
resp, err := group.NewGroupClient(g.conn).GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{ cc, err := g.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := group.NewGroupClient(cc).GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{
GroupID: groupID, GroupID: groupID,
}) })
if err != nil { if err != nil {

@ -0,0 +1,31 @@
package rpcclient
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"google.golang.org/grpc"
)
type MetaClient struct {
// contains filtered or unexported fields
client discoveryregistry.SvcDiscoveryRegistry
rpcRegisterName string
}
func NewMetaClient(client discoveryregistry.SvcDiscoveryRegistry, rpcRegisterName string, opts ...MetaClientOptions) *MetaClient {
c := &MetaClient{
client: client,
rpcRegisterName: rpcRegisterName,
}
for _, opt := range opts {
opt(c)
}
return c
}
type MetaClientOptions func(*MetaClient)
func (m *MetaClient) getConn(ctx context.Context) (*grpc.ClientConn, error) {
return m.client.GetConn(ctx, m.rpcRegisterName)
}

@ -100,33 +100,46 @@ func newSessionTypeConf() map[int32]int32 {
type MsgClient struct { type MsgClient struct {
conn *grpc.ClientConn conn *grpc.ClientConn
*MetaClient
} }
func NewMsgClient(discov discoveryregistry.SvcDiscoveryRegistry) *MsgClient { func NewMsgClient(discov discoveryregistry.SvcDiscoveryRegistry) *MsgClient {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName) return &MsgClient{MetaClient: NewMetaClient(discov, config.Config.RpcRegisterName.OpenImMsgName)}
if err != nil {
panic(err)
}
return &MsgClient{conn: conn}
} }
func (m *MsgClient) SendMsg(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) { func (m *MsgClient) SendMsg(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) {
resp, err := msg.NewMsgClient(m.conn).SendMsg(ctx, req) cc, err := m.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := msg.NewMsgClient(cc).SendMsg(ctx, req)
return resp, err return resp, err
} }
func (m *MsgClient) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqReq) (*sdkws.GetMaxSeqResp, error) { func (m *MsgClient) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqReq) (*sdkws.GetMaxSeqResp, error) {
resp, err := msg.NewMsgClient(m.conn).GetMaxSeq(ctx, req) cc, err := m.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := msg.NewMsgClient(cc).GetMaxSeq(ctx, req)
return resp, err return resp, err
} }
func (m *MsgClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) { func (m *MsgClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) {
resp, err := msg.NewMsgClient(m.conn).PullMessageBySeqs(ctx, req) cc, err := m.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := msg.NewMsgClient(cc).PullMessageBySeqs(ctx, req)
return resp, err return resp, err
} }
func (m *MsgClient) GetConversationMaxSeq(ctx context.Context, conversationID string) (int64, error) { func (m *MsgClient) GetConversationMaxSeq(ctx context.Context, conversationID string) (int64, error) {
resp, err := msg.NewMsgClient(m.conn).GetConversationMaxSeq(ctx, &msg.GetConversationMaxSeqReq{ConversationID: conversationID}) cc, err := m.getConn(ctx)
if err != nil {
return 0, err
}
resp, err := msg.NewMsgClient(cc).GetConversationMaxSeq(ctx, &msg.GetConversationMaxSeqReq{ConversationID: conversationID})
if err != nil { if err != nil {
return 0, err return 0, err
} }

@ -6,23 +6,27 @@ import (
"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/discoveryregistry" "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
"google.golang.org/grpc"
) )
type PushClient struct { type PushClient struct {
conn *grpc.ClientConn MetaClient
} }
func NewPushClient(discov discoveryregistry.SvcDiscoveryRegistry) *PushClient { func NewPushClient(client discoveryregistry.SvcDiscoveryRegistry) *PushClient {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImPushName) return &PushClient{
if err != nil { MetaClient: MetaClient{
panic(err) client: client,
rpcRegisterName: config.Config.RpcRegisterName.OpenImPushName,
},
} }
return &PushClient{conn: conn}
} }
func (p *PushClient) DelUserPushToken(ctx context.Context, req *push.DelUserPushTokenReq) (*push.DelUserPushTokenResp, error) { func (p *PushClient) DelUserPushToken(ctx context.Context, req *push.DelUserPushTokenReq) (*push.DelUserPushTokenResp, error) {
resp, err := push.NewPushMsgServiceClient(p.conn).DelUserPushToken(ctx, req) cc, err := p.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := push.NewPushMsgServiceClient(cc).DelUserPushToken(ctx, req)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -11,23 +11,27 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
) )
type UserClient struct { type UserClient struct {
conn *grpc.ClientConn MetaClient
} }
func NewUserClient(discov discoveryregistry.SvcDiscoveryRegistry) *UserClient { func NewUserClient(client discoveryregistry.SvcDiscoveryRegistry) *UserClient {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName) return &UserClient{
if err != nil { MetaClient: MetaClient{
panic(err) client: client,
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
},
} }
return &UserClient{conn: conn}
} }
func (u *UserClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) { func (u *UserClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
resp, err := user.NewUserClient(u.conn).GetDesignateUsers(ctx, &user.GetDesignateUsersReq{ cc, err := u.getConn(ctx)
if err != nil {
return nil, err
}
resp, err := user.NewUserClient(cc).GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
UserIDs: userIDs, UserIDs: userIDs,
}) })
if err != nil { if err != nil {
@ -93,7 +97,11 @@ func (u *UserClient) GetPublicUserInfoMap(ctx context.Context, userIDs []string,
} }
func (u *UserClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) { func (u *UserClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) {
resp, err := user.NewUserClient(u.conn).GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{ cc, err := u.getConn(ctx)
if err != nil {
return 0, err
}
resp, err := user.NewUserClient(cc).GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{
UserID: userID, UserID: userID,
}) })
if err != nil { if err != nil {

Loading…
Cancel
Save