From d1347c3db066a6d5aae6d76f59fdba887187c588 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 21 Jun 2023 10:43:10 +0800 Subject: [PATCH] group --- internal/push/push_to_client.go | 32 ++++++++++---------------------- pkg/rpcclient/group.go | 8 ++++++++ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/internal/push/push_to_client.go b/internal/push/push_to_client.go index 3df748792..291fbb189 100644 --- a/internal/push/push_to_client.go +++ b/internal/push/push_to_client.go @@ -18,7 +18,6 @@ import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome" "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" - "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msggateway" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient" @@ -32,25 +31,26 @@ type Pusher struct { groupLocalCache *localcache.GroupLocalCache conversationLocalCache *localcache.ConversationLocalCache msgClient *rpcclient.MessageRpcClient - conversationClient *rpcclient.ConversationRpcClient + conversationRpcClient *rpcclient.ConversationRpcClient + groupRpcClient *rpcclient.GroupRpcClient successCount int } var errNoOfflinePusher = errors.New("no offlinePusher is configured") -func NewPusher(client discoveryregistry.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase, +func NewPusher(discov discoveryregistry.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase, groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache) *Pusher { - - msgClient := rpcclient.NewMessageRpcClient(client) - conversationClient := rpcclient.NewConversationRpcClient(client) + msgClient := rpcclient.NewMessageRpcClient(discov) + conversationRpcClient := rpcclient.NewConversationRpcClient(discov) + groupRpcClient := rpcclient.NewGroupRpcClient(discov) return &Pusher{ database: database, - client: client, offlinePusher: offlinePusher, groupLocalCache: groupLocalCache, conversationLocalCache: conversationLocalCache, msgClient: &msgClient, - conversationClient: &conversationClient, + conversationRpcClient: &conversationRpcClient, + groupRpcClient: &groupRpcClient, } } @@ -68,25 +68,13 @@ func NewOfflinePusher(cache cache.MsgModel) offlinepush.OfflinePusher { return offlinePusher } -func (p *Pusher) DismissGroup(ctx context.Context, groupID string) error { - cc, err := p.client.GetConn(ctx, config.Config.RpcRegisterName.OpenImGroupName) - if err != nil { - return err - } - _, err = group.NewGroupClient(cc).DismissGroup(ctx, &group.DismissGroupReq{ - GroupID: groupID, - DeleteMember: true, - }) - return err -} - func (p *Pusher) DeleteMemberAndSetConversationSeq(ctx context.Context, groupID string, userIDs []string) error { conevrsationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID) maxSeq, err := p.msgClient.GetConversationMaxSeq(ctx, conevrsationID) if err != nil { return err } - return p.conversationClient.SetConversationMaxSeq(ctx, userIDs, conevrsationID, maxSeq) + return p.conversationRpcClient.SetConversationMaxSeq(ctx, userIDs, conevrsationID, maxSeq) } func (p *Pusher) Push2User(ctx context.Context, userIDs []string, msg *sdkws.MsgData) error { @@ -179,7 +167,7 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws ctx = mcontext.WithOpUserIDContext(ctx, config.Config.Manager.AppManagerUid[0]) } defer func(groupID string) { - if err := p.DismissGroup(ctx, groupID); err != nil { + if err := p.groupRpcClient.DismissGroup(ctx, groupID); err != nil { log.ZError(ctx, "DismissGroup Notification clear members", err, "groupID", groupID) } }(groupID) diff --git a/pkg/rpcclient/group.go b/pkg/rpcclient/group.go index f1a6fab73..6f87e63cc 100644 --- a/pkg/rpcclient/group.go +++ b/pkg/rpcclient/group.go @@ -155,3 +155,11 @@ func (g *GroupRpcClient) GetGroupMemberCache(ctx context.Context, groupID string } return resp.Member, nil } + +func (g *GroupRpcClient) DismissGroup(ctx context.Context, groupID string) error { + _, err := g.Client.DismissGroup(ctx, &group.DismissGroupReq{ + GroupID: groupID, + DeleteMember: true, + }) + return err +}