|
|
@ -236,20 +236,15 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var unequal int
|
|
|
|
conversationMap := make(map[string]*dbModel.Conversation)
|
|
|
|
var conv *dbModel.Conversation
|
|
|
|
var needUpdateUsersList []string
|
|
|
|
|
|
|
|
|
|
|
|
if len(req.UserIDs) == 1 {
|
|
|
|
for _, userID := range req.UserIDs {
|
|
|
|
cs, err := c.conversationDatabase.FindConversations(ctx, req.UserIDs[0], []string{req.Conversation.ConversationID})
|
|
|
|
conversationList, err := c.conversationDatabase.FindConversations(ctx, userID, []string{req.Conversation.ConversationID})
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
conversationMap[userID] = conversationList[0]
|
|
|
|
if len(cs) > 0 {
|
|
|
|
|
|
|
|
conv = cs[0]
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
unequal++
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var conversation dbModel.Conversation
|
|
|
|
var conversation dbModel.Conversation
|
|
|
@ -260,58 +255,96 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver
|
|
|
|
|
|
|
|
|
|
|
|
m := make(map[string]any)
|
|
|
|
m := make(map[string]any)
|
|
|
|
|
|
|
|
|
|
|
|
if req.Conversation.RecvMsgOpt != nil {
|
|
|
|
setConversationFieldsFunc := func() {
|
|
|
|
m["recv_msg_opt"] = req.Conversation.RecvMsgOpt.Value
|
|
|
|
if req.Conversation.RecvMsgOpt != nil {
|
|
|
|
if conv != nil && req.Conversation.RecvMsgOpt.Value != conv.RecvMsgOpt {
|
|
|
|
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.AttachedInfo != nil {
|
|
|
|
// set need set field in conversation
|
|
|
|
m["attached_info"] = req.Conversation.AttachedInfo.Value
|
|
|
|
setConversationFieldsFunc()
|
|
|
|
if conv != nil && req.Conversation.AttachedInfo.Value != conv.AttachedInfo {
|
|
|
|
|
|
|
|
unequal++
|
|
|
|
for userID := range conversationMap {
|
|
|
|
|
|
|
|
unequal := len(m)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if req.Conversation.RecvMsgOpt != nil {
|
|
|
|
|
|
|
|
m["recv_msg_opt"] = req.Conversation.RecvMsgOpt.Value
|
|
|
|
|
|
|
|
if req.Conversation.RecvMsgOpt.Value != conversationMap[userID].RecvMsgOpt {
|
|
|
|
|
|
|
|
unequal--
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if req.Conversation.Ex != nil {
|
|
|
|
if req.Conversation.AttachedInfo != nil {
|
|
|
|
m["ex"] = req.Conversation.Ex.Value
|
|
|
|
m["attached_info"] = req.Conversation.AttachedInfo.Value
|
|
|
|
if conv != nil && req.Conversation.Ex.Value != conv.Ex {
|
|
|
|
if req.Conversation.AttachedInfo.Value != conversationMap[userID].AttachedInfo {
|
|
|
|
unequal++
|
|
|
|
unequal--
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.Conversation.IsPinned != nil {
|
|
|
|
if req.Conversation.Ex != nil {
|
|
|
|
m["is_pinned"] = req.Conversation.IsPinned.Value
|
|
|
|
m["ex"] = req.Conversation.Ex.Value
|
|
|
|
if conv != nil && req.Conversation.IsPinned.Value != conv.IsPinned {
|
|
|
|
if req.Conversation.Ex.Value != conversationMap[userID].Ex {
|
|
|
|
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.GroupAtType != nil {
|
|
|
|
if req.Conversation.GroupAtType != nil {
|
|
|
|
m["group_at_type"] = req.Conversation.GroupAtType.Value
|
|
|
|
m["group_at_type"] = req.Conversation.GroupAtType.Value
|
|
|
|
if conv != nil && req.Conversation.GroupAtType.Value != conv.GroupAtType {
|
|
|
|
if req.Conversation.GroupAtType.Value != conversationMap[userID].GroupAtType {
|
|
|
|
unequal++
|
|
|
|
unequal--
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if req.Conversation.MsgDestructTime != nil {
|
|
|
|
|
|
|
|
m["msg_destruct_time"] = req.Conversation.MsgDestructTime.Value
|
|
|
|
|
|
|
|
if req.Conversation.MsgDestructTime.Value != conversationMap[userID].MsgDestructTime {
|
|
|
|
|
|
|
|
unequal--
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if req.Conversation.MsgDestructTime != nil {
|
|
|
|
if req.Conversation.IsMsgDestruct != nil {
|
|
|
|
m["msg_destruct_time"] = req.Conversation.MsgDestructTime.Value
|
|
|
|
m["is_msg_destruct"] = req.Conversation.IsMsgDestruct.Value
|
|
|
|
if conv != nil && req.Conversation.MsgDestructTime.Value != conv.MsgDestructTime {
|
|
|
|
if req.Conversation.IsMsgDestruct.Value != conversationMap[userID].IsMsgDestruct {
|
|
|
|
unequal++
|
|
|
|
unequal--
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if req.Conversation.IsMsgDestruct != nil {
|
|
|
|
if req.Conversation.BurnDuration != nil {
|
|
|
|
m["is_msg_destruct"] = req.Conversation.IsMsgDestruct.Value
|
|
|
|
m["burn_duration"] = req.Conversation.BurnDuration.Value
|
|
|
|
if conv != nil && req.Conversation.IsMsgDestruct.Value != conv.IsMsgDestruct {
|
|
|
|
if req.Conversation.BurnDuration.Value != conversationMap[userID].BurnDuration {
|
|
|
|
unequal++
|
|
|
|
unequal--
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if req.Conversation.BurnDuration != nil {
|
|
|
|
if unequal > 0 {
|
|
|
|
m["burn_duration"] = req.Conversation.BurnDuration.Value
|
|
|
|
needUpdateUsersList = append(needUpdateUsersList, userID)
|
|
|
|
if conv != nil && req.Conversation.BurnDuration.Value != conv.BurnDuration {
|
|
|
|
|
|
|
|
unequal++
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -334,17 +367,14 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbconver
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if len(m) != 0 {
|
|
|
|
if len(m) != 0 {
|
|
|
|
if err := c.conversationDatabase.SetUsersConversationFieldTx(ctx, req.UserIDs, &conversation, m); err != nil {
|
|
|
|
if err := c.conversationDatabase.SetUsersConversationFieldTx(ctx, needUpdateUsersList, &conversation, m); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if unequal > 0 {
|
|
|
|
for _, v := range needUpdateUsersList {
|
|
|
|
for _, v := range req.UserIDs {
|
|
|
|
c.conversationNotificationSender.ConversationChangeNotification(ctx, v, []string{req.Conversation.ConversationID})
|
|
|
|
c.conversationNotificationSender.ConversationChangeNotification(ctx, v, []string{req.Conversation.ConversationID})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return &pbconversation.SetConversationsResp{}, nil
|
|
|
|
return &pbconversation.SetConversationsResp{}, nil
|
|
|
|