This commit is contained in:
wangchuxiao 2023-06-21 10:43:10 +08:00
parent fa9ff6709d
commit d1347c3db0
2 changed files with 18 additions and 22 deletions

View File

@ -18,7 +18,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext" "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/common/prome"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" "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/msggateway"
"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/rpcclient" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
@ -32,25 +31,26 @@ type Pusher struct {
groupLocalCache *localcache.GroupLocalCache groupLocalCache *localcache.GroupLocalCache
conversationLocalCache *localcache.ConversationLocalCache conversationLocalCache *localcache.ConversationLocalCache
msgClient *rpcclient.MessageRpcClient msgClient *rpcclient.MessageRpcClient
conversationClient *rpcclient.ConversationRpcClient conversationRpcClient *rpcclient.ConversationRpcClient
groupRpcClient *rpcclient.GroupRpcClient
successCount int successCount int
} }
var errNoOfflinePusher = errors.New("no offlinePusher is configured") 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 { groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache) *Pusher {
msgClient := rpcclient.NewMessageRpcClient(discov)
msgClient := rpcclient.NewMessageRpcClient(client) conversationRpcClient := rpcclient.NewConversationRpcClient(discov)
conversationClient := rpcclient.NewConversationRpcClient(client) groupRpcClient := rpcclient.NewGroupRpcClient(discov)
return &Pusher{ return &Pusher{
database: database, database: database,
client: client,
offlinePusher: offlinePusher, offlinePusher: offlinePusher,
groupLocalCache: groupLocalCache, groupLocalCache: groupLocalCache,
conversationLocalCache: conversationLocalCache, conversationLocalCache: conversationLocalCache,
msgClient: &msgClient, msgClient: &msgClient,
conversationClient: &conversationClient, conversationRpcClient: &conversationRpcClient,
groupRpcClient: &groupRpcClient,
} }
} }
@ -68,25 +68,13 @@ func NewOfflinePusher(cache cache.MsgModel) offlinepush.OfflinePusher {
return 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 { func (p *Pusher) DeleteMemberAndSetConversationSeq(ctx context.Context, groupID string, userIDs []string) error {
conevrsationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID) conevrsationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID)
maxSeq, err := p.msgClient.GetConversationMaxSeq(ctx, conevrsationID) maxSeq, err := p.msgClient.GetConversationMaxSeq(ctx, conevrsationID)
if err != nil { if err != nil {
return err 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 { 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]) ctx = mcontext.WithOpUserIDContext(ctx, config.Config.Manager.AppManagerUid[0])
} }
defer func(groupID string) { 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) log.ZError(ctx, "DismissGroup Notification clear members", err, "groupID", groupID)
} }
}(groupID) }(groupID)

View File

@ -155,3 +155,11 @@ func (g *GroupRpcClient) GetGroupMemberCache(ctx context.Context, groupID string
} }
return resp.Member, nil 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
}