feat: update set conversation logic. (#2544)

* refactor: refactor workflows contents.

* add tool workflows.

* update field.

* fix: remove chat error.

* Fix err.

* fix error.

* remove cn comment.

* update workflows files.

* update infra config.

* move workflows.

* feat: update bot.

* fix: solve uncorrect outdated msg get.

* update get docIDs logic.

* update

* update skip logic.

* fix

* update.

* feat: update set conversation logic.

* content format.

* update setConversation logic.

* update conversation logic.

* update conversation logic.

* update logic.

* update logic.
pull/2556/head
Monet Lee 3 months ago committed by GitHub
parent a559bfe323
commit d938754ff6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -221,11 +221,11 @@ func (c *conversationServer) SetConversation(ctx context.Context, req *pbconvers
return resp, nil return resp, nil
} }
// nolint
func (c *conversationServer) SetConversations(ctx context.Context, req *pbconversation.SetConversationsReq) (*pbconversation.SetConversationsResp, error) { func (c *conversationServer) SetConversations(ctx context.Context, req *pbconversation.SetConversationsReq) (*pbconversation.SetConversationsResp, error) {
if req.Conversation == nil { if req.Conversation == nil {
return nil, errs.ErrArgs.WrapMsg("conversation must not be nil") return nil, errs.ErrArgs.WrapMsg("conversation must not be nil")
} }
if req.Conversation.ConversationType == constant.WriteGroupChatType { if req.Conversation.ConversationType == constant.WriteGroupChatType {
groupInfo, err := c.groupRpcClient.GetGroupInfo(ctx, req.Conversation.GroupID) groupInfo, err := c.groupRpcClient.GetGroupInfo(ctx, req.Conversation.GroupID)
if err != nil { if err != nil {
@ -235,17 +235,20 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver
return nil, servererrs.ErrDismissedAlready.WrapMsg("group dismissed") return nil, servererrs.ErrDismissedAlready.WrapMsg("group dismissed")
} }
} }
var unequal int
var conv dbModel.Conversation conversationMap := make(map[string]*dbModel.Conversation)
if len(req.UserIDs) == 1 { var needUpdateUsersList []string
cs, err := c.conversationDatabase.FindConversations(ctx, req.UserIDs[0], []string{req.Conversation.ConversationID})
for _, userID := range req.UserIDs {
conversationList, err := c.conversationDatabase.FindConversations(ctx, userID, []string{req.Conversation.ConversationID})
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(cs) == 0 { if len(conversationList) != 0 {
return nil, errs.ErrRecordNotFound.WrapMsg("conversation not found") conversationMap[userID] = conversationList[0]
} else {
needUpdateUsersList = append(needUpdateUsersList, userID)
} }
conv = *cs[0]
} }
var conversation dbModel.Conversation var conversation dbModel.Conversation
@ -253,91 +256,122 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver
conversation.ConversationType = req.Conversation.ConversationType conversation.ConversationType = req.Conversation.ConversationType
conversation.UserID = req.Conversation.UserID conversation.UserID = req.Conversation.UserID
conversation.GroupID = req.Conversation.GroupID conversation.GroupID = req.Conversation.GroupID
m := make(map[string]any) m := make(map[string]any)
if req.Conversation.RecvMsgOpt != nil {
m["recv_msg_opt"] = req.Conversation.RecvMsgOpt.Value
if req.Conversation.RecvMsgOpt.Value != conv.RecvMsgOpt {
unequal++
}
}
if req.Conversation.AttachedInfo != nil { setConversationFieldsFunc := func() {
m["attached_info"] = req.Conversation.AttachedInfo.Value if req.Conversation.RecvMsgOpt != nil {
if req.Conversation.AttachedInfo.Value != conv.AttachedInfo { m["recv_msg_opt"] = req.Conversation.RecvMsgOpt.Value
unequal++ }
if req.Conversation.AttachedInfo != nil {
m["attached_info"] = req.Conversation.AttachedInfo.Value
}
if req.Conversation.Ex != nil {
m["ex"] = req.Conversation.Ex.Value
}
if req.Conversation.IsPinned != nil {
m["is_pinned"] = req.Conversation.IsPinned.Value
}
if req.Conversation.GroupAtType != nil {
m["group_at_type"] = req.Conversation.GroupAtType.Value
}
if req.Conversation.MsgDestructTime != nil {
m["msg_destruct_time"] = req.Conversation.MsgDestructTime.Value
}
if req.Conversation.MsgDestructTime != nil {
m["msg_destruct_time"] = req.Conversation.MsgDestructTime.Value
}
if req.Conversation.BurnDuration != nil {
m["burn_duration"] = req.Conversation.BurnDuration.Value
} }
} }
if req.Conversation.Ex != nil { // set need set field in conversation
m["ex"] = req.Conversation.Ex.Value setConversationFieldsFunc()
if req.Conversation.Ex.Value != conv.Ex {
unequal++ for userID := range conversationMap {
unequal := len(m)
if req.Conversation.RecvMsgOpt != nil {
if req.Conversation.RecvMsgOpt.Value != conversationMap[userID].RecvMsgOpt {
unequal--
}
} }
}
if req.Conversation.IsPinned != nil { if req.Conversation.AttachedInfo != nil {
m["is_pinned"] = req.Conversation.IsPinned.Value if req.Conversation.AttachedInfo.Value != conversationMap[userID].AttachedInfo {
if req.Conversation.IsPinned.Value != conv.IsPinned { unequal--
unequal++ }
} }
}
if req.Conversation.GroupAtType != nil { if req.Conversation.Ex != nil {
m["group_at_type"] = req.Conversation.GroupAtType.Value if req.Conversation.Ex.Value != conversationMap[userID].Ex {
if req.Conversation.GroupAtType.Value != conv.GroupAtType { unequal--
unequal++ }
}
if req.Conversation.IsPinned != nil {
m["is_pinned"] = req.Conversation.IsPinned.Value
if req.Conversation.IsPinned.Value != conversationMap[userID].IsPinned {
unequal--
}
} }
}
if req.Conversation.MsgDestructTime != nil { if req.Conversation.GroupAtType != nil {
m["msg_destruct_time"] = req.Conversation.MsgDestructTime.Value if req.Conversation.GroupAtType.Value != conversationMap[userID].GroupAtType {
if req.Conversation.MsgDestructTime.Value != conv.MsgDestructTime { unequal--
unequal++ }
} }
}
if req.Conversation.IsMsgDestruct != nil { if req.Conversation.MsgDestructTime != nil {
m["is_msg_destruct"] = req.Conversation.IsMsgDestruct.Value if req.Conversation.MsgDestructTime.Value != conversationMap[userID].MsgDestructTime {
if req.Conversation.IsMsgDestruct.Value != conv.IsMsgDestruct { unequal--
unequal++ }
} }
}
if req.Conversation.BurnDuration != nil { if req.Conversation.IsMsgDestruct != nil {
m["burn_duration"] = req.Conversation.BurnDuration.Value if req.Conversation.IsMsgDestruct.Value != conversationMap[userID].IsMsgDestruct {
if req.Conversation.BurnDuration.Value != conv.BurnDuration { unequal--
unequal++ }
} }
}
if len(m) != 0 { if req.Conversation.BurnDuration != nil {
if err := c.conversationDatabase.SetUsersConversationFieldTx(ctx, req.UserIDs, &conversation, m); err != nil { if req.Conversation.BurnDuration.Value != conversationMap[userID].BurnDuration {
return nil, err unequal--
}
} }
}
if unequal > 0 { if unequal > 0 {
for _, v := range req.UserIDs { needUpdateUsersList = append(needUpdateUsersList, userID)
c.conversationNotificationSender.ConversationChangeNotification(ctx, v, []string{req.Conversation.ConversationID})
} }
return &pbconversation.SetConversationsResp{}, nil
} }
if req.Conversation.IsPrivateChat != nil && req.Conversation.ConversationType != constant.ReadGroupChatType { if req.Conversation.IsPrivateChat != nil && req.Conversation.ConversationType != constant.ReadGroupChatType {
var conversations []*dbModel.Conversation var conversations []*dbModel.Conversation
for _, ownerUserID := range req.UserIDs { for _, ownerUserID := range req.UserIDs {
conversation2 := conversation transConversation := conversation
conversation2.OwnerUserID = ownerUserID transConversation.OwnerUserID = ownerUserID
conversation2.IsPrivateChat = req.Conversation.IsPrivateChat.Value transConversation.IsPrivateChat = req.Conversation.IsPrivateChat.Value
conversations = append(conversations, &conversation2) conversations = append(conversations, &transConversation)
} }
if err := c.conversationDatabase.SyncPeerUserPrivateConversationTx(ctx, conversations); err != nil { if err := c.conversationDatabase.SyncPeerUserPrivateConversationTx(ctx, conversations); err != nil {
return nil, err return nil, err
} }
for _, userID := range req.UserIDs { for _, userID := range req.UserIDs {
c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, userID, req.Conversation.UserID, c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, userID, req.Conversation.UserID,
req.Conversation.IsPrivateChat.Value, req.Conversation.ConversationID) req.Conversation.IsPrivateChat.Value, req.Conversation.ConversationID)
} }
} else {
if len(m) != 0 {
if err := c.conversationDatabase.SetUsersConversationFieldTx(ctx, needUpdateUsersList, &conversation, m); err != nil {
return nil, err
}
for _, v := range needUpdateUsersList {
c.conversationNotificationSender.ConversationChangeNotification(ctx, v, []string{req.Conversation.ConversationID})
}
}
} }
return &pbconversation.SetConversationsResp{}, nil return &pbconversation.SetConversationsResp{}, nil

Loading…
Cancel
Save