From cae28764e907c91cdc9f153e569d73b3882b6352 Mon Sep 17 00:00:00 2001 From: Monet Lee Date: Fri, 14 Mar 2025 15:37:03 +0800 Subject: [PATCH] implement createconversation webhook. --- internal/rpc/conversation/conversation.go | 20 +++++++------------ pkg/callbackstruct/conversation.go | 4 +++- pkg/common/storage/controller/conversation.go | 10 +++++++++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/internal/rpc/conversation/conversation.go b/internal/rpc/conversation/conversation.go index 637d3018a..8bc3fd2a9 100644 --- a/internal/rpc/conversation/conversation.go +++ b/internal/rpc/conversation/conversation.go @@ -338,11 +338,6 @@ func (c *conversationServer) GetRecvMsgNotNotifyUserIDs(ctx context.Context, req func (c *conversationServer) CreateSingleChatConversations(ctx context.Context, req *pbconversation.CreateSingleChatConversationsReq, ) (*pbconversation.CreateSingleChatConversationsResp, error) { - log.ZWarn(ctx, "create Single Chat Conversations is start", nil, "req", req) - // if err := c.webhookBeforeCreateSingleChatConversations(ctx, &c.config.WebhooksConfig.BeforeCreateSingleChatConversations, req); err != nil && err != servererrs.ErrCallbackContinue { - // return nil, err - // } - var conversation dbModel.Conversation switch req.ConversationType { case constant.SingleChatType: @@ -397,23 +392,22 @@ func (c *conversationServer) CreateSingleChatConversations(ctx context.Context, } func (c *conversationServer) CreateGroupChatConversations(ctx context.Context, req *pbconversation.CreateGroupChatConversationsReq) (*pbconversation.CreateGroupChatConversationsResp, error) { - var conversations dbModel.Conversation + var conversation dbModel.Conversation - conversations.ConversationID = msgprocessor.GetConversationIDBySessionType(constant.ReadGroupChatType, req.GroupID) - conversations.GroupID = req.GroupID - conversations.ConversationType = constant.ReadGroupChatType - // conversations.MaxSeq = 0 + conversation.ConversationID = msgprocessor.GetConversationIDBySessionType(constant.ReadGroupChatType, req.GroupID) + conversation.GroupID = req.GroupID + conversation.ConversationType = constant.ReadGroupChatType - if err := c.webhookBeforeCreateGroupChatConversations(ctx, &c.config.WebhooksConfig.BeforeCreateGroupChatConversations, &conversations); err != nil { + if err := c.webhookBeforeCreateGroupChatConversations(ctx, &c.config.WebhooksConfig.BeforeCreateGroupChatConversations, &conversation); err != nil { return nil, err } - err := c.conversationDatabase.CreateGroupChatConversation(ctx, req.GroupID, req.UserIDs, &conversations) + err := c.conversationDatabase.CreateGroupChatConversation(ctx, req.GroupID, req.UserIDs, &conversation) if err != nil { return nil, err } - c.webhookAfterCreateGroupChatConversations(ctx, &c.config.WebhooksConfig.AfterCreateGroupChatConversations, &conversations) + c.webhookAfterCreateGroupChatConversations(ctx, &c.config.WebhooksConfig.AfterCreateGroupChatConversations, &conversation) return &pbconversation.CreateGroupChatConversationsResp{}, nil } diff --git a/pkg/callbackstruct/conversation.go b/pkg/callbackstruct/conversation.go index a6c9fa6f5..1e32c6a9c 100644 --- a/pkg/callbackstruct/conversation.go +++ b/pkg/callbackstruct/conversation.go @@ -1,6 +1,8 @@ package callbackstruct -import "time" +import ( + "time" +) type Conversation struct { OwnerUserID string `json:"owner_user_id"` diff --git a/pkg/common/storage/controller/conversation.go b/pkg/common/storage/controller/conversation.go index e950edf89..7578394b5 100644 --- a/pkg/common/storage/controller/conversation.go +++ b/pkg/common/storage/controller/conversation.go @@ -308,7 +308,15 @@ func (c *conversationDatabase) CreateGroupChatConversation(ctx context.Context, notExistUserIDs := stringutil.DifferenceString(userIDs, existConversationUserIDs) var conversations []*relationtb.Conversation for _, v := range notExistUserIDs { - conversation := relationtb.Conversation{ConversationType: conversation.ConversationType, GroupID: groupID, OwnerUserID: v, ConversationID: conversationID} + conversation := relationtb.Conversation{ + ConversationType: conversation.ConversationType, GroupID: groupID, OwnerUserID: v, ConversationID: conversationID, + // the parameters have default value + RecvMsgOpt: conversation.RecvMsgOpt, IsPinned: conversation.IsPinned, IsPrivateChat: conversation.IsPrivateChat, + BurnDuration: conversation.BurnDuration, GroupAtType: conversation.GroupAtType, AttachedInfo: conversation.AttachedInfo, + Ex: conversation.Ex, MaxSeq: conversation.MaxSeq, MinSeq: conversation.MinSeq, CreateTime: conversation.CreateTime, + MsgDestructTime: conversation.MsgDestructTime, IsMsgDestruct: conversation.IsMsgDestruct, LatestMsgDestructTime: conversation.LatestMsgDestructTime, + } + conversations = append(conversations, &conversation) cache = cache.DelConversations(v, conversationID).DelConversationNotReceiveMessageUserIDs(conversationID) }