From 698515549bdabf1a2b4bc5eb2d07bc63574907ad Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Mon, 19 Jun 2023 10:22:25 +0800 Subject: [PATCH] second reset seq --- internal/push/push_to_client.go | 32 ++++++++++++++++++++++++++++---- internal/rpc/group/group.go | 1 - 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/internal/push/push_to_client.go b/internal/push/push_to_client.go index abc4ade1e..0abd421fb 100644 --- a/internal/push/push_to_client.go +++ b/internal/push/push_to_client.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "errors" - "github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush" "github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush/fcm" "github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush/getui" @@ -32,6 +31,8 @@ type Pusher struct { offlinePusher offlinepush.OfflinePusher groupLocalCache *localcache.GroupLocalCache conversationLocalCache *localcache.ConversationLocalCache + msgClient *rpcclient.MsgClient + conversationClient *rpcclient.ConversationClient successCount int } @@ -46,6 +47,8 @@ func NewPusher(client discoveryregistry.SvcDiscoveryRegistry, offlinePusher offl offlinePusher: offlinePusher, groupLocalCache: groupLocalCache, conversationLocalCache: conversationLocalCache, + msgClient: rpcclient.NewMsgClient(client), + conversationClient: rpcclient.NewConversationClient(client), } } @@ -75,6 +78,15 @@ func (p *Pusher) DismissGroup(ctx context.Context, groupID string) error { 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) +} + func (p *Pusher) Push2User(ctx context.Context, userIDs []string, msg *sdkws.MsgData) error { log.ZDebug(ctx, "Get msg from msg_transfer And push msg", "userIDs", userIDs, "msg", msg.String()) // callback @@ -145,6 +157,11 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws if p.UnmarshalNotificationElem(msg.Content, &tips) != nil { return err } + defer func(groupID string, userIDs []string) { + if err := p.DeleteMemberAndSetConversationSeq(ctx, groupID, userIDs); err != nil { + log.ZError(ctx, "MemberQuitNotification DeleteMemberAndSetConversationSeq", err, "groupID", groupID, "userIDs", userIDs) + } + }(groupID, []string{tips.QuitUser.UserID}) pushToUserIDs = append(pushToUserIDs, tips.QuitUser.UserID) case constant.MemberKickedNotification: var tips sdkws.MemberKickedTips @@ -152,6 +169,11 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws return err } kickedUsers := utils.Slice(tips.KickedUserList, func(e *sdkws.GroupMemberFullInfo) string { return e.UserID }) + defer func(groupID string, userIDs []string) { + if err := p.DeleteMemberAndSetConversationSeq(ctx, groupID, userIDs); err != nil { + log.ZError(ctx, "MemberKickedNotification DeleteMemberAndSetConversationSeq", err, "groupID", groupID, "userIDs", userIDs) + } + }(groupID, kickedUsers) pushToUserIDs = append(pushToUserIDs, kickedUsers...) case constant.GroupDismissedNotification: if utils.IsNotification(utils.GetConversationIDByMsg(msg)) { // 消息先到,通知后到 @@ -163,9 +185,11 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws if len(config.Config.Manager.AppManagerUid) > 0 { ctx = mcontext.WithOpUserIDContext(ctx, config.Config.Manager.AppManagerUid[0]) } - if err := p.DismissGroup(ctx, groupID); err != nil { - log.ZError(ctx, "DismissGroup Notification clear members", err, "groupID", groupID) - } + defer func(groupID string) { + if err := p.DismissGroup(ctx, groupID); err != nil { + log.ZError(ctx, "DismissGroup Notification clear members", err, "groupID", groupID) + } + }(groupID) } } } diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index d1a4dc1e4..0e8b723cb 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -806,7 +806,6 @@ func (s *groupServer) deleteMemberAndSetConversationSeq(ctx context.Context, gro conevrsationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID) maxSeq, err := s.msgRpcClient.GetConversationMaxSeq(ctx, conevrsationID) if err != nil { - return err } return s.conversationRpcClient.SetConversationMaxSeq(ctx, userIDs, conevrsationID, maxSeq)