conversation create

This commit is contained in:
wangchuxiao 2023-05-04 17:27:29 +08:00
parent cfa543802e
commit 640313386b
3 changed files with 53 additions and 36 deletions

View File

@ -12,7 +12,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
@ -170,15 +169,20 @@ func (och *OnlineHistoryRedisConsumerHandler) handleMsg(ctx context.Context, con
currentMaxSeq, err = och.msgDatabase.GetGroupMaxSeq(ctx, conversationID)
if err == redis.Nil {
log.ZInfo(ctx, "group chat first create conversation", "conversationID", conversationID)
if err := och.GroupChatFirstCreateConversation(ctx, storageList[0]); err != nil {
userIDs, err := och.groupRpcClient.GetGroupMemberIDs(ctx, storageList[0].GroupID)
if err != nil {
log.ZError(ctx, "get group member ids error", err, "conversationID", conversationID)
} else {
if err := och.conversationRpcClient.GroupChatFirstCreateConversation(ctx, storageList[0].GroupID, userIDs); err != nil {
log.ZError(ctx, "single chat first create conversation error", err, "conversationID", conversationID)
}
}
}
} else {
currentMaxSeq, err = och.msgDatabase.GetUserMaxSeq(ctx, conversationID)
if err == redis.Nil {
log.ZInfo(ctx, "single chat first create conversation", "conversationID", conversationID)
if err := och.SingleChatFirstCreateConversation(ctx, storageList[0]); err != nil {
if err := och.conversationRpcClient.SingleChatFirstCreateConversation(ctx, storageList[0].RecvID, storageList[0].SendID); err != nil {
log.ZError(ctx, "single chat first create conversation error", err, "conversationID", conversationID)
}
}
@ -206,35 +210,6 @@ func (och *OnlineHistoryRedisConsumerHandler) handleMsg(ctx context.Context, con
}
}
func (och *OnlineHistoryRedisConsumerHandler) SingleChatFirstCreateConversation(ctx context.Context, msg *sdkws.MsgData) error {
conversation := new(pbConversation.Conversation)
conversationID := utils.GetConversationIDBySessionType(constant.SingleChatType, msg.RecvID, msg.SendID)
conversation.ConversationType = constant.SingleChatType
conversation2 := proto.Clone(conversation).(*pbConversation.Conversation)
conversation.OwnerUserID = msg.SendID
conversation.UserID = msg.RecvID
conversation.ConversationID = conversationID
conversation2.OwnerUserID = msg.RecvID
conversation2.UserID = msg.SendID
conversation2.ConversationID = conversationID
log.ZDebug(ctx, "create single conversation", "conversation", conversation, "conversation2", conversation2)
return och.conversationRpcClient.CreateConversationsWithoutNotification(ctx, []*pbConversation.Conversation{conversation, conversation2})
}
func (och *OnlineHistoryRedisConsumerHandler) GroupChatFirstCreateConversation(ctx context.Context, msg *sdkws.MsgData) error {
userIDs, err := och.groupRpcClient.GetGroupMemberIDs(ctx, msg.GroupID)
if err != nil {
return err
}
var conversations []*pbConversation.Conversation
for _, v := range userIDs {
conversation := pbConversation.Conversation{ConversationType: constant.SuperGroupChatType, GroupID: msg.GroupID, OwnerUserID: v, ConversationID: utils.GetConversationIDBySessionType(constant.SuperGroupChatType, msg.GroupID)}
conversations = append(conversations, &conversation)
}
log.ZDebug(ctx, "create group conversation", "conversations", conversations)
return och.conversationRpcClient.CreateConversationsWithoutNotification(ctx, conversations)
}
func (och *OnlineHistoryRedisConsumerHandler) MessagesDistributionHandle() {
for {
aggregationMsgs := make(map[string][]*ContextMsg, ChannelNum)

View File

@ -68,7 +68,6 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
type groupServer struct {
GroupDatabase controller.GroupDatabase
User *rpcclient.UserClient
//Notification *notification.Check
Notification *notification.GroupNotificationSender
conversationRpcClient *rpcclient.ConversationClient
}
@ -308,10 +307,14 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
}
}
}
if group.GroupType == constant.SuperGroup {
if err := s.GroupDatabase.CreateSuperGroupMember(ctx, req.GroupID, req.InvitedUserIDs); err != nil {
return nil, err
}
if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, req.InvitedUserIDs); err != nil {
return nil, err
}
for _, userID := range req.InvitedUserIDs {
s.Notification.SuperGroupNotification(ctx, userID, userID)
}
@ -336,6 +339,9 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
if err := s.GroupDatabase.CreateGroup(ctx, nil, groupMembers); err != nil {
return nil, err
}
if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, req.InvitedUserIDs); err != nil {
return nil, err
}
s.Notification.MemberInvitedNotification(ctx, req.GroupID, req.Reason, req.InvitedUserIDs)
}
return resp, nil
@ -669,6 +675,9 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
if err := s.GroupDatabase.CreateGroup(ctx, nil, []*relationTb.GroupMemberModel{groupMember}); err != nil {
return nil, err
}
if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, []string{req.InviterUserID}); err != nil {
return nil, err
}
s.Notification.MemberEnterDirectlyNotification(ctx, req.GroupID, req.InviterUserID)
return resp, nil
}

View File

@ -4,9 +4,13 @@ import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/protobuf/proto"
)
type ConversationClient struct {
@ -41,6 +45,31 @@ func (c *ConversationClient) GetSingleConversationRecvMsgOpt(ctx context.Context
return conversation.GetConversation().RecvMsgOpt, err
}
func (c *ConversationClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error {
conversation := new(pbConversation.Conversation)
conversationID := utils.GetConversationIDBySessionType(constant.SingleChatType, recvID, sendID)
conversation.ConversationType = constant.SingleChatType
conversation2 := proto.Clone(conversation).(*pbConversation.Conversation)
conversation.OwnerUserID = sendID
conversation.UserID = recvID
conversation.ConversationID = conversationID
conversation2.OwnerUserID = recvID
conversation2.UserID = sendID
conversation2.ConversationID = conversationID
log.ZDebug(ctx, "create single conversation", "conversation", conversation, "conversation2", conversation2)
return c.CreateConversationsWithoutNotification(ctx, []*pbConversation.Conversation{conversation, conversation2})
}
func (c *ConversationClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error {
var conversations []*pbConversation.Conversation
for _, v := range userIDs {
conversation := pbConversation.Conversation{ConversationType: constant.SuperGroupChatType, GroupID: groupID, OwnerUserID: v, ConversationID: utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID)}
conversations = append(conversations, &conversation)
}
log.ZDebug(ctx, "create group conversation", "conversations", conversations)
return c.CreateConversationsWithoutNotification(ctx, conversations)
}
func (c *ConversationClient) CreateConversationsWithoutNotification(ctx context.Context, conversations []*pbConversation.Conversation) error {
cc, err := c.getConn()
if err != nil {
@ -49,3 +78,7 @@ func (c *ConversationClient) CreateConversationsWithoutNotification(ctx context.
_, err = conversation.NewConversationClient(cc).CreateConversationsWithoutNotification(ctx, &pbConversation.CreateConversationsWithoutNotificationReq{Conversations: conversations})
return err
}
func (c *ConversationClient) DelConversations(ctx context.Context) {
}