conversation update

pull/351/head
Gordon 2 years ago
parent b5afd304d0
commit ec0cd9a348

@ -316,13 +316,18 @@ func (s *userServer) SetRecvMsgOpt(ctx context.Context, req *pbUser.SetRecvMsgOp
conversation.ConversationType = constant.GroupChatType conversation.ConversationType = constant.GroupChatType
} }
} }
err := imdb.SetRecvMsgOpt(conversation) isUpdate, err := imdb.SetRecvMsgOpt(conversation)
if err != nil { if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation error", err.Error())
resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg} resp.CommonResp = &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}
return resp, nil return resp, nil
} }
if err = rocksCache.DelConversationFromCache(conversation.OwnerUserID, conversation.ConversationID); err != nil { if isUpdate {
err = rocksCache.DelConversationFromCache(conversation.OwnerUserID, conversation.ConversationID)
} else {
err = rocksCache.DelUserConversationIDListFromCache(conversation.OwnerUserID)
}
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), conversation.ConversationID, err.Error()) log.NewError(req.OperationID, utils.GetSelfFuncName(), conversation.ConversationID, err.Error())
} }
chat.ConversationChangeNotification(req.OperationID, req.OwnerUserID) chat.ConversationChangeNotification(req.OperationID, req.OwnerUserID)

@ -41,16 +41,18 @@ func PeerUserSetConversation(conversation db.Conversation) error {
} }
func SetRecvMsgOpt(conversation db.Conversation) error { func SetRecvMsgOpt(conversation db.Conversation) (bool, error) {
var isUpdate bool
newConversation := conversation newConversation := conversation
if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error
// if exist, then update record // if exist, then update record
} else { } else {
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
//force update //force update
return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID). isUpdate = true
return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID).
Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error
} }
} }

@ -454,7 +454,7 @@ func GetUserConversationIDListFromCache(userID string) ([]string, error) {
} }
func DelUserConversationIDListFromCache(userID string) error { func DelUserConversationIDListFromCache(userID string) error {
return db.DB.Rc.TagAsDeleted(conversationIDListCache + userID) return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationIDListCache+userID), "DelUserConversationIDListFromCache err")
} }
func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversation, error) { func GetConversationFromCache(ownerUserID, conversationID string) (*db.Conversation, error) {
@ -511,5 +511,5 @@ func GetUserAllConversationList(ownerUserID string) ([]db.Conversation, error) {
} }
func DelConversationFromCache(ownerUserID, conversationID string) error { func DelConversationFromCache(ownerUserID, conversationID string) error {
return db.DB.Rc.TagAsDeleted(conversationCache + ownerUserID + ":" + conversationID) return utils.Wrap(db.DB.Rc.TagAsDeleted(conversationCache+ownerUserID+":"+conversationID), "DelConversationFromCache err")
} }

Loading…
Cancel
Save