add global recv opt

This commit is contained in:
Gordon 2022-06-16 12:41:31 +08:00 committed by Xinwei Xiong(cubxxw-openim)
parent e923cbd53e
commit 389ea2c726
2 changed files with 23 additions and 8 deletions

View File

@ -364,12 +364,19 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetUserGlobalMsgRecvOpt failed ", err.Error(), user)
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
err = imdb.UpdateUserInfoByMap(user, m)
if err != nil {
log.NewError(req.OperationID, "UpdateUserInfo failed ", err.Error(), user)
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
} else {
err := imdb.UpdateUserInfo(user)
if err != nil {
log.NewError(req.OperationID, "UpdateUserInfo failed ", err.Error(), user)
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
}
err := imdb.UpdateUserInfo(user, m)
if err != nil {
log.NewError(req.OperationID, "UpdateUserInfo failed ", err.Error(), user)
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
client := pbFriend.NewFriendClient(etcdConn)
newReq := &pbFriend.GetFriendListReq{

View File

@ -86,16 +86,24 @@ func GetUserNameByUserID(userID string) (string, error) {
return user.Nickname, nil
}
func UpdateUserInfo(user db.User, m ...map[string]interface{}) error {
func UpdateUserInfo(user db.User) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(false)
err = dbConn.Table("users").Where("user_id=?", user.UserID).Update(&user).Error
if len(m) > 0 {
err = dbConn.Table("users").Where("user_id=?", user.UserID).Updates(m[0]).Error
return err
}
func UpdateUserInfoByMap(user db.User, m map[string]interface{}) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
dbConn.LogMode(false)
err = dbConn.Table("users").Where("user_id=?", user.UserID).Updates(m).Error
return err
}