mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-01-08 21:07:01 +08:00
feat: update set conversation logic.
This commit is contained in:
parent
d63c5b7a65
commit
d7c40f574d
@ -221,11 +221,11 @@ func (c *conversationServer) SetConversation(ctx context.Context, req *pbconvers
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// nolint
|
||||
func (c *conversationServer) SetConversations(ctx context.Context, req *pbconversation.SetConversationsReq) (*pbconversation.SetConversationsResp, error) {
|
||||
if req.Conversation == nil {
|
||||
return nil, errs.ErrArgs.WrapMsg("conversation must not be nil")
|
||||
}
|
||||
|
||||
if req.Conversation.ConversationType == constant.WriteGroupChatType {
|
||||
groupInfo, err := c.groupRpcClient.GetGroupInfo(ctx, req.Conversation.GroupID)
|
||||
if err != nil {
|
||||
@ -235,17 +235,21 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver
|
||||
return nil, servererrs.ErrDismissedAlready.WrapMsg("group dismissed")
|
||||
}
|
||||
}
|
||||
|
||||
var unequal int
|
||||
var conv dbModel.Conversation
|
||||
var conv *dbModel.Conversation
|
||||
|
||||
if len(req.UserIDs) == 1 {
|
||||
cs, err := c.conversationDatabase.FindConversations(ctx, req.UserIDs[0], []string{req.Conversation.ConversationID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(cs) == 0 {
|
||||
return nil, errs.ErrRecordNotFound.WrapMsg("conversation not found")
|
||||
|
||||
if len(cs) > 0 {
|
||||
conv = cs[0]
|
||||
} else {
|
||||
unequal++
|
||||
}
|
||||
conv = *cs[0]
|
||||
}
|
||||
|
||||
var conversation dbModel.Conversation
|
||||
@ -253,58 +257,60 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver
|
||||
conversation.ConversationType = req.Conversation.ConversationType
|
||||
conversation.UserID = req.Conversation.UserID
|
||||
conversation.GroupID = req.Conversation.GroupID
|
||||
|
||||
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 {
|
||||
if conv != nil && req.Conversation.RecvMsgOpt.Value != conv.RecvMsgOpt {
|
||||
unequal++
|
||||
}
|
||||
}
|
||||
|
||||
if req.Conversation.AttachedInfo != nil {
|
||||
m["attached_info"] = req.Conversation.AttachedInfo.Value
|
||||
if req.Conversation.AttachedInfo.Value != conv.AttachedInfo {
|
||||
if conv != nil && req.Conversation.AttachedInfo.Value != conv.AttachedInfo {
|
||||
unequal++
|
||||
}
|
||||
}
|
||||
|
||||
if req.Conversation.Ex != nil {
|
||||
m["ex"] = req.Conversation.Ex.Value
|
||||
if req.Conversation.Ex.Value != conv.Ex {
|
||||
if conv != nil && req.Conversation.Ex.Value != conv.Ex {
|
||||
unequal++
|
||||
}
|
||||
}
|
||||
if req.Conversation.IsPinned != nil {
|
||||
m["is_pinned"] = req.Conversation.IsPinned.Value
|
||||
if req.Conversation.IsPinned.Value != conv.IsPinned {
|
||||
if conv != nil && req.Conversation.IsPinned.Value != conv.IsPinned {
|
||||
unequal++
|
||||
}
|
||||
}
|
||||
|
||||
if req.Conversation.GroupAtType != nil {
|
||||
m["group_at_type"] = req.Conversation.GroupAtType.Value
|
||||
if req.Conversation.GroupAtType.Value != conv.GroupAtType {
|
||||
if conv != nil && req.Conversation.GroupAtType.Value != conv.GroupAtType {
|
||||
unequal++
|
||||
}
|
||||
}
|
||||
|
||||
if req.Conversation.MsgDestructTime != nil {
|
||||
m["msg_destruct_time"] = req.Conversation.MsgDestructTime.Value
|
||||
if req.Conversation.MsgDestructTime.Value != conv.MsgDestructTime {
|
||||
if conv != nil && req.Conversation.MsgDestructTime.Value != conv.MsgDestructTime {
|
||||
unequal++
|
||||
}
|
||||
}
|
||||
|
||||
if req.Conversation.IsMsgDestruct != nil {
|
||||
m["is_msg_destruct"] = req.Conversation.IsMsgDestruct.Value
|
||||
if req.Conversation.IsMsgDestruct.Value != conv.IsMsgDestruct {
|
||||
if conv != nil && req.Conversation.IsMsgDestruct.Value != conv.IsMsgDestruct {
|
||||
unequal++
|
||||
}
|
||||
}
|
||||
|
||||
if req.Conversation.BurnDuration != nil {
|
||||
m["burn_duration"] = req.Conversation.BurnDuration.Value
|
||||
if req.Conversation.BurnDuration.Value != conv.BurnDuration {
|
||||
if conv != nil && req.Conversation.BurnDuration.Value != conv.BurnDuration {
|
||||
unequal++
|
||||
}
|
||||
}
|
||||
@ -315,20 +321,13 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver
|
||||
}
|
||||
}
|
||||
|
||||
if unequal > 0 {
|
||||
for _, v := range req.UserIDs {
|
||||
c.conversationNotificationSender.ConversationChangeNotification(ctx, v, []string{req.Conversation.ConversationID})
|
||||
}
|
||||
return &pbconversation.SetConversationsResp{}, nil
|
||||
}
|
||||
|
||||
if req.Conversation.IsPrivateChat != nil && req.Conversation.ConversationType != constant.ReadGroupChatType {
|
||||
var conversations []*dbModel.Conversation
|
||||
for _, ownerUserID := range req.UserIDs {
|
||||
conversation2 := conversation
|
||||
conversation2.OwnerUserID = ownerUserID
|
||||
conversation2.IsPrivateChat = req.Conversation.IsPrivateChat.Value
|
||||
conversations = append(conversations, &conversation2)
|
||||
transConversation := conversation
|
||||
transConversation.OwnerUserID = ownerUserID
|
||||
transConversation.IsPrivateChat = req.Conversation.IsPrivateChat.Value
|
||||
conversations = append(conversations, &transConversation)
|
||||
}
|
||||
|
||||
if err := c.conversationDatabase.SyncPeerUserPrivateConversationTx(ctx, conversations); err != nil {
|
||||
@ -340,6 +339,12 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver
|
||||
}
|
||||
}
|
||||
|
||||
if unequal > 0 {
|
||||
for _, v := range req.UserIDs {
|
||||
c.conversationNotificationSender.ConversationChangeNotification(ctx, v, []string{req.Conversation.ConversationID})
|
||||
}
|
||||
}
|
||||
|
||||
return &pbconversation.SetConversationsResp{}, nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user