From b05bedf243db02d58e5d31955e78a98dc97ceecc Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 20 Apr 2023 16:05:22 +0800 Subject: [PATCH 01/10] conversation --- internal/msggateway/message_handler.go | 5 +++-- pkg/common/db/controller/conversation.go | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/msggateway/message_handler.go b/internal/msggateway/message_handler.go index a8f331240..b79e99946 100644 --- a/internal/msggateway/message_handler.go +++ b/internal/msggateway/message_handler.go @@ -2,6 +2,7 @@ package msggateway import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification" @@ -61,7 +62,7 @@ func (g GrpcHandler) GetSeq(context context.Context, data Req) ([]byte, error) { if err := proto.Unmarshal(data.Data, &req); err != nil { return nil, err } - if err := g.validate.Struct(req); err != nil { + if err := g.validate.Struct(&req); err != nil { return nil, err } resp, err := g.notification.Msg.GetMaxAndMinSeq(context, &req) @@ -100,7 +101,7 @@ func (g GrpcHandler) SendSignalMessage(context context.Context, data Req) ([]byt if err := proto.Unmarshal(data.Data, &signalReq); err != nil { return nil, err } - if err := g.validate.Struct(signalReq); err != nil { + if err := g.validate.Struct(&signalReq); err != nil { return nil, err } //req := pbRtc.SignalMessageAssembleReq{SignalReq: &signalReq, OperationID: "111"} diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index dd8597125..204bfd811 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -168,6 +168,7 @@ func (c *ConversationDataBase) SetUserConversations(ctx context.Context, ownerUs return err } if len(existConversations) > 0 { + log.ZDebug(ctx, "SetUserConversations", "existConversations", existConversations) err = conversationTx.Update(ctx, conversations) if err != nil { return err From 934e5318405c1692b89b2f9c2fa9900d4001e043 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 20 Apr 2023 16:23:41 +0800 Subject: [PATCH 02/10] conversation --- pkg/common/db/controller/conversation.go | 9 +++++---- pkg/common/db/relation/conversation_model.go | 4 ++-- pkg/common/db/table/relation/conversation.go | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index 204bfd811..cbb440a7d 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -168,10 +168,11 @@ func (c *ConversationDataBase) SetUserConversations(ctx context.Context, ownerUs return err } if len(existConversations) > 0 { - log.ZDebug(ctx, "SetUserConversations", "existConversations", existConversations) - err = conversationTx.Update(ctx, conversations) - if err != nil { - return err + for _, conversation := range conversations { + err = conversationTx.Update(ctx, conversation) + if err != nil { + return err + } } } var existConversationIDs []string diff --git a/pkg/common/db/relation/conversation_model.go b/pkg/common/db/relation/conversation_model.go index 72c3710a9..d54161649 100644 --- a/pkg/common/db/relation/conversation_model.go +++ b/pkg/common/db/relation/conversation_model.go @@ -33,8 +33,8 @@ func (c *ConversationGorm) UpdateByMap(ctx context.Context, userIDList []string, return utils.Wrap(c.db(ctx).Where("owner_user_id IN (?) and conversation_id=?", userIDList, conversationID).Updates(args).Error, "") } -func (c *ConversationGorm) Update(ctx context.Context, conversations []*relation.ConversationModel) (err error) { - return utils.Wrap(c.db(ctx).Updates(&conversations).Error, "") +func (c *ConversationGorm) Update(ctx context.Context, conversation *relation.ConversationModel) (err error) { + return utils.Wrap(c.db(ctx).Updates(conversation).Error, "") } func (c *ConversationGorm) Find(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []*relation.ConversationModel, err error) { diff --git a/pkg/common/db/table/relation/conversation.go b/pkg/common/db/table/relation/conversation.go index 6971d06f3..b2cbde6a1 100644 --- a/pkg/common/db/table/relation/conversation.go +++ b/pkg/common/db/table/relation/conversation.go @@ -33,7 +33,7 @@ type ConversationModelInterface interface { Create(ctx context.Context, conversations []*ConversationModel) (err error) Delete(ctx context.Context, groupIDs []string) (err error) UpdateByMap(ctx context.Context, userIDs []string, conversationID string, args map[string]interface{}) (err error) - Update(ctx context.Context, conversations []*ConversationModel) (err error) + Update(ctx context.Context, conversation *ConversationModel) (err error) Find(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []*ConversationModel, err error) FindUserID(ctx context.Context, userIDs []string, conversationID string) ([]string, error) FindUserIDAllConversationID(ctx context.Context, userID string) ([]string, error) From 5bf165d2c37658ca9734c91a30a408c8dbb975fc Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 20 Apr 2023 16:28:02 +0800 Subject: [PATCH 03/10] Updates --- pkg/common/db/relation/conversation_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/relation/conversation_model.go b/pkg/common/db/relation/conversation_model.go index d54161649..f7d3a0ce2 100644 --- a/pkg/common/db/relation/conversation_model.go +++ b/pkg/common/db/relation/conversation_model.go @@ -34,7 +34,7 @@ func (c *ConversationGorm) UpdateByMap(ctx context.Context, userIDList []string, } func (c *ConversationGorm) Update(ctx context.Context, conversation *relation.ConversationModel) (err error) { - return utils.Wrap(c.db(ctx).Updates(conversation).Error, "") + return utils.Wrap(c.db(ctx).Updates(&conversation).Error, "") } func (c *ConversationGorm) Find(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []*relation.ConversationModel, err error) { From e1d2c52519f98c98cbbc1c449b7dcb02fa22b79d Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 20 Apr 2023 16:31:36 +0800 Subject: [PATCH 04/10] conversation --- pkg/common/db/relation/conversation_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/relation/conversation_model.go b/pkg/common/db/relation/conversation_model.go index f7d3a0ce2..932e1a217 100644 --- a/pkg/common/db/relation/conversation_model.go +++ b/pkg/common/db/relation/conversation_model.go @@ -34,7 +34,7 @@ func (c *ConversationGorm) UpdateByMap(ctx context.Context, userIDList []string, } func (c *ConversationGorm) Update(ctx context.Context, conversation *relation.ConversationModel) (err error) { - return utils.Wrap(c.db(ctx).Updates(&conversation).Error, "") + return utils.Wrap(c.db(ctx).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).Updates(conversation).Error, "") } func (c *ConversationGorm) Find(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []*relation.ConversationModel, err error) { From 2bd22b42b704ce6d639d70155ce623bae733e23a Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 21 Apr 2023 11:26:48 +0800 Subject: [PATCH 05/10] conversation --- internal/rpc/conversation/conversaion.go | 4 ---- pkg/common/db/controller/conversation.go | 8 ++++---- pkg/common/db/relation/conversation_model.go | 4 ++-- pkg/common/db/table/relation/conversation.go | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index 67b0fba83..b66d40e68 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -145,10 +145,6 @@ func (c *conversationServer) ModifyConversationField(ctx context.Context, req *p c.notify.ConversationSetPrivateNotification(ctx, req.Conversation.OwnerUserID, req.Conversation.UserID, req.Conversation.IsPrivateChat) return resp, nil } - //haveUserID, err := c.ConversationDatabase.GetUserIDExistConversation(ctx, req.UserIDList, req.Conversation.ConversationID) - //if err != nil { - // return nil, err - //} filedMap := make(map[string]interface{}) switch req.FieldType { case constant.FieldRecvMsgOpt: diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index cbb440a7d..36ddf0f34 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -47,7 +47,7 @@ type ConversationDataBase struct { func (c *ConversationDataBase) SetUsersConversationFiledTx(ctx context.Context, userIDs []string, conversation *relationTb.ConversationModel, filedMap map[string]interface{}) error { return c.tx.Transaction(func(tx any) error { conversationTx := c.conversationDB.NewTx(tx) - haveUserIDs, err := conversationTx.FindUserID(ctx, userIDs, conversation.ConversationID) + haveUserIDs, err := conversationTx.FindUserID(ctx, userIDs, []string{conversation.ConversationID}) if err != nil { return err } @@ -102,9 +102,9 @@ func (c *ConversationDataBase) CreateConversation(ctx context.Context, conversat func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Context, conversation *relationTb.ConversationModel) error { return c.tx.Transaction(func(tx any) error { - userIDList := []string{conversation.OwnerUserID, conversation.UserID} + userIDs := []string{conversation.OwnerUserID, conversation.UserID} conversationTx := c.conversationDB.NewTx(tx) - haveUserIDs, err := conversationTx.FindUserID(ctx, userIDList, conversation.ConversationID) + haveUserIDs, err := conversationTx.FindUserID(ctx, userIDs, []string{conversation.ConversationID, utils.GetConversationIDBySessionType(conversation.UserID, constant.SingleChatType)}) if err != nil { return err } @@ -115,7 +115,7 @@ func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Con return err } } - NotUserIDs := utils.DifferenceString(haveUserIDs, userIDList) + NotUserIDs := utils.DifferenceString(haveUserIDs, userIDs) var cList []*relationTb.ConversationModel for _, v := range NotUserIDs { temp := new(relationTb.ConversationModel) diff --git a/pkg/common/db/relation/conversation_model.go b/pkg/common/db/relation/conversation_model.go index 932e1a217..ccdce96fd 100644 --- a/pkg/common/db/relation/conversation_model.go +++ b/pkg/common/db/relation/conversation_model.go @@ -47,8 +47,8 @@ func (c *ConversationGorm) Take(ctx context.Context, userID, conversationID stri return cc, utils.Wrap(c.db(ctx).Where("conversation_id = ? And owner_user_id = ?", conversationID, userID).Take(cc).Error, "") } -func (c *ConversationGorm) FindUserID(ctx context.Context, userIDList []string, conversationID string) (existUserID []string, err error) { - return existUserID, utils.Wrap(c.db(ctx).Where(" owner_user_id IN (?) and conversation_id=?", userIDList, conversationID).Pluck("owner_user_id", &existUserID).Error, "") +func (c *ConversationGorm) FindUserID(ctx context.Context, userIDs []string, conversationIDs []string) (existUserID []string, err error) { + return existUserID, utils.Wrap(c.db(ctx).Where(" owner_user_id IN (?) and conversation_id in (?)", userIDs, conversationIDs).Pluck("owner_user_id", &existUserID).Error, "") } func (c *ConversationGorm) FindConversationID(ctx context.Context, userID string, conversationIDList []string) (existConversationID []string, err error) { diff --git a/pkg/common/db/table/relation/conversation.go b/pkg/common/db/table/relation/conversation.go index b2cbde6a1..d368ff7c8 100644 --- a/pkg/common/db/table/relation/conversation.go +++ b/pkg/common/db/table/relation/conversation.go @@ -35,7 +35,7 @@ type ConversationModelInterface interface { UpdateByMap(ctx context.Context, userIDs []string, conversationID string, args map[string]interface{}) (err error) Update(ctx context.Context, conversation *ConversationModel) (err error) Find(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []*ConversationModel, err error) - FindUserID(ctx context.Context, userIDs []string, conversationID string) ([]string, error) + FindUserID(ctx context.Context, userIDs []string, conversationIDs []string) ([]string, error) FindUserIDAllConversationID(ctx context.Context, userID string) ([]string, error) Take(ctx context.Context, userID, conversationID string) (conversation *ConversationModel, err error) FindConversationID(ctx context.Context, userID string, conversationIDs []string) (existConversationID []string, err error) From 22c1b8eb596b2046e6df744d53ce65702e702661 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 21 Apr 2023 11:48:47 +0800 Subject: [PATCH 06/10] con --- pkg/common/db/controller/conversation.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index 36ddf0f34..655293a38 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -116,6 +116,7 @@ func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Con } } NotUserIDs := utils.DifferenceString(haveUserIDs, userIDs) + log.ZDebug(ctx, "SyncPeerUserPrivateConversationTx", "NotUserIDs", NotUserIDs, "haveUserIDs", haveUserIDs, "userIDs", userIDs) var cList []*relationTb.ConversationModel for _, v := range NotUserIDs { temp := new(relationTb.ConversationModel) From 8ad343e97cfe6f8f13618acbaa048aebfae44a84 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 21 Apr 2023 14:51:57 +0800 Subject: [PATCH 07/10] conversationID --- pkg/common/db/cache/conversation.go | 4 +- pkg/common/db/controller/conversation.go | 67 ++++++++------------ pkg/common/db/relation/conversation_model.go | 5 +- pkg/common/db/table/relation/conversation.go | 2 +- 4 files changed, 31 insertions(+), 47 deletions(-) diff --git a/pkg/common/db/cache/conversation.go b/pkg/common/db/cache/conversation.go index e57f774bc..ede6417ce 100644 --- a/pkg/common/db/cache/conversation.go +++ b/pkg/common/db/cache/conversation.go @@ -34,7 +34,7 @@ type ConversationCache interface { // get one conversation from cache GetConversation(ctx context.Context, ownerUserID, conversationID string) (*relationTb.ConversationModel, error) DelConvsersations(ownerUserID string, conversationIDs []string) ConversationCache - DelUsersConversation(ownerUserIDs []string, conversationID string) ConversationCache + DelUsersConversation(conversationID string, ownerUserIDs ...string) ConversationCache // get one conversation from cache GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*relationTb.ConversationModel, error) // get one user's all conversations from cache @@ -169,7 +169,7 @@ func (c *ConversationRedisCache) GetSuperGroupRecvMsgNotNotifyUserIDs(ctx contex }) } -func (c *ConversationRedisCache) DelUsersConversation(ownerUserIDs []string, conversationID string) ConversationCache { +func (c *ConversationRedisCache) DelUsersConversation(conversationID string, ownerUserIDs ...string) ConversationCache { var keys []string for _, ownerUserID := range ownerUserIDs { keys = append(keys, c.getConversationKey(ownerUserID, conversationID)) diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index 655293a38..008fbf80f 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -51,44 +51,45 @@ func (c *ConversationDataBase) SetUsersConversationFiledTx(ctx context.Context, if err != nil { return err } + cache := c.cache.NewCache() if len(haveUserIDs) > 0 { - err = conversationTx.UpdateByMap(ctx, haveUserIDs, conversation.ConversationID, filedMap) + _, err = conversationTx.UpdateByMap(ctx, haveUserIDs, conversation.ConversationID, filedMap) if err != nil { return err } + cache = cache.DelUsersConversation(conversation.ConversationID, haveUserIDs...) } NotUserIDs := utils.DifferenceString(haveUserIDs, userIDs) log.ZDebug(ctx, "SetUsersConversationFiledTx", "NotUserIDs", NotUserIDs, "haveUserIDs", haveUserIDs, "userIDs", userIDs) - var cList []*relationTb.ConversationModel + var conversations []*relationTb.ConversationModel for _, v := range NotUserIDs { temp := new(relationTb.ConversationModel) if err := utils.CopyStructFields(temp, conversation); err != nil { return err } temp.OwnerUserID = v - cList = append(cList, temp) + conversations = append(conversations, temp) } - cache := c.cache.NewCache() - if len(cList) > 0 { - err = conversationTx.Create(ctx, cList) + + if len(conversations) > 0 { + err = conversationTx.Create(ctx, conversations) if err != nil { return err } cache = cache.DelConversationIDs(NotUserIDs) - log.ZDebug(ctx, "SetUsersConversationFiledTx", "cache", cache.GetPreDelKeys(), "addr", &cache) } // clear cache log.ZDebug(ctx, "SetUsersConversationFiledTx", "cache", cache.GetPreDelKeys(), "addr", &cache) - return cache.DelUsersConversation(haveUserIDs, conversation.ConversationID).ExecDel(ctx) + return cache.ExecDel(ctx) }) } func (c *ConversationDataBase) UpdateUsersConversationFiled(ctx context.Context, userIDs []string, conversationID string, args map[string]interface{}) error { - err := c.conversationDB.UpdateByMap(ctx, userIDs, conversationID, args) + _, err := c.conversationDB.UpdateByMap(ctx, userIDs, conversationID, args) if err != nil { return err } - return c.cache.DelUsersConversation(userIDs, conversationID).ExecDel(ctx) + return c.cache.DelUsersConversation(conversationID, userIDs...).ExecDel(ctx) } func (c *ConversationDataBase) CreateConversation(ctx context.Context, conversations []*relationTb.ConversationModel) error { @@ -102,46 +103,28 @@ func (c *ConversationDataBase) CreateConversation(ctx context.Context, conversat func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Context, conversation *relationTb.ConversationModel) error { return c.tx.Transaction(func(tx any) error { - userIDs := []string{conversation.OwnerUserID, conversation.UserID} conversationTx := c.conversationDB.NewTx(tx) - haveUserIDs, err := conversationTx.FindUserID(ctx, userIDs, []string{conversation.ConversationID, utils.GetConversationIDBySessionType(conversation.UserID, constant.SingleChatType)}) - if err != nil { - return err - } - filedMap := map[string]interface{}{"is_private_chat": conversation.IsPrivateChat} - if len(haveUserIDs) > 0 { - err = conversationTx.UpdateByMap(ctx, haveUserIDs, conversation.ConversationID, filedMap) + cache := c.cache.NewCache() + for _, v := range [][3]string{{conversation.OwnerUserID, conversation.ConversationID, conversation.UserID}, {conversation.UserID, utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType), conversation.OwnerUserID}} { + rows, err := conversationTx.UpdateByMap(ctx, []string{v[0]}, v[1], map[string]interface{}{"is_private_chat": conversation.IsPrivateChat}) if err != nil { return err } - } - NotUserIDs := utils.DifferenceString(haveUserIDs, userIDs) - log.ZDebug(ctx, "SyncPeerUserPrivateConversationTx", "NotUserIDs", NotUserIDs, "haveUserIDs", haveUserIDs, "userIDs", userIDs) - var cList []*relationTb.ConversationModel - for _, v := range NotUserIDs { - temp := new(relationTb.ConversationModel) - if v == conversation.UserID { - temp.OwnerUserID = conversation.UserID - temp.ConversationID = utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType) - temp.ConversationType = constant.SingleChatType - temp.UserID = conversation.OwnerUserID - temp.IsPrivateChat = conversation.IsPrivateChat - } else { - if err := utils.CopyStructFields(temp, conversation); err != nil { + if rows == 0 { + newConversation := *conversation + newConversation.OwnerUserID = v[1] + newConversation.UserID = v[2] + newConversation.ConversationID = v[1] + newConversation.IsPrivateChat = conversation.IsPrivateChat + if err := conversationTx.Create(ctx, []*relationTb.ConversationModel{&newConversation}); err != nil { return err } - temp.OwnerUserID = v - } - cList = append(cList, temp) - } - if len(NotUserIDs) > 0 { - err = c.conversationDB.Create(ctx, cList) - if err != nil { - return err + cache = cache.DelConversationIDs([]string{v[0]}) + } else { + cache = cache.DelUsersConversation(v[1], v[0]) } } - // clear cache - return c.cache.DelConversationIDs(NotUserIDs).DelUsersConversation(haveUserIDs, conversation.ConversationID).ExecDel(ctx) + return c.cache.ExecDel(ctx) }) } diff --git a/pkg/common/db/relation/conversation_model.go b/pkg/common/db/relation/conversation_model.go index ccdce96fd..f2963295f 100644 --- a/pkg/common/db/relation/conversation_model.go +++ b/pkg/common/db/relation/conversation_model.go @@ -29,8 +29,9 @@ func (c *ConversationGorm) Delete(ctx context.Context, groupIDs []string) (err e return utils.Wrap(c.db(ctx).Where("group_id in (?)", groupIDs).Delete(&relation.ConversationModel{}).Error, "") } -func (c *ConversationGorm) UpdateByMap(ctx context.Context, userIDList []string, conversationID string, args map[string]interface{}) (err error) { - return utils.Wrap(c.db(ctx).Where("owner_user_id IN (?) and conversation_id=?", userIDList, conversationID).Updates(args).Error, "") +func (c *ConversationGorm) UpdateByMap(ctx context.Context, userIDList []string, conversationID string, args map[string]interface{}) (rows int64, err error) { + result := c.db(ctx).Where("owner_user_id IN (?) and conversation_id=?", userIDList, conversationID).Updates(args) + return result.RowsAffected, utils.Wrap(result.Error, "") } func (c *ConversationGorm) Update(ctx context.Context, conversation *relation.ConversationModel) (err error) { diff --git a/pkg/common/db/table/relation/conversation.go b/pkg/common/db/table/relation/conversation.go index d368ff7c8..e0abfcd86 100644 --- a/pkg/common/db/table/relation/conversation.go +++ b/pkg/common/db/table/relation/conversation.go @@ -32,7 +32,7 @@ func (ConversationModel) TableName() string { type ConversationModelInterface interface { Create(ctx context.Context, conversations []*ConversationModel) (err error) Delete(ctx context.Context, groupIDs []string) (err error) - UpdateByMap(ctx context.Context, userIDs []string, conversationID string, args map[string]interface{}) (err error) + UpdateByMap(ctx context.Context, userIDs []string, conversationID string, args map[string]interface{}) (rows int64, err error) Update(ctx context.Context, conversation *ConversationModel) (err error) Find(ctx context.Context, ownerUserID string, conversationIDs []string) (conversations []*ConversationModel, err error) FindUserID(ctx context.Context, userIDs []string, conversationIDs []string) ([]string, error) From 886f59e19d351da64dcb5589a15ea27372fda117 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 21 Apr 2023 14:55:24 +0800 Subject: [PATCH 08/10] conversation --- pkg/common/db/controller/conversation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index 008fbf80f..336b2ffee 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -112,7 +112,7 @@ func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Con } if rows == 0 { newConversation := *conversation - newConversation.OwnerUserID = v[1] + newConversation.OwnerUserID = v[0] newConversation.UserID = v[2] newConversation.ConversationID = v[1] newConversation.IsPrivateChat = conversation.IsPrivateChat From 4bcad908dae9e39ee98db8d13874877086c4432c Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 21 Apr 2023 14:58:42 +0800 Subject: [PATCH 09/10] conversation --- pkg/common/db/controller/conversation.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index 336b2ffee..3c12f08e6 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -110,6 +110,7 @@ func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Con if err != nil { return err } + log.ZDebug(ctx, "SyncPeerUserPrivateConversationTx", "rows", rows, "v", v) if rows == 0 { newConversation := *conversation newConversation.OwnerUserID = v[0] From 7f805e89bb016d8e44712c4e3b13d001c4216d2f Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 21 Apr 2023 15:06:29 +0800 Subject: [PATCH 10/10] conversations --- pkg/common/db/controller/conversation.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/common/db/controller/conversation.go b/pkg/common/db/controller/conversation.go index 3c12f08e6..bb34be0ec 100644 --- a/pkg/common/db/controller/conversation.go +++ b/pkg/common/db/controller/conversation.go @@ -106,12 +106,17 @@ func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Con conversationTx := c.conversationDB.NewTx(tx) cache := c.cache.NewCache() for _, v := range [][3]string{{conversation.OwnerUserID, conversation.ConversationID, conversation.UserID}, {conversation.UserID, utils.GetConversationIDBySessionType(conversation.OwnerUserID, constant.SingleChatType), conversation.OwnerUserID}} { - rows, err := conversationTx.UpdateByMap(ctx, []string{v[0]}, v[1], map[string]interface{}{"is_private_chat": conversation.IsPrivateChat}) + haveUserIDs, err := conversationTx.FindUserID(ctx, []string{v[0]}, []string{v[1]}) if err != nil { return err } - log.ZDebug(ctx, "SyncPeerUserPrivateConversationTx", "rows", rows, "v", v) - if rows == 0 { + if len(haveUserIDs) > 0 { + _, err := conversationTx.UpdateByMap(ctx, []string{v[0]}, v[1], map[string]interface{}{"is_private_chat": conversation.IsPrivateChat}) + if err != nil { + return err + } + cache = cache.DelUsersConversation(v[1], v[0]) + } else { newConversation := *conversation newConversation.OwnerUserID = v[0] newConversation.UserID = v[2] @@ -121,8 +126,6 @@ func (c *ConversationDataBase) SyncPeerUserPrivateConversationTx(ctx context.Con return err } cache = cache.DelConversationIDs([]string{v[0]}) - } else { - cache = cache.DelUsersConversation(v[1], v[0]) } } return c.cache.ExecDel(ctx)