diff --git a/go.mod b/go.mod index 21dbce086..d32497f3d 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( require github.com/google/uuid v1.3.1 require ( - github.com/OpenIMSDK/protocol v0.0.18 + github.com/OpenIMSDK/protocol v0.0.19 github.com/OpenIMSDK/tools v0.0.14 github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible github.com/go-redis/redis v6.15.9+incompatible diff --git a/go.sum b/go.sum index 45165e608..2bade408e 100644 --- a/go.sum +++ b/go.sum @@ -17,8 +17,8 @@ cloud.google.com/go/storage v1.30.1/go.mod h1:NfxhC0UJE1aXSx7CIIbCf7y9HKT7Biccwk firebase.google.com/go v3.13.0+incompatible h1:3TdYC3DDi6aHn20qoRkxwGqNgdjtblwVAyRLQwGn/+4= firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIwjt8toICdV5Wh9ptHs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/OpenIMSDK/protocol v0.0.18 h1:hXukFiDMLZx7s+hDCQePIK9ABiHyNlobNL4MppvOuMY= -github.com/OpenIMSDK/protocol v0.0.18/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= +github.com/OpenIMSDK/protocol v0.0.19 h1:uhIToUMv6AZK0g5k4uuSEMRwuRdeLSUmM4yMG0Hw5Rk= +github.com/OpenIMSDK/protocol v0.0.19/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= github.com/OpenIMSDK/tools v0.0.14 h1:WLof/+WxyPyRST+QkoTKubYCiV73uCLiL8pgnpH/yKQ= github.com/OpenIMSDK/tools v0.0.14/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI= github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= diff --git a/internal/api/conversation.go b/internal/api/conversation.go index 9f25b5427..74b0e7c19 100644 --- a/internal/api/conversation.go +++ b/internal/api/conversation.go @@ -44,3 +44,7 @@ func (o *ConversationApi) GetConversations(c *gin.Context) { func (o *ConversationApi) SetConversations(c *gin.Context) { a2r.Call(conversation.ConversationClient.SetConversations, o.Client, c) } + +func (o *ConversationApi) GetConversationNeedOfflinePushUserIDs(c *gin.Context) { + a2r.Call(conversation.ConversationClient.GetConversationNeedOfflinePushUserIDs, o.Client, c) +} diff --git a/internal/api/route.go b/internal/api/route.go index a118092c4..08f5a092f 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -198,6 +198,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive conversationGroup.POST("/get_conversation", c.GetConversation) conversationGroup.POST("/get_conversations", c.GetConversations) conversationGroup.POST("/set_conversations", c.SetConversations) + conversationGroup.POST("/get_offline_push_userid", c.GetConversationNeedOfflinePushUserIDs) } statisticsGroup := r.Group("/statistics", ParseToken) diff --git a/internal/push/push_to_client.go b/internal/push/push_to_client.go index 690cd37f8..23df0f224 100644 --- a/internal/push/push_to_client.go +++ b/internal/push/push_to_client.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "errors" + "github.com/OpenIMSDK/protocol/conversation" "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" @@ -234,15 +235,20 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws if len(offlinePushUserIDs) > 0 { needOfflinePushUserIDs = offlinePushUserIDs } - err = p.offlinePushMsg(ctx, groupID, msg, offlinePushUserIDs) + resp, err := p.conversationRpcClient.Client.GetConversationNeedOfflinePushUserIDs(ctx, &conversation.GetConversationNeedOfflinePushUserIDsReq{ConversationID: utils.GenGroupConversationID(groupID), OwnerUserIDs: needOfflinePushUserIDs}) if err != nil { - log.ZError(ctx, "offlinePushMsg failed", err, "groupID", groupID, "msg", msg) return err } - _, err := p.GetConnsAndOnlinePush(ctx, msg, utils.IntersectString(needOfflinePushUserIDs, WebAndPcBackgroundUserIDs)) - if err != nil { - log.ZError(ctx, "offlinePushMsg failed", err, "groupID", groupID, "msg", msg, "userIDs", utils.IntersectString(needOfflinePushUserIDs, WebAndPcBackgroundUserIDs)) - return err + if len(resp.UserIDs) > 0 { + err = p.offlinePushMsg(ctx, groupID, msg, resp.UserIDs) + if err != nil { + log.ZError(ctx, "offlinePushMsg failed", err, "groupID", groupID, "msg", msg) + return err + } + if _, err := p.GetConnsAndOnlinePush(ctx, msg, utils.IntersectString(resp.UserIDs, WebAndPcBackgroundUserIDs)); err != nil { + log.ZError(ctx, "offlinePushMsg failed", err, "groupID", groupID, "msg", msg, "userIDs", utils.IntersectString(needOfflinePushUserIDs, WebAndPcBackgroundUserIDs)) + return err + } } } } diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index 093bddc35..d3223d2ed 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -16,7 +16,6 @@ package conversation import ( "context" - "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" "google.golang.org/grpc" @@ -300,3 +299,17 @@ func (c *conversationServer) GetConversationsByConversationID( } return &pbconversation.GetConversationsByConversationIDResp{Conversations: convert.ConversationsDB2Pb(conversations)}, nil } + +func (c *conversationServer) GetConversationNeedOfflinePushUserIDs(ctx context.Context, req *pbconversation.GetConversationNeedOfflinePushUserIDsReq) (*pbconversation.GetConversationNeedOfflinePushUserIDsResp, error) { + if req.ConversationID == "" { + return nil, errs.ErrArgs.Wrap("conversationID is empty") + } + if len(req.OwnerUserIDs) == 0 { + return &pbconversation.GetConversationNeedOfflinePushUserIDsResp{}, nil + } + userIDs, err := c.conversationDatabase.GetConversationNeedOfflinePushUserIDs(ctx, req.ConversationID, req.OwnerUserIDs) + if err != nil { + return nil, err + } + return &pbconversation.GetConversationNeedOfflinePushUserIDsResp{UserIDs: userIDs}, nil +} diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index 16eedbc2d..f7a0a9f66 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -53,6 +53,7 @@ type ConversationDatabase interface { GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (map[string]int64, error) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationtb.ConversationModel, error) GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationtb.ConversationModel, error) + GetConversationNeedOfflinePushUserIDs(ctx context.Context, conversationID string, ownerUserIDs []string) ([]string, error) } func NewConversationDatabase(conversation relationtb.ConversationModelInterface, cache cache.ConversationCache, tx tx.Tx) ConversationDatabase { @@ -296,3 +297,7 @@ func (c *conversationDatabase) GetConversationsByConversationID(ctx context.Cont func (c *conversationDatabase) GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationtb.ConversationModel, error) { return c.conversationDB.GetConversationIDsNeedDestruct(ctx) } + +func (c *conversationDatabase) GetConversationNeedOfflinePushUserIDs(ctx context.Context, conversationID string, ownerUserIDs []string) ([]string, error) { + return c.conversationDB.GetConversationNeedOfflinePushUserIDs(ctx, conversationID, ownerUserIDs) +} diff --git a/pkg/common/db/relation/conversation_model.go b/pkg/common/db/relation/conversation_model.go index f58ac6e22..4b3b0cc41 100644 --- a/pkg/common/db/relation/conversation_model.go +++ b/pkg/common/db/relation/conversation_model.go @@ -16,6 +16,7 @@ package relation import ( "context" + "github.com/OpenIMSDK/tools/errs" "gorm.io/gorm" @@ -214,3 +215,8 @@ func (c *ConversationGorm) GetConversationIDsNeedDestruct( "", ) } + +func (c *ConversationGorm) GetConversationNeedOfflinePushUserIDs(ctx context.Context, conversationID string, ownerUserIDs []string) ([]string, error) { + var userIDs []string + return userIDs, errs.Wrap(c.db(ctx).Model(&relation.ConversationModel{}).Where("conversation_id = ? and owner_user_id in ? and recv_msg_opt = ?", conversationID, ownerUserIDs, constant.ReceiveMessage).Pluck("owner_user_id", &userIDs).Error) +} diff --git a/pkg/common/db/table/relation/conversation.go b/pkg/common/db/table/relation/conversation.go index 99c01e5b7..2721f05e5 100644 --- a/pkg/common/db/table/relation/conversation.go +++ b/pkg/common/db/table/relation/conversation.go @@ -66,5 +66,6 @@ type ConversationModelInterface interface { GetUserAllHasReadSeqs(ctx context.Context, ownerUserID string) (hashReadSeqs map[string]int64, err error) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*ConversationModel, error) GetConversationIDsNeedDestruct(ctx context.Context) ([]*ConversationModel, error) + GetConversationNeedOfflinePushUserIDs(ctx context.Context, conversationID string, ownerUserIDs []string) ([]string, error) NewTx(tx any) ConversationModelInterface }