mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-06 01:55:58 +08:00
conversation
This commit is contained in:
@@ -4,13 +4,9 @@ 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 {
|
||||
@@ -46,39 +42,28 @@ func (c *ConversationClient) GetSingleConversationRecvMsgOpt(ctx context.Context
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
_, err = conversation.NewConversationClient(cc).CreateConversationsWithoutNotification(ctx, &pbConversation.CreateConversationsWithoutNotificationReq{Conversations: conversations})
|
||||
_, err = conversation.NewConversationClient(cc).CreateSingleChatConversations(ctx, &pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *ConversationClient) DelConversations(ctx context.Context) {
|
||||
|
||||
func (c *ConversationClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error {
|
||||
cc, err := c.getConn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = conversation.NewConversationClient(cc).CreateGroupChatConversations(ctx, &pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID})
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *ConversationClient) DelGroupChatConversations(ctx context.Context, ownerUserIDs []string, groupID string, maxSeq int64) error {
|
||||
cc, err := c.getConn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = conversation.NewConversationClient(cc).DelGroupChatConversations(ctx, &pbConversation.DelGroupChatConversationsReq{OwnerUserID: ownerUserIDs, GroupID: groupID, MaxSeq: maxSeq})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user