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
+33
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) {
}