From 13dd8dc2efb68631e0b77d41fd4c98335104ae40 Mon Sep 17 00:00:00 2001 From: Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:48:21 +0800 Subject: [PATCH] fix: api send messages for notification conversation . --- go.mod | 2 +- go.sum | 4 +- .../msgtransfer/online_history_msg_handler.go | 26 +++++++--- internal/rpc/conversation/conversaion.go | 50 ++++++++++++------- internal/rpc/friend/friend.go | 3 +- pkg/rpcclient/conversation.go | 10 +++- 6 files changed, 63 insertions(+), 32 deletions(-) diff --git a/go.mod b/go.mod index 8510f780d..f31f63ee6 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require github.com/google/uuid v1.3.1 require ( github.com/IBM/sarama v1.41.3 - github.com/OpenIMSDK/protocol v0.0.27 + github.com/OpenIMSDK/protocol v0.0.28 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 0e19ebfbf..313d6d1d0 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/IBM/sarama v1.41.3 h1:MWBEJ12vHC8coMjdEXFq/6ftO6DUZnQlFYcxtOJFa7c= github.com/IBM/sarama v1.41.3/go.mod h1:Xxho9HkHd4K/MDUo/T/sOqwtX/17D33++E9Wib6hUdQ= -github.com/OpenIMSDK/protocol v0.0.27 h1:ee1Y6idLahgJrTHkgWPboKIvCT9zvf7jitavVpffpPw= -github.com/OpenIMSDK/protocol v0.0.27/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= +github.com/OpenIMSDK/protocol v0.0.28 h1:JiIUl630GfP9oAu3bNNGsOMuxRowdsm2DmyqDBOl/4c= +github.com/OpenIMSDK/protocol v0.0.28/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/msgtransfer/online_history_msg_handler.go b/internal/msgtransfer/online_history_msg_handler.go index e83939a4c..b4556634c 100644 --- a/internal/msgtransfer/online_history_msg_handler.go +++ b/internal/msgtransfer/online_history_msg_handler.go @@ -283,20 +283,30 @@ func (och *OnlineHistoryRedisConsumerHandler) handleMsg( return } if isNewConversation { - if storageList[0].SessionType == constant.SuperGroupChatType { - log.ZInfo(ctx, "group chat first create conversation", "conversationID", conversationID) + switch storageList[0].SessionType { + case constant.SuperGroupChatType: + log.ZInfo(ctx, "group chat first create conversation", "conversationID", + conversationID) userIDs, err := och.groupRpcClient.GetGroupMemberIDs(ctx, storageList[0].GroupID) if err != nil { - log.ZWarn(ctx, "get group member ids error", err, "conversationID", conversationID) + log.ZWarn(ctx, "get group member ids error", err, "conversationID", + conversationID) } else { - if err := och.conversationRpcClient.GroupChatFirstCreateConversation(ctx, storageList[0].GroupID, userIDs); err != nil { - log.ZWarn(ctx, "single chat first create conversation error", err, "conversationID", conversationID) + if err := och.conversationRpcClient.GroupChatFirstCreateConversation(ctx, + storageList[0].GroupID, userIDs); err != nil { + log.ZWarn(ctx, "single chat first create conversation error", err, + "conversationID", conversationID) } } - } else { - if err := och.conversationRpcClient.SingleChatFirstCreateConversation(ctx, storageList[0].RecvID, storageList[0].SendID); err != nil { - log.ZWarn(ctx, "single chat first create conversation error", err, "conversationID", conversationID) + case constant.SingleChatType, constant.NotificationChatType: + if err := och.conversationRpcClient.SingleChatFirstCreateConversation(ctx, storageList[0].RecvID, + storageList[0].SendID, conversationID, storageList[0].SessionType); err != nil { + log.ZWarn(ctx, "single chat or notification first create conversation error", err, + "conversationID", conversationID, "sessionType", storageList[0].SessionType) } + default: + log.ZWarn(ctx, "unknown session type", nil, "sessionType", + storageList[0].SessionType) } } diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index e76f83008..c39432768 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -17,8 +17,6 @@ package conversation import ( "context" - "github.com/openimsdk/open-im-server/v3/pkg/msgprocessor" - "google.golang.org/grpc" "github.com/OpenIMSDK/protocol/constant" @@ -235,24 +233,40 @@ func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req } // create conversation without notification for msg redis transfer. -func (c *conversationServer) CreateSingleChatConversations(ctx context.Context, req *pbconversation.CreateSingleChatConversationsReq) (*pbconversation.CreateSingleChatConversationsResp, error) { - var conversation tablerelation.ConversationModel - conversation.ConversationID = msgprocessor.GetConversationIDBySessionType(constant.SingleChatType, req.RecvID, req.SendID) - conversation.ConversationType = constant.SingleChatType - conversation.OwnerUserID = req.SendID - conversation.UserID = req.RecvID - err := c.conversationDatabase.CreateConversation(ctx, []*tablerelation.ConversationModel{&conversation}) - if err != nil { - log.ZWarn(ctx, "create conversation failed", err, "conversation", conversation) - } +func (c *conversationServer) CreateSingleChatConversations(ctx context.Context, + req *pbconversation.CreateSingleChatConversationsReq, +) (*pbconversation.CreateSingleChatConversationsResp, error) { + switch req.ConversationType { + case constant.SingleChatType: + var conversation tablerelation.ConversationModel + conversation.ConversationID = req.ConversationID + conversation.ConversationType = req.ConversationType + conversation.OwnerUserID = req.SendID + conversation.UserID = req.RecvID + err := c.conversationDatabase.CreateConversation(ctx, []*tablerelation.ConversationModel{&conversation}) + if err != nil { + log.ZWarn(ctx, "create conversation failed", err, "conversation", conversation) + } - conversation2 := conversation - conversation2.OwnerUserID = req.RecvID - conversation2.UserID = req.SendID - err = c.conversationDatabase.CreateConversation(ctx, []*tablerelation.ConversationModel{&conversation2}) - if err != nil { - log.ZWarn(ctx, "create conversation failed", err, "conversation2", conversation) + conversation2 := conversation + conversation2.OwnerUserID = req.RecvID + conversation2.UserID = req.SendID + err = c.conversationDatabase.CreateConversation(ctx, []*tablerelation.ConversationModel{&conversation2}) + if err != nil { + log.ZWarn(ctx, "create conversation failed", err, "conversation2", conversation) + } + case constant.NotificationChatType: + var conversation tablerelation.ConversationModel + conversation.ConversationID = req.ConversationID + conversation.ConversationType = req.ConversationType + conversation.OwnerUserID = req.RecvID + conversation.UserID = req.SendID + err := c.conversationDatabase.CreateConversation(ctx, []*tablerelation.ConversationModel{&conversation}) + if err != nil { + log.ZWarn(ctx, "create conversation failed", err, "conversation2", conversation) + } } + return &pbconversation.CreateSingleChatConversationsResp{}, nil } diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index 1524a7f27..c563f77fe 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -252,7 +252,8 @@ func (s *friendServer) GetDesignatedFriends( return resp, nil } -func (s *friendServer) GetDesignatedFriendsApply(ctx context.Context, req *pbfriend.GetDesignatedFriendsApplyReq) (resp *pbfriend.GetDesignatedFriendsApplyResp, err error) { +func (s *friendServer) GetDesignatedFriendsApply(ctx context.Context, + req *pbfriend.GetDesignatedFriendsApplyReq) (resp *pbfriend.GetDesignatedFriendsApplyResp, err error) { friendRequests, err := s.friendDatabase.FindBothFriendRequests(ctx, req.FromUserID, req.ToUserID) if err != nil { return nil, err diff --git a/pkg/rpcclient/conversation.go b/pkg/rpcclient/conversation.go index 60ca53351..057e0fd23 100644 --- a/pkg/rpcclient/conversation.go +++ b/pkg/rpcclient/conversation.go @@ -59,8 +59,14 @@ func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Cont return conversation.GetConversation().RecvMsgOpt, err } -func (c *ConversationRpcClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error { - _, err := c.Client.CreateSingleChatConversations(ctx, &pbconversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID}) +func (c *ConversationRpcClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID, + conversationID string, conversationType int32, +) error { + _, err := c.Client.CreateSingleChatConversations(ctx, + &pbconversation.CreateSingleChatConversationsReq{ + RecvID: recvID, SendID: sendID, ConversationID: conversationID, + ConversationType: conversationType, + }) return err }